ModuleCalculate
parent
4be59b1825
commit
d15244b635
|
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
"device": [18,19]
|
||||
}
|
||||
|
|
@ -6,13 +6,13 @@ export class ZvksmetricsController {
|
|||
constructor(private readonly metricsService: ZvksmetricsService) { }
|
||||
|
||||
@Get('ranges')
|
||||
async getHello(): Promise<any> {
|
||||
async getHello(@Body() inputMetrics: any): Promise<any> {
|
||||
let a: number = 7;
|
||||
let b: number = 9;
|
||||
let sum: any = { value: (a + b) / 4 * b + a };
|
||||
await this.metricsService.useStatusModel(1);
|
||||
await this.metricsService.useStatusModel(inputMetrics);
|
||||
// let a = await this.metricsService.showStatus();
|
||||
// console.log(sum.value);
|
||||
// console.log(inputMetrics);
|
||||
return sum.value;
|
||||
}
|
||||
|
||||
|
|
@ -38,8 +38,6 @@ export class ZvksmetricsController {
|
|||
|
||||
@Post('input')
|
||||
async getPostMessage(@Body() inputMetrics: any): Promise<string> {
|
||||
// console.log(inputMetrics);
|
||||
// console.log(23+12);
|
||||
console.log(inputMetrics);
|
||||
let out: any = await this.metricsService.useStatusModel(inputMetrics);
|
||||
return out;
|
||||
|
|
|
|||
|
|
@ -22,6 +22,8 @@ export class MetricK2 {
|
|||
@Injectable()
|
||||
export class K2Metrics {
|
||||
service_name: string;
|
||||
device: number;
|
||||
source: string;
|
||||
//endpoint_name: string;
|
||||
metrics: MetricK2[];
|
||||
};
|
||||
|
|
@ -72,44 +74,15 @@ export class ZvksmetricsService {
|
|||
// console.log(prev);
|
||||
|
||||
let intermediate = await this.getComplexMetricsValues(inp, prev, complex, model, scope);
|
||||
console.log(inp);
|
||||
// console.log(intermediate);
|
||||
|
||||
// console.log(inp.metrics[20], complex.metrics[2]);
|
||||
|
||||
const val = JSON.parse(JSON.stringify(model[0].values));
|
||||
// console.log(val.arr[1]);
|
||||
// console.log(val);
|
||||
|
||||
// const reif = JSON.parse(comlexCalc[1].values);
|
||||
// console.log(reif);
|
||||
|
||||
|
||||
|
||||
|
||||
// console.log(inp);
|
||||
// let rng: any = {val: [{x:3}, {x:4}, {x:5}, {x:9}]};
|
||||
// console.log(rng.val[0].x);
|
||||
// let testFormula: string = (rng.val[0].x + rng.val[1].x - rng.val[2].x + rng.val[3].x).toString();
|
||||
|
||||
// let formula: string = scope[0].ranges[0].sum;
|
||||
// let value: any = {formula};
|
||||
// console.log(evaluate(testFormula, rng));
|
||||
|
||||
// console.log(JSON.stringify("arr:[191, 192, 193]"));
|
||||
|
||||
let x: any = { arr: ["191", "192", "193"], prev: ["1", "1"], abb: ["1", "34"] };
|
||||
//let k = JSON.parse(scope[0].ranges[0].values); //
|
||||
//let y: string = scope[0].ranges[0].formula;
|
||||
let y = "arr[1]/prev[1]*abb[1]+arr[2]*prev[2]+arr[3]+prev[1]/prev[2]";
|
||||
// console.log(y, x);
|
||||
// console.log(evaluate(y, x));
|
||||
|
||||
// let editedMetrics : K2Metrics = await this.getMetrics (inp, comlexCalc, scope);
|
||||
let responseFromExporter: any = await this.sendMetrics(intermediate);
|
||||
let responseFromExporter1: any = await this.sendMetrics(inp);
|
||||
|
||||
// console.log(inp.metrics[200].device);
|
||||
|
||||
prev = inp;
|
||||
|
||||
return responseFromExporter;
|
||||
|
|
@ -132,24 +105,28 @@ export class ZvksmetricsService {
|
|||
let length: number = complexCalc.length;
|
||||
let metrics: MetricK2[] = complexData.metrics;
|
||||
|
||||
// let val = await this.setComplexMetricValue(complexCalc[0].values, complexCalc[0].formula, inputData.metrics, prevousData.metrics);
|
||||
// let status = 3;
|
||||
let devices: number [] = [18,19];
|
||||
let device_len: number = devices.length;
|
||||
|
||||
for (let i = 0; i < length; i++) {
|
||||
let val = await this.setComplexMetricValue(complexCalc[i].values, complexCalc[i].formula, inputData.metrics, prevousData.metrics);
|
||||
let status = 3;
|
||||
let complexMetric = new MetricK2();
|
||||
complexMetric.id = complexCalc[i].id;
|
||||
complexMetric.name = complexCalc[i].name;
|
||||
complexMetric.type = inputData.metrics[0].type;
|
||||
complexMetric.addr = inputData.metrics[0].addr;
|
||||
complexMetric.value = val;
|
||||
complexMetric.description = complexCalc[i].name;
|
||||
complexMetric.status = status;
|
||||
// complexMetric.device = number(inputData.metrics.find(el => el.name == complexMetric.name)?.device);
|
||||
// complexMetric.device = inputData.metrics[0].device;
|
||||
// complexMetric.source = string(inputData.metrics.find(elem => elem.name == complexMetric.name)?.source);
|
||||
metrics.push(complexMetric);
|
||||
// const jsonData = require('../conf/devices.json');
|
||||
// console.log(jsonData);
|
||||
for (let d = 0; d<device_len; d++){
|
||||
for (let i = 0; i < length; i++) {
|
||||
let metr = {"source": ""};
|
||||
let val = await this.setComplexMetricValue(complexCalc[i].values, complexCalc[i].formula, inputData.metrics, prevousData.metrics, devices[d], metr);
|
||||
let status = 3;
|
||||
let complexMetric = new MetricK2();
|
||||
complexMetric.id = complexCalc[i].id;
|
||||
complexMetric.name = complexCalc[i].name;
|
||||
complexMetric.type = inputData.metrics[0].type;
|
||||
complexMetric.addr = inputData.metrics[0].addr;
|
||||
complexMetric.value = val;
|
||||
complexMetric.description = complexCalc[i].name;
|
||||
complexMetric.status = status;
|
||||
complexMetric.device = devices[d];
|
||||
complexMetric.source = metr.source;
|
||||
metrics.push(complexMetric);
|
||||
}
|
||||
}
|
||||
|
||||
console.log(complexData);
|
||||
|
|
@ -157,21 +134,25 @@ export class ZvksmetricsService {
|
|||
return complexData;
|
||||
}
|
||||
|
||||
async setComplexMetricValue(value: string, formula: string, currMetrics: MetricK2[], prevMetrics: MetricK2[]): Promise<number> {
|
||||
async setComplexMetricValue(value: string, formula: string, currMetrics: MetricK2[], prevMetrics: MetricK2[], device: number, obj: any): Promise<number> {
|
||||
const val = JSON.parse(JSON.stringify(value));
|
||||
let arr = val.arr;
|
||||
let arr_len: number = arr.length;
|
||||
obj.source = currMetrics.find(element => element.name == arr[0] && element.device == device)?.source;
|
||||
// console.log(obj.source);
|
||||
|
||||
for (let i = 0; i < arr_len; i++) {
|
||||
arr[i] = currMetrics.find(element => element.name == arr[i])?.value;
|
||||
arr[i] = currMetrics.find(element => element.name == arr[i] && element.device == device)?.value;
|
||||
}
|
||||
let prevarr = val.prevarr;
|
||||
if (prevarr) {
|
||||
let prevarr_len: number = prevarr.length;
|
||||
for (let i = 0; i < prevarr_len; i++) {
|
||||
prevarr[i] = prevMetrics.find(element => element.name == prevarr[i])?.value;
|
||||
prevarr[i] = prevMetrics.find(element => element.name == prevarr[i] && element.device == device)?.value;
|
||||
}
|
||||
}
|
||||
// console.log(val);
|
||||
|
||||
// console.log(obj.soure);
|
||||
let result: number = evaluate(formula, val);
|
||||
// console.log(result);
|
||||
return result;
|
||||
|
|
|
|||
Loading…
Reference in New Issue