Autofill data between times

This commit is contained in:
2023-12-19 17:47:24 +08:00
parent 46ec332298
commit 810c301398
2 changed files with 58 additions and 11 deletions

View File

@@ -18,7 +18,7 @@ import { TopLevelFormatterParams } from 'echarts/types/dist/shared'
import '@/assets/css/pages/system/index.scss'
import { useUpdatedEffect } from '@/util/hooks'
import { formatByteSize } from '@/util/common'
import { utcToLocalTime } from '@/util/datetime'
import { getTimesBetweenTwoTimes, utcToLocalTime } from '@/util/datetime'
import {
r_sys_statistic_active,
r_sys_statistic_cpu,
@@ -223,7 +223,17 @@ const OnlineInfo: React.FC = () => {
setCurrentOnlineCount(data.current)
setTimeout(() => {
const dataList = data.history.map((value) => [value.time, value.record])
const dataList = getTimesBetweenTwoTimes(
data.history[0].time,
data.history[data.history.length - 1].time,
'minute'
).map((time) => [
time,
data.history.find(
(value) => value.time.substring(0, 16) === time.substring(0, 16)
)?.record ?? 0
])
onlineInfoEChartsRef.current = echarts.init(
onlineInfoDivRef.current,
null,
@@ -342,14 +352,32 @@ const ActiveInfo: React.FC = () => {
setIsLoading(false)
setTimeout(() => {
const registerList = data.registerHistory.map((value) => [
value.time,
value.count
])
const loginList = data.loginHistory.map((value) => [
value.time,
value.count
])
const registerList = data.registerHistory.length
? getTimesBetweenTwoTimes(
data.registerHistory[0].time,
data.registerHistory[data.registerHistory.length - 1].time,
'day'
).map((time) => [
time,
data.registerHistory.find(
(value) =>
value.time.substring(0, 10) === time.substring(0, 10)
)?.count ?? 0
])
: []
const loginList = data.loginHistory.length
? getTimesBetweenTwoTimes(
data.loginHistory[0].time,
data.loginHistory[data.loginHistory.length - 1].time,
'day'
).map((time) => [
time,
data.loginHistory.find(
(value) =>
value.time.substring(0, 10) === time.substring(0, 10)
)?.count ?? 0
])
: []
activeInfoEChartsRef.current = echarts.init(
activeInfoDivRef.current,

View File

@@ -1,4 +1,4 @@
import moment from 'moment/moment'
import moment, { unitOfTime } from 'moment/moment'
import dayjs from 'dayjs'
export const getNowLocalTime = (format: string = 'yyyy-MM-DD HH:mm:ssZ') => {
@@ -36,3 +36,22 @@ export const utcToMillisecond = (utcTime: string) => {
export const millisecondToUtc = (millisecond: number) => {
return moment(millisecond).toISOString()
}
export const getTimesBetweenTwoTimes = (
startTime: string,
endTime: string,
interval: unitOfTime.Diff
) => {
const timesList: string[] = []
const start = moment.utc(startTime)
const end = moment.utc(endTime)
const count = end.diff(start, interval)
timesList.push(start.toISOString())
for (let i = 0; i < count; i++) {
timesList.push(start.add(1, interval).toISOString())
}
return timesList
}