summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVitalii Lysak <v.lysak@dunice.net>2022-07-22 20:09:09 +0300
committerVitalii Lysak <v.lysak@dunice.net>2022-07-22 20:09:09 +0300
commit39c7d4d68411571b4d3fe81409ef805ca874c141 (patch)
treef69323674008d2fcca8726259e4890be9d09eff5
parent5541fa8aa255edda1904631294e7c7ecb6650245 (diff)
downloadwebui-vue-39c7d4d68411571b4d3fe81409ef805ca874c141.tar.xz
add table, processor
-rw-r--r--src/components/_sila/Global/Chart.vue8
-rw-r--r--src/utilities/_sila/metricProperties.js84
-rw-r--r--src/views/_sila/Processors/Dynamic/ProcessorsDynamicPage.vue8
3 files changed, 96 insertions, 4 deletions
diff --git a/src/components/_sila/Global/Chart.vue b/src/components/_sila/Global/Chart.vue
index c5214bd7..a74c5425 100644
--- a/src/components/_sila/Global/Chart.vue
+++ b/src/components/_sila/Global/Chart.vue
@@ -79,9 +79,11 @@ export default {
let arr = Object.keys(groupTime).map((key) => {
const findAverage = (arr) => {
const { length } = arr;
- return arr.reduce((acc, val) => {
- return Math.round(acc + val.MetricValue / length);
- }, 0);
+ return Math.round(
+ arr.reduce((acc, val) => {
+ return acc + val.MetricValue / length;
+ }, 0)
+ );
};
return findAverage(groupTime[key]);
});
diff --git a/src/utilities/_sila/metricProperties.js b/src/utilities/_sila/metricProperties.js
new file mode 100644
index 00000000..5dd58014
--- /dev/null
+++ b/src/utilities/_sila/metricProperties.js
@@ -0,0 +1,84 @@
+export function getItems(data) {
+ let filteredData = data.filter((metric) => {
+ return metric.MetricValue !== 'nan';
+ });
+
+ let transform = filteredData.map((metric) => {
+ let date = new Date(metric.Timestamp);
+ let time =
+ date.getHours() +
+ ':' +
+ String(date.getMinutes()).padStart(2, '0') +
+ ' ' +
+ formatDate(date);
+ return {
+ ...metric,
+ Timestamp: time,
+ MetricValue: Math.round(metric.MetricValue),
+ };
+ });
+
+ let group = transform.reduce(function (rv, x) {
+ (rv[x['MetricProperty']] = rv[x['MetricProperty']] || []).push(x);
+ return rv;
+ }, {});
+
+ return Object.keys(group).map((metric) => {
+ return {
+ name: metric,
+ currentTemperature: group[metric][group[metric].length - 1].MetricValue,
+ middleTemperature: findAverage(group[metric]),
+ minTemperature: findMin(group[metric]),
+ minDate: findDateOfMin(group[metric]),
+ maxTemperature: findMax(group[metric]),
+ maxDate: findDateOfMax(group[metric]),
+ };
+ });
+}
+
+function padTo2Digits(num) {
+ return num.toString().padStart(2, '0');
+}
+
+function formatDate(date) {
+ return [
+ padTo2Digits(date.getDate()),
+ padTo2Digits(date.getMonth() + 1),
+ date.getFullYear(),
+ ].join('.');
+}
+
+function findAverage(arr) {
+ const { length } = arr;
+ return Math.round(
+ arr.reduce((acc, val) => {
+ return acc + val.MetricValue / length;
+ }, 0)
+ );
+}
+
+function findMin(arr) {
+ return arr.reduce(
+ (min, p) => (p.MetricValue < min ? p.MetricValue : min),
+ arr[0].MetricValue
+ );
+}
+
+function findMax(arr) {
+ return arr.reduce(
+ (max, p) => (p.MetricValue > max ? p.MetricValue : max),
+ arr[0].MetricValue
+ );
+}
+
+function findDateOfMin(arr) {
+ return arr.reduce((res, obj) =>
+ obj.MetricValue < res.MetricValue ? obj : res
+ ).Timestamp;
+}
+
+function findDateOfMax(arr) {
+ return arr.reduce((res, obj) =>
+ obj.MetricValue > res.MetricValue ? obj : res
+ ).Timestamp;
+}
diff --git a/src/views/_sila/Processors/Dynamic/ProcessorsDynamicPage.vue b/src/views/_sila/Processors/Dynamic/ProcessorsDynamicPage.vue
index 6f30576a..44e5e18b 100644
--- a/src/views/_sila/Processors/Dynamic/ProcessorsDynamicPage.vue
+++ b/src/views/_sila/Processors/Dynamic/ProcessorsDynamicPage.vue
@@ -82,6 +82,8 @@ import LoadingBarMixin from '@/components/_sila/Mixins/LoadingBarMixin';
import TableFilterMixin from '@/components/_sila/Mixins/TableFilterMixin';
import Collapse from '@/components/_sila/Global/Collapse';
+import { getItems } from '@/utilities/_sila/metricProperties';
+
export default {
components: { PageTitle, Collapse, PageSection, Chart },
mixins: [DataFormatterMixin, LoadingBarMixin, TableFilterMixin],
@@ -197,7 +199,11 @@ export default {
});
},
},
-
+ watch: {
+ filteredSensors(data) {
+ this.items = getItems(data);
+ },
+ },
created() {
this.startLoader();
this.$store.dispatch('processors/getProcessorsDynamic').finally(() => {