updated to new model format
This commit is contained in:
parent
819666c344
commit
f0aad664d0
@ -15,9 +15,6 @@
|
||||
<ng-template rbFormValidationMessage="failure">{{nameInput.errors.failure}}</ng-template>
|
||||
<ng-template rbFormValidationMessage="required">Cannot be empty</ng-template>
|
||||
</rb-form-input>
|
||||
<rb-form-input name="label" label="label" appValidate="string" [(ngModel)]="model.label" #labelInput="ngModel">
|
||||
<ng-template rbFormValidationMessage="failure">{{labelInput.errors.failure}}</ng-template>
|
||||
</rb-form-input>
|
||||
<rb-form-input name="url" label="URL" appValidate="url" required [(ngModel)]="model.url" #urlInput="ngModel">
|
||||
<ng-template rbFormValidationMessage="failure">{{urlInput.errors.failure}}</ng-template>
|
||||
<ng-template rbFormValidationMessage="required">Cannot be empty</ng-template>
|
||||
@ -31,7 +28,6 @@
|
||||
<rb-table class="space-above">
|
||||
<tr>
|
||||
<th>Name</th>
|
||||
<th>Label</th>
|
||||
<th>URL</th>
|
||||
<th></th>
|
||||
<th></th>
|
||||
@ -41,7 +37,6 @@
|
||||
<tr><th>{{group.group}}</th><th></th><th></th><th></th><th></th></tr>
|
||||
<tr *ngFor="let modelItem of group.models">
|
||||
<td>{{modelItem.name}}</td>
|
||||
<td>{{modelItem.label}}</td>
|
||||
<td>{{modelItem.url}}</td>
|
||||
<td>
|
||||
<span class="rb-ic rb-ic-edit clickable"
|
||||
|
@ -4,7 +4,6 @@ export class ModelItemModel extends BaseModel {
|
||||
group = '';
|
||||
models = [{
|
||||
name: '',
|
||||
url: '',
|
||||
label: ''
|
||||
url: ''
|
||||
}];
|
||||
}
|
||||
|
@ -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');
|
||||
}
|
||||
}
|
||||
|
@ -238,7 +238,7 @@
|
||||
[(ngModel)]="measurement.measurement_template"
|
||||
(ngModelChange)="clearMeasurement(gIndex, mIndex)">
|
||||
<option [value]="sample.condition.condition_template">
|
||||
{{d.id.measurementTemplates[measurement.measurement_template].name}} - current
|
||||
{{d.id.measurementTemplates[measurement.measurement_template].name}} - old
|
||||
</option>
|
||||
<option *ngFor="let m of d.latest.measurementTemplates" [value]="m._id">{{m.name}}</option>
|
||||
</rb-form-select>
|
||||
@ -330,7 +330,7 @@
|
||||
<ng-template #modalDeleteConfirm>
|
||||
<rb-alert alertTitle="Are you sure?" type="danger" [okBtnLabel]="'Delete sample' + (samples.length > 1 ? 's' : '')"
|
||||
cancelBtnLabel="Cancel">
|
||||
Do you really want to delete {{samples.length > 1 ? 'these samples' : 'this sample'}}?
|
||||
Do you really want to delete {{(samples.length > 1 ? 'samples ' : 'sample ') + sampleNames()}}?
|
||||
</rb-alert>
|
||||
</ng-template>
|
||||
|
||||
|
@ -613,6 +613,10 @@ export class SampleComponent implements OnInit, AfterContentChecked {
|
||||
return this.sampleReferenceList.bind(this);
|
||||
}
|
||||
|
||||
sampleNames() {
|
||||
return this.samples.map(e => e.number).join(', ');
|
||||
}
|
||||
|
||||
uniqueCfValues(index) { // returns all names until index for unique check
|
||||
return this.customFields ? this.customFields.slice(0, index).map(e => e[0]) : [];
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user