Skip to content

Commit b3f5d82

Browse files
committed
Add data type selection and validation in BiasSettings component; update localization for data type messages
1 parent c4eebe7 commit b3f5d82

File tree

3 files changed

+82
-0
lines changed

3 files changed

+82
-0
lines changed

src/components/BiasSettings.tsx

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,25 @@ export default function BiasSettings({
143143
};
144144

145145
const onSubmit = (data: z.infer<typeof FormSchema>) => {
146+
// Check if data type matches the actual data
147+
const isNumericData = data.data.every(row => {
148+
return !isNaN(parseFloat(row[data.targetColumn]));
149+
});
150+
151+
if (data.dataType === 'numeric' && !isNumericData) {
152+
setPerformanceMetricColumnError(
153+
t('biasSettings.form.errors.numericDataRequired')
154+
);
155+
return;
156+
}
157+
158+
if (data.dataType === 'categorical' && isNumericData) {
159+
setPerformanceMetricColumnError(
160+
t('biasSettings.form.errors.categoricalDataRequired')
161+
);
162+
return;
163+
}
164+
146165
onRun({
147166
clusterSize: clusters[0],
148167
iterations: iter[0],
@@ -259,6 +278,55 @@ export default function BiasSettings({
259278
)}
260279
/>
261280
</div>
281+
<div className="grid gap-3">
282+
<FormField
283+
control={form.control}
284+
name="dataType"
285+
disabled={isLoading}
286+
render={({ field }) => (
287+
<FormItem>
288+
<FormLabel>
289+
{t(
290+
'biasSettings.form.fieldsets.data.dataType'
291+
)}
292+
</FormLabel>
293+
<RadioGroup
294+
onValueChange={field.onChange}
295+
defaultValue={field.value}
296+
key={`${dataKey}_dataType`}
297+
className="flex flex-col space-y-1"
298+
>
299+
<FormItem className="flex items-center space-x-3 space-y-0">
300+
<FormControl>
301+
<RadioGroupItem
302+
value="categorical"
303+
disabled={isLoading}
304+
/>
305+
</FormControl>
306+
<FormLabel className="font-normal">
307+
{t(
308+
'biasSettings.form.fieldsets.data.categoricalData'
309+
)}
310+
</FormLabel>
311+
</FormItem>
312+
<FormItem className="flex items-center space-x-3 space-y-0">
313+
<FormControl>
314+
<RadioGroupItem
315+
value="numeric"
316+
disabled={isLoading}
317+
/>
318+
</FormControl>
319+
<FormLabel className="font-normal">
320+
{t(
321+
'biasSettings.form.fieldsets.data.numericalData'
322+
)}
323+
</FormLabel>
324+
</FormItem>
325+
</RadioGroup>
326+
</FormItem>
327+
)}
328+
/>
329+
</div>
262330
</fieldset>
263331

264332
<fieldset className="grid gap-6 rounded-lg border p-4">

src/locales/en.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ export const en = {
3030
dataSet: 'Dataset',
3131
dataSetTooltip: `Your data should be prepared as follows: ...`,
3232
performanceMetric: 'Bias metric',
33+
dataType: 'Type of data',
34+
categoricalData: 'Categorical data',
35+
numericalData: 'Numerical data',
3336
},
3437
parameters: {
3538
title: 'Parameters',
@@ -55,6 +58,10 @@ export const en = {
5558
'No numeric columns found. Please upload a valid dataset.',
5659
analysisError: 'Error while analysing',
5760
noData: 'No data loaded',
61+
numericDataRequired:
62+
'Selected column must contain numerical data for k-means clustering.',
63+
categoricalDataRequired:
64+
'Selected column must contain categorical data for k-modes clustering.',
5865
},
5966
actions: {
6067
tryItOut: 'Demo dataset',

src/locales/nl.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ export const nl = {
2828
dataSet: 'Dataset',
2929
dataSetTooltip: `Data wordt als volgt behandeld: ...`,
3030
performanceMetric: 'Gelijkheidsmetriek',
31+
dataType: 'Type data',
32+
categoricalData: 'Categorische data',
33+
numericalData: 'Numerieke data',
3134
},
3235
parameters: {
3336
title: 'Parameters',
@@ -54,6 +57,10 @@ export const nl = {
5457
'Geen numerieke kolommen gevonden. Upload een geldige dataset.',
5558
analysisError: 'Fout tijdens analyse',
5659
noData: 'Geen gegevens geladen',
60+
numericDataRequired:
61+
'Geselecteerde kolom moet numerieke data bevatten voor k-means clustering.',
62+
categoricalDataRequired:
63+
'Geselecteerde kolom moet categorische data bevatten voor k-modes clustering.',
5764
},
5865
actions: {
5966
tryItOut: 'Demo dataset',

0 commit comments

Comments
 (0)