Skip to content

Commit b68dcbe

Browse files
committed
export synthetic data as json and some small refactoring to make it work
1 parent 66bb556 commit b68dcbe

File tree

6 files changed

+43
-19
lines changed

6 files changed

+43
-19
lines changed

src/assets/synthetic-data.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,10 @@ start = time.time()
4141
4242
from js import data
4343
from js import setResult
44-
from js import dataType
4544
from js import isDemo
4645
from js import sdgMethod
4746
from js import samples
47+
from js import setOutputData
4848
4949
INIT_STEP = 'init'
5050
PROCESSOR_STEP = 'processor'
@@ -592,6 +592,9 @@ def run():
592592
print("Original Data (first 5 rows):", real_data.head())
593593
print("Synthetic Data (first 5 rows):", synthetic_data.head())
594594
595+
setOutputData("syntheticData", synthetic_data.to_json(orient='records'))
596+
597+
595598
results = run_diagnostic(real_data, synthetic_data, target_column='gpa')
596599
print('Results:', results)
597600
setResult(json.dumps(

src/components/SyntheticDataSettings.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ import { zodResolver } from '@hookform/resolvers/zod';
88
import { Form, FormControl, FormField, FormItem, FormLabel } from './ui/form';
99
import { Card, CardDescription, CardHeader, CardTitle } from './ui/card';
1010
import Papa from 'papaparse';
11-
import { SyntheticDataParameters } from './synthetic-data-interfaces/BiasDetectionParameters';
1211
import { useTranslation } from 'react-i18next';
1312
import { RadioGroup, RadioGroupItem } from './ui/radio-group';
1413
import { Slider } from './ui/slider';
1514
import { Label } from './ui/label';
15+
import { SyntheticDataParameters } from './synthetic-data-interfaces/SyntheticDataParameters';
1616

1717
const createFormSchema = (t: (key: string) => string) =>
1818
z.object({
@@ -99,7 +99,6 @@ export default function BiasSettings({
9999

100100
const onSubmit = (data: z.infer<typeof FormSchema>) => {
101101
onRun({
102-
dataType: 'numeric',
103102
isDemo: false,
104103
sdgMethod: data.sdgMethod,
105104
samples: outputSamples[0],

src/components/synthetic-data-interfaces/BiasDetectionParameters.ts renamed to src/components/synthetic-data-interfaces/SyntheticDataParameters.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
export interface SyntheticDataParameters {
2-
dataType: string;
32
isDemo: boolean;
43
sdgMethod: string;
54
samples: number;
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
export interface SyntheticDataInfo {
2-
dataType: string;
32
isDemo: boolean;
43
sdgMethod: string;
54
samples: number;
5+
syntheticData: object;
6+
date: Date;
67
}

src/components/ui/dropdown-menu.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ const DropdownMenuSubContent = React.forwardRef<
4545
<DropdownMenuPrimitive.SubContent
4646
ref={ref}
4747
className={cn(
48-
'z-50 min-w-[8rem] overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-lg data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2',
48+
'z-50 min-w-[8rem] overflow-hidden rounded-md border bg-white p-1 text-popover-foreground shadow-lg data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2',
4949
className
5050
)}
5151
{...props}
@@ -63,7 +63,7 @@ const DropdownMenuContent = React.forwardRef<
6363
ref={ref}
6464
sideOffset={sideOffset}
6565
className={cn(
66-
'z-50 min-w-[8rem] overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-md',
66+
'z-50 min-w-[8rem] overflow-hidden rounded-md border bg-white p-1 text-popover-foreground shadow-md',
6767
'data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2',
6868
className
6969
)}

src/routes/SyntheticData.tsx

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ import {
1717
DropdownMenuContent,
1818
DropdownMenuItem,
1919
DropdownMenuTrigger,
20-
} from "@/components/ui/dropdown-menu";
20+
} from '@/components/ui/dropdown-menu';
21+
import { downloadFile } from '@/lib/download-file';
22+
import { SyntheticDataParameters } from '@/components/synthetic-data-interfaces/SyntheticDataParameters';
2123

2224
const PAGE_STYLE = `
2325
@page {
@@ -67,8 +69,8 @@ export default function SyntheticDataGeneration() {
6769
runPython,
6870
sendData,
6971
error,
70-
} = usePython<SyntheticDataInfo, SyntheticDataInfo>({
71-
dataType: 'numeric',
72+
clusterInfo,
73+
} = usePython<SyntheticDataParameters, SyntheticDataInfo>({
7274
isDemo: false,
7375
sdgMethod: 'gc',
7476
samples: 1000,
@@ -106,7 +108,6 @@ export default function SyntheticDataGeneration() {
106108
}
107109
if (data.demo) {
108110
onRun({
109-
dataType: 'numeric',
110111
isDemo: true,
111112
sdgMethod: 'cart',
112113
samples: 1000,
@@ -115,7 +116,6 @@ export default function SyntheticDataGeneration() {
115116
}, [initialised, data]);
116117

117118
const onRun = (props: {
118-
dataType: string;
119119
isDemo: boolean;
120120
sdgMethod: string;
121121
samples: number;
@@ -124,7 +124,6 @@ export default function SyntheticDataGeneration() {
124124
type: 'start',
125125
params: {
126126
parameters: {
127-
dataType: props.dataType,
128127
isDemo: props.isDemo,
129128
sdgMethod: props.sdgMethod,
130129
samples: props.samples,
@@ -156,19 +155,42 @@ export default function SyntheticDataGeneration() {
156155
<div className="ml-auto flex flex-row gap-2 hideonprint">
157156
<DropdownMenu>
158157
<DropdownMenuTrigger asChild>
159-
<Button variant="outline" size="sm" className="p-4 text-sm">
158+
<Button
159+
variant="outline"
160+
size="sm"
161+
className="p-4 text-sm"
162+
>
160163
{t('downloadButton')}
161164
</Button>
162165
</DropdownMenuTrigger>
163166
<DropdownMenuContent align="end">
164-
<DropdownMenuItem onClick={() => reactToPrintFn()}>
167+
<DropdownMenuItem
168+
onClick={() => reactToPrintFn()}
169+
>
165170
<Share className="size-3.5 mr-2" />
166171
{t('syntheticData.exportToPDF')}
167172
</DropdownMenuItem>
168-
<DropdownMenuItem>
169-
<Share className="size-3.5 mr-2" />
170-
{t('syntheticData.exportToJSON')}
171-
</DropdownMenuItem>
173+
{clusterInfo && (
174+
<DropdownMenuItem
175+
onClick={() => {
176+
downloadFile(
177+
JSON.stringify(
178+
{
179+
fileName: data.fileName,
180+
...clusterInfo,
181+
},
182+
null,
183+
2
184+
),
185+
`${data.fileName.replace('.csv', '') || 'cluster-info'}-${clusterInfo.date.toISOString()}.json`,
186+
'application/json'
187+
);
188+
}}
189+
>
190+
<Share className="size-3.5 mr-2" />
191+
{t('syntheticData.exportToJSON')}
192+
</DropdownMenuItem>
193+
)}
172194
</DropdownMenuContent>
173195
</DropdownMenu>
174196
</div>

0 commit comments

Comments
 (0)