2020-06-29 13:44:23 +00:00
|
|
|
import { Injectable } from '@angular/core';
|
|
|
|
import { IJsonline } from '../models/json-line';
|
|
|
|
import { ISenMLItem } from '../models/senml-item';
|
2020-06-29 13:51:08 +00:00
|
|
|
import { IDataLayer } from '../models/data.layer';
|
2020-06-29 14:09:19 +00:00
|
|
|
import { IItem } from '../models/item';
|
2020-06-29 13:44:23 +00:00
|
|
|
|
|
|
|
@Injectable({
|
|
|
|
providedIn: 'root',
|
|
|
|
})
|
|
|
|
export class SenmlService {
|
|
|
|
constructor() {
|
|
|
|
}
|
|
|
|
|
2020-06-29 14:09:19 +00:00
|
|
|
getSenMLItem(layer:IDataLayer,jsonLine:IJsonline): ISenMLItem {
|
2020-06-29 13:44:23 +00:00
|
|
|
if (jsonLine) {
|
|
|
|
var senmlPack = jsonLine.data as ISenMLItem[];
|
2020-06-29 14:09:19 +00:00
|
|
|
var temp = senmlPack.filter((i) => i.u == layer.indexKey);
|
2020-06-29 13:44:23 +00:00
|
|
|
if (temp.length == 1) return temp[0];
|
|
|
|
return null;
|
|
|
|
}
|
2020-06-29 13:51:08 +00:00
|
|
|
}
|
2020-06-29 13:44:23 +00:00
|
|
|
|
2020-06-29 14:09:19 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
2020-06-29 13:44:23 +00:00
|
|
|
}
|