feat:修正mos和cct查询时间范围
This commit is contained in:
@@ -399,8 +399,8 @@ async function fetchMosData(neId: string) {
|
|||||||
console.log('MOS数据响应:', res)
|
console.log('MOS数据响应:', res)
|
||||||
|
|
||||||
if (res.code === 1 && Array.isArray(res.data)) {
|
if (res.code === 1 && Array.isArray(res.data)) {
|
||||||
// 使用24小时数据补全功能
|
// 使用当天0点到现在的数据补全功能
|
||||||
mosData.value = generate24HourTimeSeries(res.data, 'mosAvg')
|
mosData.value = generateTodayTimeSeries(res.data, 'mosAvg')
|
||||||
console.log('MOS数据加载完成:', mosData.value)
|
console.log('MOS数据加载完成:', mosData.value)
|
||||||
|
|
||||||
// 更新MOS图表
|
// 更新MOS图表
|
||||||
@@ -441,8 +441,8 @@ async function fetchCctData(neId: string) {
|
|||||||
console.log('CCT数据响应:', res)
|
console.log('CCT数据响应:', res)
|
||||||
|
|
||||||
if (res.code === 1 && Array.isArray(res.data)) {
|
if (res.code === 1 && Array.isArray(res.data)) {
|
||||||
// 使用24小时数据补全功能
|
// 使用当天0点到现在的数据补全功能
|
||||||
cctData.value = generate24HourTimeSeries(res.data, 'cctAvg')
|
cctData.value = generateTodayTimeSeries(res.data, 'cctAvg')
|
||||||
console.log('CCT数据加载完成:', cctData.value)
|
console.log('CCT数据加载完成:', cctData.value)
|
||||||
|
|
||||||
// 更新CCT图表
|
// 更新CCT图表
|
||||||
@@ -2125,25 +2125,35 @@ function calculateMosCctTimeDifference(latestData: any, previousData: any) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 生成24小时完整时间序列数据(用于MOS/CCT数据补全)
|
// 生成当天0点到现在的完整时间序列数据(用于MOS/CCT数据补全)
|
||||||
function generate24HourTimeSeries(rawData: any[], dataField: string) {
|
function generateTodayTimeSeries(rawData: any[], dataField: string) {
|
||||||
if (!rawData || rawData.length === 0) {
|
if (!rawData || rawData.length === 0) {
|
||||||
// 如果没有数据,返回24个0值
|
// 如果没有数据,返回当天0点到现在的0值数据点
|
||||||
return Array.from({ length: 24 }, (_, i) => ({
|
const now = new Date()
|
||||||
timeGroup: Math.floor(Date.now() / 1000) - (23 - i) * 3600,
|
const todayStart = new Date(now.getFullYear(), now.getMonth(), now.getDate(), 0, 0, 0)
|
||||||
|
const hoursFromStart = Math.floor((now.getTime() - todayStart.getTime()) / (1000 * 60 * 60))
|
||||||
|
|
||||||
|
return Array.from({ length: hoursFromStart + 1 }, (_, i) => ({
|
||||||
|
timeGroup: Math.floor(todayStart.getTime() / 1000) + i * 3600,
|
||||||
[dataField]: 0
|
[dataField]: 0
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取当前时间(秒级时间戳)
|
// 获取当前时间和当天0点
|
||||||
const now = Math.floor(Date.now() / 1000)
|
const now = new Date()
|
||||||
|
const todayStart = new Date(now.getFullYear(), now.getMonth(), now.getDate(), 0, 0, 0)
|
||||||
|
const todayStartTimestamp = Math.floor(todayStart.getTime() / 1000)
|
||||||
|
const nowTimestamp = Math.floor(now.getTime() / 1000)
|
||||||
|
|
||||||
// 生成过去24小时的完整时间点(每小时一个点)
|
// 计算从当天0点到现在的小时数
|
||||||
const timePoints = Array.from({ length: 24 }, (_, i) => {
|
const hoursFromStart = Math.floor((nowTimestamp - todayStartTimestamp) / 3600)
|
||||||
const hourTimestamp = now - (23 - i) * 3600
|
|
||||||
|
// 生成当天0点到现在的完整时间点(每小时一个点)
|
||||||
|
const timePoints = Array.from({ length: hoursFromStart + 1 }, (_, i) => {
|
||||||
|
const hourTimestamp = todayStartTimestamp + i * 3600
|
||||||
return {
|
return {
|
||||||
timestamp: hourTimestamp,
|
timestamp: hourTimestamp,
|
||||||
hourStart: Math.floor(hourTimestamp / 3600) * 3600 // 整点时间
|
hourStart: hourTimestamp // 已经是整点时间
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -2155,7 +2165,7 @@ function generate24HourTimeSeries(rawData: any[], dataField: string) {
|
|||||||
dataMap.set(hourStart, item)
|
dataMap.set(hourStart, item)
|
||||||
})
|
})
|
||||||
|
|
||||||
// 补全24小时数据
|
// 补全当天数据
|
||||||
const completeData = timePoints.map(({ hourStart }) => {
|
const completeData = timePoints.map(({ hourStart }) => {
|
||||||
const existingData = dataMap.get(hourStart)
|
const existingData = dataMap.get(hourStart)
|
||||||
if (existingData) {
|
if (existingData) {
|
||||||
|
|||||||
Reference in New Issue
Block a user