优化统计

menu1.0
fanluyan 1 month ago
parent 7e917bd8be
commit b033caa832

@ -8,7 +8,7 @@ const service = axios.create({
// baseURL: '',
// timeout: 5000
baseURL: "api", //把原来的项目地址改成api解决跨域问题
timeout: 60000,
timeout: 600000,
});
service.interceptors.request.use((config) => {

@ -87,16 +87,20 @@ export default {
this.picloading = false;
});
},
//
processData() {
const channelPresetMap = {};
//
this.picListData.forEach((photo) => {
const channel = photo.channnelname;
const presetId = photo.presetId;
const hour = new Date(photo.photoTime).getHours();
console.log("我是时间", hour);
const photoTime = new Date(photo.photoTime);
// 0-47
const hour = photoTime.getHours();
const minute = photoTime.getMinutes();
const halfHourIndex = hour * 2 + (minute >= 30 ? 1 : 0);
const key = `${channel}-${presetId}`;
if (!channelPresetMap[key]) {
@ -104,12 +108,12 @@ export default {
channel: channel,
presetId: presetId,
totalCount: 0,
hourlyData: new Array(24).fill(0),
hourlyData: new Array(48).fill(0), // 48
};
}
channelPresetMap[key].totalCount++;
channelPresetMap[key].hourlyData[hour]++;
channelPresetMap[key].hourlyData[halfHourIndex]++; //
});
//
@ -123,7 +127,8 @@ export default {
channel: item.channel,
presetId: `预置位:${item.presetId}`,
totalCount: item.totalCount,
anomalies: anomalies.join(", "),
// anomalies: anomalies.join(", "),
anomalies: anomalies.length > 0 ? anomalies.join(", ") : "正常",
};
});
});
@ -144,25 +149,93 @@ export default {
.sort()
.map((channel) => grouped[channel]);
},
//
// detectAnomalies
detectAnomalies(hourlyData) {
const anomalies = [];
const now = new Date(); //
const currentHour = now.getHours(); //
hourlyData.forEach((count, hour) => {
//
if (hour <= currentHour) {
if (count > 2) {
anomalies.push(`${hour}:00 - 多${count - 2}`);
} else if (count < 2) {
anomalies.push(`${hour}:00 - 少${2 - count}`);
}
const startTime = new Date(this.paramsData.starttime);
const endTime = new Date(this.paramsData.endtime);
// 10:00, 10:30, 11:00
const halfHourlyPoints = this.getHalfHourlyPoints(startTime, endTime);
halfHourlyPoints.forEach((timeStr) => {
// "10:00"0-47
const index = this.timeToHalfHourIndex(timeStr);
const count = hourlyData[index] || 0;
// 1/
if (count > 1) {
anomalies.push(`${timeStr} - 多${count - 1}`);
} else if (count < 1) {
anomalies.push(`${timeStr} - 少${1 - count}`);
}
});
return anomalies;
},
//
getHoursInRange(startTime, endTime) {
const startHour = startTime.getHours();
const endHour = endTime.getHours();
const hours = [];
if (startTime <= endTime) {
//
for (let h = startHour; h <= endHour; h++) {
hours.push(h);
}
} else {
// startHour230endHour
for (let h = startHour; h < 24; h++) {
hours.push(h);
}
for (let h = 0; h <= endHour; h++) {
hours.push(h);
}
}
return hours;
},
// HH:mm
getHalfHourlyPoints(startTime, endTime) {
const points = [];
let current = new Date(startTime);
// 10:15 10:00
current.setMinutes(current.getMinutes() >= 30 ? 30 : 0, 0, 0);
while (current <= endTime) {
const hours = current.getHours().toString().padStart(2, "0");
const minutes = current.getMinutes().toString().padStart(2, "0");
points.push(`${hours}:${minutes}`);
current = new Date(current.getTime() + 30 * 60 * 1000); // 30
}
return points;
},
// HH:mm 0-47
timeToHalfHourIndex(timeStr) {
const [hours, minutes] = timeStr.split(":").map(Number);
return hours * 2 + (minutes >= 30 ? 1 : 0);
},
// //
// detectAnomalies(hourlyData) {
// const anomalies = [];
// const now = new Date(); //
// const currentHour = now.getHours(); //
// hourlyData.forEach((count, hour) => {
// //
// if (hour <= currentHour) {
// if (count > 2) {
// anomalies.push(`${hour}:00 - ${count - 2}`);
// } else if (count < 2) {
// anomalies.push(`${hour}:00 - ${2 - count}`);
// }
// }
// });
// return anomalies;
// },
//
handleCurrentChange(val) {
this.page = val;

@ -116,18 +116,17 @@
</template>
</el-table-column>
<!-- <el-table-column prop="id" label="ID" width="80px"> </el-table-column> -->
<el-table-column prop="dyName" label="电压等级" sortable>
</el-table-column>
<el-table-column prop="dyName" label="电压" sortable> </el-table-column>
<el-table-column
prop="lineName"
label="线路名称"
label="线路"
show-overflow-tooltip
sortable
>
</el-table-column>
<el-table-column
prop="towerName"
label="杆塔名称"
label="杆塔"
min-width="180"
show-overflow-tooltip
sortable
@ -178,7 +177,7 @@
></template
>
</el-table-column>
<el-table-column
<!-- <el-table-column
prop="firstPhotoTime"
label="当天第一张照片时间"
min-width="130"
@ -189,10 +188,10 @@
<template slot-scope="scope">
{{ scope.row.photoInfo.firstPhotoTime }}
</template>
</el-table-column>
</el-table-column> -->
<el-table-column
prop="lastPhotoTime"
label="照片最后拍摄时间"
label="最后拍照时间"
min-width="130"
show-overflow-tooltip
sortable
@ -204,7 +203,7 @@
</el-table-column>
<el-table-column
prop="lastRecvTime"
label="照片最后接收时间"
label="最后接收时间"
min-width="130"
show-overflow-tooltip
sortable
@ -214,11 +213,11 @@
{{ scope.row.photoInfo.lastRecvTime }}
</template>
</el-table-column>
<el-table-column prop="rebootCount" label="重启次数" sortable>
<el-table-column prop="rebootCount" label="重启" sortable>
</el-table-column>
<el-table-column
prop="workingStatus.bootTime"
label="最后重启时间"
label="最后重启"
min-width="130"
show-overflow-tooltip
sortable
@ -642,4 +641,7 @@ export default {
}
}
}
.el-date-table td.prev-month {
color: #606266;
}
</style>

Loading…
Cancel
Save