-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(JAQPOT-184): export csv results (#38)
* feat: export csv results * fix: add bottom margin to dataset result
- Loading branch information
Showing
8 changed files
with
169 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { DatasetDto, FeatureDto, ModelDto } from '@/app/api.types'; | ||
import { generateResultTableRow } from '@/app/util/dataset'; | ||
|
||
function generateCSVFromData( | ||
independentFeatures: FeatureDto[], | ||
dependentFeatures: FeatureDto[], | ||
dataset: DatasetDto, | ||
) { | ||
const headerRow = [...independentFeatures, ...dependentFeatures] | ||
.map((feature) => { | ||
return feature.name; | ||
}) | ||
.join(','); | ||
|
||
const resultRows = | ||
dataset.result?.map((result: any, resultIndex: number) => { | ||
return generateResultTableRow( | ||
independentFeatures, | ||
dependentFeatures, | ||
dataset, | ||
resultIndex, | ||
result, | ||
).join(','); | ||
}) ?? []; | ||
|
||
return [headerRow, ...resultRows].join('\n'); | ||
} | ||
|
||
export async function POST(request: Request) { | ||
const { independentFeatures, dependentFeatures, dataset } = | ||
await request.json(); | ||
const csv = generateCSVFromData( | ||
independentFeatures, | ||
dependentFeatures, | ||
dataset, | ||
); | ||
|
||
const headers = new Headers(); | ||
headers.append('Content-Disposition', 'attachment; filename="results.csv"'); | ||
headers.append('Content-Type', 'application/csv'); | ||
|
||
return new Response(csv, { | ||
headers: { | ||
'Content-Disposition': 'attachment; filename="results.csv"', | ||
'Content-Type': 'application/csv', | ||
}, | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { Chip } from '@nextui-org/chip'; | ||
import React from 'react'; | ||
import { DatasetDto, FeatureDto, ModelDto } from '@/app/api.types'; | ||
|
||
export function getDatasetStatusNode(dataset: DatasetDto | null | undefined) { | ||
if (!dataset) { | ||
return <></>; | ||
} else if (dataset?.status === 'SUCCESS') { | ||
return ( | ||
<Chip color="success" variant="flat"> | ||
Success | ||
</Chip> | ||
); | ||
} else if (dataset?.status === 'FAILURE') { | ||
return ( | ||
<Chip color="danger" variant="flat"> | ||
Failed | ||
</Chip> | ||
); | ||
} else { | ||
return <Chip color="primary">In progress</Chip>; | ||
} | ||
} | ||
|
||
export function generateResultTableRow( | ||
independentFeatures: FeatureDto[], | ||
dependentFeatures: FeatureDto[], | ||
dataset: DatasetDto, | ||
resultIndex: number, | ||
result: any, | ||
): string[] { | ||
const independentFeatureCellValues: string[] = independentFeatures.map( | ||
(feature, independentFeatureIndex) => { | ||
const input = dataset.input[resultIndex] as any; | ||
if (!input || !input[feature.key]) { | ||
return 'N/A'; | ||
} | ||
if (feature.featureType === 'CATEGORICAL') { | ||
return ( | ||
feature.possibleValues?.find( | ||
(possibleValue) => possibleValue.key === input[feature.key], | ||
)?.value ?? input[feature.key] | ||
); | ||
} | ||
return input[feature.key]; | ||
}, | ||
); | ||
|
||
const dependentFeatureCellValues = dependentFeatures.map((feature, index) => { | ||
return result[feature.key]; | ||
}); | ||
return [...independentFeatureCellValues, ...dependentFeatureCellValues]; | ||
} |
This file was deleted.
Oops, something went wrong.