diff options
Diffstat (limited to 'src/utilities/_sila/metricProperties.js')
-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; } |