Allow viscosity number predictions to be saved

This commit is contained in:
Kai S. K. Engelbart 2021-02-24 13:58:14 +01:00
parent 014ddcc2d7
commit 06e649671f
2 changed files with 31 additions and 6 deletions

View File

@ -40,7 +40,7 @@
</div>
<div class="file-input space-below">
<rb-form-file name="spectrum-upload" label="spectrum file" maxSize="10000000" class="space-below" multiple
<rb-form-file name="spectrum-upload" label="Spectrum File" maxSize="10000000" class="space-below" multiple
(ngModelChange)="fileToArray($event)" placeholder="Select file or drag and drop" dragDrop ngModel>
</rb-form-file>
@ -72,6 +72,20 @@
Export to PDF
</rb-icon-button>
<!-- Save Prediction -->
<!-- Only available for single sample viscosity number predictions -->
<div *ngIf="spectrumNames.length && !multipleSamples && activeGroup.group === 'Viscosity Number'">
<rb-form-input name="prediction-name" label="Prediction Name" [(ngModel)]="predictionName"></rb-form-input>
<rb-icon-button icon="forward-right" mode="secondary" (click)="savePrediction()" [rbModal]="modalSuccess">
Save Prediction
</rb-icon-button>
<ng-template #modalSuccess>
<rb-alert alertTitle="Success" type="success" okBtnLabel="Got it">
Prediction saved!
</rb-alert>
</ng-template>
</div>
<div class="dpt-chart space-below">
<canvas baseChart
class="dpt-chart"

View File

@ -39,8 +39,11 @@ export class PredictionComponent implements OnInit {
loading = false;
activeGroup: ModelItemModel = new ModelItemModel();
activeModelIndex = 0;
predictionName: String;
// If true, spectra belong to different samples, otherwise multiple spectra from the same sample are given
multipleSamples = false;
spectrumNames: string[] = [];
spectrum: string[][] = [[]];
flattenedSpectra = [];
@ -122,20 +125,28 @@ export class PredictionComponent implements OnInit {
});
}
groupChange(index) { // Group was changed
// Group was changed
groupChange(index) {
this.activeGroup = this.d.arr.modelGroups[index];
this.activeModelIndex = 0;
this.result = undefined;
}
// Save prediction to database
// This is not suited for multiple samples
savePrediction() {
let prediction = { name: this.predictionName, value: this.result.mean[0].value };
this.api.post<any>('/prediction/new', prediction);
}
// 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);
.map(prediction => prediction
.filter(field => field.category === 'Prediction')
.map(field => field.value));
return zip(this.spectrumNames, values);
}
// Generates a timestamp suitable for file naming