Add CSV prediction export

This commit is contained in:
Kai S. K. Engelbart 2020-12-15 12:00:16 +01:00
parent b54e167ee7
commit 4c88db301f
5 changed files with 40 additions and 20 deletions

17
package-lock.json generated
View File

@ -2034,6 +2034,12 @@
"integrity": "sha512-EaObqwIvayI5a8dCzhFrjKzVwKLxjoG9T6Ppd5CEo07LRKfQ8Yokw54r5+Wq7FaBQ+yXRvQAYPrHwya1/UFt9g==",
"dev": true
},
"@types/file-saver": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/@types/file-saver/-/file-saver-2.0.1.tgz",
"integrity": "sha512-g1QUuhYVVAamfCifK7oB7G3aIl4BbOyzDOqVyUfEr4tfBKrXfeH+M+Tg7HKCXSrbzxYdhyCP7z9WbKo0R2hBCw==",
"dev": true
},
"@types/glob": {
"version": "7.1.1",
"resolved": "https://registry.npmjs.org/@types/glob/-/glob-7.1.1.tgz",
@ -2067,9 +2073,9 @@
"dev": true
},
"@types/node": {
"version": "12.12.41",
"resolved": "https://registry.npmjs.org/@types/node/-/node-12.12.41.tgz",
"integrity": "sha512-Q+eSkdYQJ2XK1AJnr4Ji8Gvk3sRDybEwfTvtL9CA25FFUSD2EgZQewN6VCyWYZCXg5MWZdwogdTNBhlWRcWS1w==",
"version": "12.19.9",
"resolved": "https://registry.npmjs.org/@types/node/-/node-12.19.9.tgz",
"integrity": "sha512-yj0DOaQeUrk3nJ0bd3Y5PeDRJ6W0r+kilosLA+dzF3dola/o9hxhMSg2sFvVcA2UHS5JSOsZp4S0c1OEXc4m1Q==",
"dev": true
},
"@types/q": {
@ -5515,6 +5521,11 @@
"schema-utils": "^2.6.5"
}
},
"file-saver": {
"version": "2.0.5",
"resolved": "https://registry.npmjs.org/file-saver/-/file-saver-2.0.5.tgz",
"integrity": "sha512-P9bmyZ3h/PRG+Nzga+rbdI4OEpNDzAVyy74uVO9ATgzLK6VtAsYybF/+TOCvrc0MO793d6+42lLyZTw7/ArVzA=="
},
"file-uri-to-path": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/file-uri-to-path/-/file-uri-to-path-1.0.0.tgz",

View File

@ -28,6 +28,7 @@
"angular-2-local-storage": "^3.0.2",
"chart.js": "^2.9.3",
"chartjs-plugin-datalabels": "^0.7.0",
"file-saver": "^2.0.5",
"flatpickr": "^4.6.3",
"lodash": "^4.17.15",
"ng2-charts": "^2.3.2",
@ -42,9 +43,9 @@
"@angular/cli": "~9.1.6",
"@angular/compiler-cli": "~9.1.7",
"@angular/language-service": "~9.1.7",
"@types/file-saver": "^2.0.1",
"@types/jasmine": "~3.3.8",
"@types/jasminewd2": "~2.0.3",
"@types/node": "^12.11.1",
"codelyzer": "^5.1.2",
"jasmine-core": "~3.4.0",
"jasmine-spec-reporter": "~4.2.1",

View File

@ -4,20 +4,20 @@ import { ChartsModule } from 'ng2-charts';
import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import {FormFieldsModule, ModalService, RbUiComponentsModule} from '@inst-iot/bosch-angular-ui-components';
import {LoginComponent} from './login/login.component';
import { FormFieldsModule, ModalService, RbUiComponentsModule } from '@inst-iot/bosch-angular-ui-components';
import { LoginComponent } from './login/login.component';
import { HomeComponent } from './home/home.component';
import {FormsModule, ReactiveFormsModule} from '@angular/forms';
import {LocalStorageModule} from 'angular-2-local-storage';
import {HttpClientModule} from '@angular/common/http';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { LocalStorageModule } from 'angular-2-local-storage';
import { HttpClientModule } from '@angular/common/http';
import { SamplesComponent } from './samples/samples.component';
import {RbCustomInputsModule} from './rb-custom-inputs/rb-custom-inputs.module';
import { RbCustomInputsModule } from './rb-custom-inputs/rb-custom-inputs.module';
import { SampleComponent } from './sample/sample.component';
import { ValidateDirective } from './validate.directive';
import {CommonModule} from '@angular/common';
import { CommonModule } from '@angular/common';
import { ErrorComponent } from './error/error.component';
import { ObjectPipe } from './object.pipe';
import {BrowserAnimationsModule} from '@angular/platform-browser/animations';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { DocumentationComponent } from './documentation/documentation.component';
import { ImgMagnifierComponent } from './img-magnifier/img-magnifier.component';
import { ExistsPipe } from './exists.pipe';

View File

@ -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">

View File

@ -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");
}
}