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

View File

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