From 4ce0f222125446327d0504c53ca6fe81241ef847 Mon Sep 17 00:00:00 2001 From: "Engelbart Kai Sven (PEA4-Fe)" Date: Thu, 21 Jan 2021 14:09:31 +0100 Subject: [PATCH] Fix prediction result aggregation --- src/app/prediction/prediction.component.ts | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/app/prediction/prediction.component.ts b/src/app/prediction/prediction.component.ts index 35694d3..d300031 100644 --- a/src/app/prediction/prediction.component.ts +++ b/src/app/prediction/prediction.component.ts @@ -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 }