Add CSV prediction export
This commit is contained in:
@ -60,6 +60,10 @@
|
||||
<rb-form-radio name="multiple-samples" label="Multiple samples" [(ngModel)]="multipleSamples" [value]="true">
|
||||
</rb-form-radio>
|
||||
</div>
|
||||
|
||||
<rb-icon-button icon="forward-right" mode="primary" (click)="exportCSV()" *ngIf="spectrumNames.length">
|
||||
Export to CSV
|
||||
</rb-icon-button>
|
||||
</div>
|
||||
|
||||
<div class="dpt-chart space-below">
|
||||
|
@ -1,11 +1,12 @@
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
import {ChartOptions} from 'chart.js';
|
||||
import {ApiService} from '../services/api.service';
|
||||
import {animate, style, transition, trigger} from '@angular/animations';
|
||||
import { ChartOptions } from 'chart.js';
|
||||
import { ApiService } from '../services/api.service';
|
||||
import { animate, style, transition, trigger } from '@angular/animations';
|
||||
import cloneDeep from 'lodash/cloneDeep';
|
||||
import omit from 'lodash/omit';
|
||||
import {DataService} from '../services/data.service';
|
||||
import {ModelItemModel} from '../models/model-item.model';
|
||||
import { DataService } from '../services/data.service';
|
||||
import { ModelItemModel } from '../models/model-item.model';
|
||||
import * as FileSaver from 'file-saver'
|
||||
|
||||
|
||||
@Component({
|
||||
@ -29,7 +30,7 @@ import {ModelItemModel} from '../models/model-item.model';
|
||||
})
|
||||
export class PredictionComponent implements OnInit {
|
||||
|
||||
result: {predictions: any[], mean: any[]}; // prediction result from python container
|
||||
result: { predictions: any[], mean: any[] }; // prediction result from python container
|
||||
loading = false;
|
||||
activeGroup: ModelItemModel = new ModelItemModel();
|
||||
activeModelIndex = 0;
|
||||
@ -121,7 +122,10 @@ export class PredictionComponent implements OnInit {
|
||||
this.result = undefined;
|
||||
}
|
||||
|
||||
clip(str) { // clip spaces at start and end
|
||||
return str.replace(/^\s*(.*?)\s*$/, '$1');
|
||||
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 csv = predictions.map(line => line.join(";")).join("\n");
|
||||
FileSaver.saveAs(new Blob([csv], { type: 'text/csv;charset=utf-8' }), "predictions.csv");
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user