mirror of
https://gitee.com/js-yhsec/energy_storage.git
synced 2026-05-28 11:19:24 +08:00
统计分析接口联调
This commit is contained in:
37
web/src/utils/dealWithData.js
Normal file
37
web/src/utils/dealWithData.js
Normal file
@@ -0,0 +1,37 @@
|
||||
export function getRunDays(date) {
|
||||
const launchDate = new Date(date)
|
||||
const today = new Date() // 替换为当前日期
|
||||
|
||||
const timeDiff = today - launchDate // 毫秒差
|
||||
const daysRun = Math.ceil(timeDiff / (1000 * 60 * 60 * 24)) // 转换为天数
|
||||
|
||||
console.log(`从 2023-01-01 到今天已经运行了 ${daysRun} 天`)
|
||||
|
||||
return daysRun
|
||||
}
|
||||
export function processData(data, keys) {
|
||||
data.sort((a, b) => {
|
||||
return new Date(a.dt) - new Date(b.dt)
|
||||
})
|
||||
const dates = data.map((item) => item.dt)
|
||||
const values = []
|
||||
keys.forEach((item, index) => {
|
||||
values[index] = data.map((dataValue) => dataValue[keys[index]])
|
||||
})
|
||||
|
||||
return {
|
||||
dates,
|
||||
values
|
||||
}
|
||||
}
|
||||
|
||||
export function getDateDaysAgo(daysAgo) {
|
||||
const date = new Date()
|
||||
date.setDate(date.getDate() - daysAgo)
|
||||
|
||||
const year = date.getFullYear()
|
||||
const month = String(date.getMonth() + 1).padStart(2, '0')
|
||||
const day = String(date.getDate()).padStart(2, '0')
|
||||
|
||||
return `${year}-${month}-${day}`
|
||||
}
|
||||
Reference in New Issue
Block a user