优化统计

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

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

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

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

Loading…
Cancel
Save