diff options
author | Vitalii Lysak <v.lysak@dunice.net> | 2022-08-03 17:10:44 +0300 |
---|---|---|
committer | Vitalii Lysak <v.lysak@dunice.net> | 2022-08-03 17:10:44 +0300 |
commit | 3bce3e1f788debaf7e964655c9727a179fa78e1d (patch) | |
tree | 68ff143b2851a9ba37eb6c27b73ca4ecaec771cf /src/utilities | |
parent | c9923b6fc173fdbb4ec61dbee7285bce24a0c62c (diff) | |
download | webui-vue-3bce3e1f788debaf7e964655c9727a179fa78e1d.tar.xz |
upd serialization for new back api
Diffstat (limited to 'src/utilities')
-rw-r--r-- | src/utilities/_sila/metricProperties.js | 30 |
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; } |