FarmMapsLib/projects/common/src/fm/services/senml-service.ts
Willem Dantuma 214dc3ffa1
All checks were successful
FarmMaps.Develop/FarmMapsLib/pipeline/head This commit looks good
Refactor temporallast
2020-06-29 16:09:19 +02:00

31 lines
1020 B
TypeScript

import { Injectable } from '@angular/core';
import { IJsonline } from '../models/json-line';
import { ISenMLItem } from '../models/senml-item';
import { IDataLayer } from '../models/data.layer';
import { IItem } from '../models/item';
@Injectable({
providedIn: 'root',
})
export class SenmlService {
constructor() {
}
getSenMLItem(layer:IDataLayer,jsonLine:IJsonline): ISenMLItem {
if (jsonLine) {
var senmlPack = jsonLine.data as ISenMLItem[];
var temp = senmlPack.filter((i) => i.u == layer.indexKey);
if (temp.length == 1) return temp[0];
return null;
}
}
getFirstLayer(item:IItem):IDataLayer {
if(item && item.data && item.data["layers"] && item.data["layers"].length > 0 ) {
return item.data["layers"][0] as IDataLayer;
} else {
let retVal:IDataLayer = { name:"Soil moisture",index:0,scale:1,unit:"%",indexKey:"%vol" };
return retVal;
}
}
}