updated to new model format
This commit is contained in:
@ -13,21 +13,17 @@
|
||||
<div *ngIf="result" class="result" [@inOut]>
|
||||
<ng-container *ngIf="multipleSamples; else singleSampleResult">
|
||||
<h4 *ngFor="let prediction of result.predictions; index as i">
|
||||
{{spectrumNames[i]}}: {{prediction}} {{activeGroup.models[activeModelIndex].label}}
|
||||
<a [routerLink]='"."' fragment="disclaimer"><sup>#</sup></a>
|
||||
{{spectrumNames[i]}}: {{prediction}}<a [routerLink]='"."' fragment="disclaimer"><sup>#</sup></a>
|
||||
</h4>
|
||||
</ng-container>
|
||||
<ng-template #singleSampleResult>
|
||||
<h4>
|
||||
Average result: {{result.meanPrediction}} {{activeGroup.models[activeModelIndex].label}}
|
||||
<a [routerLink]='"."' fragment="disclaimer"><sup>#</sup></a>,
|
||||
standard deviation: {{result.std}}<a [routerLink]='"."' fragment="disclaimer"><sup>#</sup></a>
|
||||
Average result: {{result.mean}}<a [routerLink]='"."' fragment="disclaimer"><sup>#</sup></a>
|
||||
</h4>
|
||||
<a href="javascript:" class="rb-details-toggle" rbDetailsToggle #triggerDetails="rbDetailsToggle">Details</a>
|
||||
<div *ngIf="triggerDetails.open" class="space-below">
|
||||
<p *ngFor="let prediction of result.predictions; index as i">
|
||||
{{spectrumNames[i]}}: {{prediction}} {{activeGroup.models[activeModelIndex].label}}
|
||||
<a [routerLink]='"."' fragment="disclaimer"><sup>#</sup></a>
|
||||
{{spectrumNames[i]}}: {{prediction}}<a [routerLink]='"."' fragment="disclaimer"><sup>#</sup></a>
|
||||
</p>
|
||||
</div>
|
||||
</ng-template>
|
||||
|
@ -3,15 +3,10 @@ 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 {HttpClient} from '@angular/common/http';
|
||||
|
||||
interface PredictionResult {
|
||||
meanPrediction: string;
|
||||
std: string;
|
||||
predictions: string[];
|
||||
}
|
||||
|
||||
@Component({
|
||||
selector: 'app-prediction',
|
||||
@ -34,7 +29,7 @@ interface PredictionResult {
|
||||
})
|
||||
export class PredictionComponent implements OnInit {
|
||||
|
||||
result: PredictionResult;
|
||||
result: {predictions: string[], mean: string};
|
||||
loading = false;
|
||||
activeGroup: ModelItemModel = new ModelItemModel();
|
||||
activeModelIndex = 0;
|
||||
@ -104,9 +99,16 @@ export class PredictionComponent implements OnInit {
|
||||
|
||||
loadPrediction() {
|
||||
this.loading = true;
|
||||
console.log(this.activeModelIndex);
|
||||
this.api.post<PredictionResult>(this.activeGroup.models[this.activeModelIndex].url, this.flattenedSpectra, data => {
|
||||
this.result = data;
|
||||
this.api.post<any>(this.activeGroup.models[this.activeModelIndex].url, this.flattenedSpectra, data => {
|
||||
this.result = {
|
||||
predictions: Object.entries(omit(data, ['mean', 'std', 'label']))
|
||||
.map((p: any) => p[1].map(e => `${p[0]}: ${e} ${data.label[p[0]]}`))
|
||||
.reduce((s, e) => s.map((el, i) => this.clip(el) + ', ' + e[i])),
|
||||
mean: Object.keys(data.mean).map(e =>
|
||||
this.clip(`${e}: ${data.mean[e]} ${data.label[e]}`) + (data.std[e] !== '' ? ` (standard deviation: ${data.std[e]})` : '')
|
||||
).join(', ')
|
||||
};
|
||||
console.log(this.result);
|
||||
this.loading = false;
|
||||
});
|
||||
}
|
||||
@ -115,4 +117,8 @@ export class PredictionComponent implements OnInit {
|
||||
this.activeGroup = this.d.arr.modelGroups[index];
|
||||
this.result = undefined;
|
||||
}
|
||||
|
||||
clip(str) { // clip spaces at start and end
|
||||
return str.replace(/^\s*(.*?)\s*$/, '$1');
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user