Skip to content

Commit 0f26f14

Browse files
committed
CART en GC en method keuze
1 parent c8644f3 commit 0f26f14

File tree

9 files changed

+538
-18
lines changed

9 files changed

+538
-18
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,6 @@ dist-ssr
2222
*.njsproj
2323
*.sln
2424
*.sw?
25+
26+
__pycache__
27+
*.pyc

src/assets/synthetic-data.tsx

Lines changed: 457 additions & 9 deletions
Large diffs are not rendered by default.

src/components/SyntheticDataSettings.tsx

Lines changed: 55 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,19 @@ import { ArrowDown, ArrowRight } from 'lucide-react';
55
import { z } from 'zod';
66
import { useForm } from 'react-hook-form';
77
import { zodResolver } from '@hookform/resolvers/zod';
8-
import { Form, FormField } from './ui/form';
8+
import { Form, FormControl, FormField, FormItem, FormLabel } from './ui/form';
99
import { Card, CardDescription, CardHeader, CardTitle } from './ui/card';
1010
import Papa from 'papaparse';
1111
import { SyntheticDataParameters } from './synthetic-data-interfaces/BiasDetectionParameters';
1212
import { useTranslation } from 'react-i18next';
13+
import { RadioGroup, RadioGroupItem } from './ui/radio-group';
1314

1415
const createFormSchema = (t: (key: string) => string) =>
1516
z.object({
1617
file: z.string({
1718
required_error: t('syntheticData.form.errors.csvRequired'),
1819
}),
20+
sdgMethod: z.string(),
1921
});
2022

2123
export default function BiasSettings({
@@ -36,8 +38,11 @@ export default function BiasSettings({
3638

3739
const form = useForm<z.infer<typeof FormSchema>>({
3840
resolver: zodResolver(FormSchema),
41+
defaultValues: {
42+
sdgMethod: 'gc',
43+
},
3944
});
40-
45+
const [dataKey, setDataKey] = useState<string>(new Date().toISOString());
4146
const [data, setData] = useState<{
4247
data: Record<string, string>[];
4348
stringified: string;
@@ -55,6 +60,7 @@ export default function BiasSettings({
5560
form.setValue('file', stringified);
5661
}
5762
setData({ data, stringified, fileName });
63+
setDataKey(new Date().toISOString());
5864
};
5965

6066
useEffect(() => {
@@ -73,8 +79,12 @@ export default function BiasSettings({
7379
);
7480
};
7581

76-
const onSubmit = () => {
77-
onRun({ dataType: 'numeric', isDemo: false });
82+
const onSubmit = (data: z.infer<typeof FormSchema>) => {
83+
onRun({
84+
dataType: 'numeric',
85+
isDemo: false,
86+
sdgMethod: data.sdgMethod,
87+
});
7888
};
7989

8090
return (
@@ -97,6 +107,47 @@ export default function BiasSettings({
97107
)}
98108
/>
99109
</div>
110+
111+
<div className="flex flex-col gap-3">
112+
<label className="text-sm font-medium">
113+
{t(
114+
'syntheticData.form.fieldset.sdgMethod.title'
115+
)}
116+
</label>
117+
<FormField
118+
control={form.control}
119+
name="sdgMethod"
120+
render={({ field }) => (
121+
<RadioGroup
122+
onValueChange={field.onChange}
123+
defaultValue={field.value}
124+
key={`${dataKey}_sdgMethod`}
125+
className="flex flex-col space-y-1"
126+
>
127+
<FormItem className="flex items-center space-x-3 space-y-0">
128+
<FormControl>
129+
<RadioGroupItem value="cart" />
130+
</FormControl>
131+
<FormLabel className="font-normal">
132+
{t(
133+
'syntheticData.form.fieldset.sdgMethod.cart'
134+
)}
135+
</FormLabel>
136+
</FormItem>
137+
<FormItem className="flex items-center space-x-3 space-y-0">
138+
<FormControl>
139+
<RadioGroupItem value="gc" />
140+
</FormControl>
141+
<FormLabel className="font-normal">
142+
{t(
143+
'syntheticData.form.fieldset.sdgMethod.gc'
144+
)}
145+
</FormLabel>
146+
</FormItem>
147+
</RadioGroup>
148+
)}
149+
/>
150+
</div>
100151
</fieldset>
101152

102153
<div className="flex flex-row ml-auto gap-2">

src/components/pyodide/worker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ self.onmessage = async (e: MessageData) => {
118118
await micropip.install('unsupervised-bias-detection');
119119
await micropip.install('kmodes');
120120
await micropip.install('scipy');
121-
121+
await micropip.install('py-synthpop');
122122
return true;
123123
}
124124

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
export interface SyntheticDataParameters {
22
dataType: string;
33
isDemo: boolean;
4+
sdgMethod: string;
45
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
export interface SyntheticDataInfo {
22
dataType: string;
33
isDemo: boolean;
4+
sdgMethod: string;
45
}

src/locales/en.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,12 @@
5858
"analysisError": "Error while analysing"
5959
},
6060
"fieldset": {
61-
"sourceDataset": "Source Dataset"
61+
"sourceDataset": "Source Dataset",
62+
"sdgMethod": {
63+
"title": "Method",
64+
"cart": "cart",
65+
"gc": "Gaussian Copula"
66+
}
6267
},
6368
"actions": {
6469
"tryItOut": "Try it out",

src/locales/nl.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,12 @@
5858
"analysisError": "Fout tijdens analyse"
5959
},
6060
"fieldset": {
61-
"sourceDataset": "Brondataset"
61+
"sourceDataset": "Brondataset",
62+
"sdgMethod": {
63+
"title": "Methode",
64+
"cart": "cart",
65+
"gc": "Gaussian Copula"
66+
}
6267
},
6368
"actions": {
6469
"tryItOut": "Uitproberen",

src/routes/SyntheticData.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ export default function SyntheticDataGeneration() {
6464
} = usePython<SyntheticDataInfo, SyntheticDataInfo>({
6565
dataType: 'numeric',
6666
isDemo: false,
67+
sdgMethod: 'gc',
6768
});
6869

6970
const onFileLoad: csvReader['onChange'] = (
@@ -88,17 +89,22 @@ export default function SyntheticDataGeneration() {
8889
sendData(data.stringified);
8990
}
9091
if (data.demo) {
91-
onRun({ dataType: 'numeric', isDemo: true });
92+
onRun({ dataType: 'numeric', isDemo: true, sdgMethod: 'cart' });
9293
}
9394
}, [initialised, data]);
9495

95-
const onRun = (props: { dataType: string; isDemo: boolean }) => {
96+
const onRun = (props: {
97+
dataType: string;
98+
isDemo: boolean;
99+
sdgMethod: string;
100+
}) => {
96101
runPython({
97102
type: 'start',
98103
params: {
99104
parameters: {
100105
dataType: props.dataType,
101106
isDemo: props.isDemo,
107+
sdgMethod: props.sdgMethod,
102108
},
103109
},
104110
});

0 commit comments

Comments
 (0)