summaryrefslogtreecommitdiff
path: root/src/utilities
diff options
context:
space:
mode:
authorVitalii Lysak <v.lysak@dunice.net>2022-08-03 17:10:44 +0300
committerVitalii Lysak <v.lysak@dunice.net>2022-08-03 17:10:44 +0300
commit3bce3e1f788debaf7e964655c9727a179fa78e1d (patch)
tree68ff143b2851a9ba37eb6c27b73ca4ecaec771cf /src/utilities
parentc9923b6fc173fdbb4ec61dbee7285bce24a0c62c (diff)
downloadwebui-vue-3bce3e1f788debaf7e964655c9727a179fa78e1d.tar.xz
upd serialization for new back api
Diffstat (limited to 'src/utilities')
-rw-r--r--src/utilities/_sila/metricProperties.js30
1 files changed, 11 insertions, 19 deletions
diff --git a/src/utilities/_sila/metricProperties.js b/src/utilities/_sila/metricProperties.js
index 32495605..389c4683 100644
--- a/src/utilities/_sila/metricProperties.js
+++ b/src/utilities/_sila/metricProperties.js
@@ -1,6 +1,6 @@
export function getItems(data) {
let filteredData = data.filter((metric) => {
- return metric.MetricValue !== 'nan';
+ return metric.Value !== 'nan';
});
let transform = filteredData.map((metric) => {
@@ -12,19 +12,19 @@ export function getItems(data) {
date.getHours() + ':' + String(date.getMinutes()).padStart(2, '0'),
date: formatDate(date),
},
- MetricValue: Math.round(metric.MetricValue),
+ Value: Math.round(metric.Value),
};
});
let group = transform.reduce(function (rv, x) {
- (rv[x['MetricProperty']] = rv[x['MetricProperty']] || []).push(x);
+ (rv[x['Sensor']] = rv[x['Sensor']] || []).push(x);
return rv;
}, {});
return Object.keys(group).map((metric) => {
return {
name: metric,
- current: group[metric][group[metric].length - 1].MetricValue,
+ current: group[metric][group[metric].length - 1].Value,
middle: findAverage(group[metric]),
min: findMin(group[metric]),
minDate: findDateOfMin(group[metric]),
@@ -50,33 +50,25 @@ function findAverage(arr) {
const { length } = arr;
return Math.round(
arr.reduce((acc, val) => {
- return acc + val.MetricValue / length;
+ return acc + val.Value / length;
}, 0)
);
}
function findMin(arr) {
- return arr.reduce(
- (min, p) => (p.MetricValue < min ? p.MetricValue : min),
- arr[0].MetricValue
- );
+ return arr.reduce((min, p) => (p.Value < min ? p.Value : min), arr[0].Value);
}
function findMax(arr) {
- return arr.reduce(
- (max, p) => (p.MetricValue > max ? p.MetricValue : max),
- arr[0].MetricValue
- );
+ return arr.reduce((max, p) => (p.Value > max ? p.Value : max), arr[0].Value);
}
function findDateOfMin(arr) {
- return arr.reduce((res, obj) =>
- obj.MetricValue < res.MetricValue ? obj : res
- ).Timestamp;
+ return arr.reduce((res, obj) => (obj.Value < res.Value ? obj : res))
+ .Timestamp;
}
function findDateOfMax(arr) {
- return arr.reduce((res, obj) =>
- obj.MetricValue > res.MetricValue ? obj : res
- ).Timestamp;
+ return arr.reduce((res, obj) => (obj.Value > res.Value ? obj : res))
+ .Timestamp;
}