Fix prediction result aggregation
This commit is contained in:
		@@ -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
 | 
			
		||||
  }
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user