From 53dd7333d585012f5cfbf27218f443d03557c326 Mon Sep 17 00:00:00 2001
From: geting <13585118195@163.com>
Date: Thu, 28 Nov 2024 14:09:36 +0800
Subject: [PATCH] =?UTF-8?q?=E7=BB=9F=E8=AE=A1=E5=88=86=E6=9E=90?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../backend/statAnalysis/trendAnalysis.vue | 42 +-
.../backend/statAnalysis/trendComparison.vue | 415 ++++++++++--------
2 files changed, 269 insertions(+), 188 deletions(-)
diff --git a/ui/dasadmin/src/views/backend/statAnalysis/trendAnalysis.vue b/ui/dasadmin/src/views/backend/statAnalysis/trendAnalysis.vue
index ccd2e7c8..680641b9 100644
--- a/ui/dasadmin/src/views/backend/statAnalysis/trendAnalysis.vue
+++ b/ui/dasadmin/src/views/backend/statAnalysis/trendAnalysis.vue
@@ -111,6 +111,7 @@ const statAnalysisSelect = reactive({
attributeCode: '',
interval: '',
time: '',
+ unit: '',
})
const getFormattedDate = (offset: number) => {
const date = new Date()
@@ -123,7 +124,7 @@ const getFormattedDate = (offset: number) => {
const times: any = reactive([[getFormattedDate(0) + ' 00:00:00', getFormattedDate(0) + ' 23:59:59']])
const addTime = () => {
if (times.length < 4) {
- times.push([getFormattedDate(times.length) + ' 00:00:00', getFormattedDate(times.length) + ' 23:59:59'])
+ times.push([getFormattedDate(-times.length) + ' 00:00:00', getFormattedDate(-times.length) + ' 23:59:59'])
customName.push(statAnalysisSelect.attributes + String(times.length))
} else {
ElMessage.info('最多可添加四条查询曲线!')
@@ -161,21 +162,27 @@ const attributesChange = () => {
const deviceIdChange = () => {
statAnalysisSelect.attributes = ''
statAnalysisSelect.attributeCode = ''
+ statAnalysisSelect.unit = ''
}
const showMeasure = ref(false)
const selectedAttrRow: any = ref({
attributeCode: '',
attributeName: '',
+ unit: '',
})
const handleRadioChange = (value: any) => {
- const { attributeCode, attributeName } = { ...value }
+ console.log('🚀 ~ handleRadioChange ~ value:', value)
+ const { attributeCode, attributeName, unit } = { ...value }
selectedAttrRow.attributeCode = attributeCode
selectedAttrRow.attributeName = attributeName
+ selectedAttrRow.unit = unit
}
const selectstatAnalysisAttributes = () => {
statAnalysisSelect.attributes = selectedAttrRow.attributeName
+ console.log('🚀 ~ selectstatAnalysisAttributes ~ selectedAttrRow:', selectedAttrRow)
statAnalysisSelect.attributeCode = selectedAttrRow.attributeCode
+ statAnalysisSelect.unit = selectedAttrRow.unit
showMeasure.value = false
customName.forEach((item: any, index: number, arr: any) => {
arr[index] = statAnalysisSelect.attributes + String(index + 1)
@@ -343,6 +350,8 @@ const calculate: any = ref([{ max: '', min: '', average: '' }])
var xDatas: any = []
const isLoading = ref(false)
const statAnalysisOperate = () => {
+ console.log('🚀 ~ findTime ~ times:', times)
+
const findTime = times.filter((item: any) => {
return Array.isArray(item)
})
@@ -355,6 +364,9 @@ const statAnalysisOperate = () => {
} else if (!findTime.length) {
ElMessage.info('请选择查询时间!')
return
+ } else if (hasDuplicateArrays(times)) {
+ ElMessage.info('存在相同的查询时间!')
+ return
}
isLoading.value = true
option.series = []
@@ -363,8 +375,10 @@ const statAnalysisOperate = () => {
calculate.value = []
chart.value.setOption(option, { notMerge: true })
const promises: any = []
+
times.forEach((time: any, index: number) => {
- if (time[0] && time[1]) {
+ console.log('🚀 ~ times.forEach ~ time:', time)
+ if (time && time[0] && time[1]) {
const requestData = {
devices: [
{
@@ -415,7 +429,6 @@ const historyDataReq = (promises: any) => {
const fillData = fillMissingData(alltimes, resData)
const xData = fillData['times']
const yData = fillData['values']
- // calculate.value[index] = calculateStats(resData['values'])
xDatas.push({
series: String(customName[index]),
data: xData,
@@ -428,7 +441,7 @@ const historyDataReq = (promises: any) => {
.map((item: any) => {
const matchData = xDatas.filter((x: any) => x.series == item.seriesName)
const x = timestampToTime(matchData[0]['data'][item.dataIndex])
- return `${item.marker}${item.seriesName} (${x}): ${item.data}`
+ return `${item.marker}${item.seriesName} (${x}): ${item.data}${statAnalysisSelect.unit}`
})
.join('
')
},
@@ -484,17 +497,16 @@ const statAnalysisExport = () => {
})
}
-function calculateStats(numbers: any) {
- const max = Math.max(...numbers)
- const min = Math.min(...numbers)
- const sum = numbers.reduce((acc: number, current: number) => acc + current, 0)
- const average = sum / numbers.length
-
- return {
- max: max.toFixed(2),
- min: min.toFixed(2),
- average: average.toFixed(2),
+const hasDuplicateArrays = (arr: any) => {
+ const seen = new Set()
+ for (let subArray of arr) {
+ const subArrayStr = JSON.stringify(subArray)
+ if (seen.has(subArrayStr)) {
+ return true
+ }
+ seen.add(subArrayStr)
}
+ return false
}
const getTimestamps = (start: any, end: any, interval: any) => {
diff --git a/ui/dasadmin/src/views/backend/statAnalysis/trendComparison.vue b/ui/dasadmin/src/views/backend/statAnalysis/trendComparison.vue
index c26dadfd..27f3457b 100644
--- a/ui/dasadmin/src/views/backend/statAnalysis/trendComparison.vue
+++ b/ui/dasadmin/src/views/backend/statAnalysis/trendComparison.vue
@@ -20,7 +20,7 @@