2
Fork 0

Fix prediction result aggregation

This commit is contained in:
Kai S. K. Engelbart 2021-01-21 14:09:31 +01:00
parent da51cd5621
commit 4ce0f22212
1 changed files with 13 additions and 2 deletions

View File

@ -126,13 +126,24 @@ export class PredictionComponent implements OnInit {
this.result = undefined;
}
// Aggregates spectrum names and prediction values into an associative array
prepareExport() {
const zip = (a, b) => a.map((k, i) => [k, b[i]]);
const values = this.result.predictions
.map(prediction => prediction
.filter(field => field.category === 'Prediction')
.map(field => field.value));
return zip(this.spectrumNames, values);
}
// Converts the prediction results to a CSV file
exportCSV() {
const zip = (a, b) => a.map((k, i) => [k, b[i]]);
const predictions = zip(this.spectrumNames, this.result.predictions.map(p => p[0].value));
const predictions = this.prepareExport();
const csv = predictions.map(line => line.join(";")).join("\n");
FileSaver.saveAs(new Blob([csv], { type: 'text/csv;charset=utf-8' }), "predictions.csv");
}
// Converts the prediction results to a PDF file
exportPDF() {
// TODO: Generate PDF export
}