update history chart step

This commit is contained in:
2024-10-20 00:44:57 +08:00
parent d567a4f55f
commit 60b609ac26
2 changed files with 84 additions and 15288 deletions

15228
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -106,6 +106,7 @@ function getOptions() {
let startTime = new Date(accountInfo.value?.createAt ?? Date.now())
if (startTime < statisticStartDate) startTime = statisticStartDate
startTime = startOfHour(startTime)
const endTime = new Date()
if (fansHistory.value) {
@@ -117,39 +118,44 @@ function getOptions() {
: fansHistory.value.findIndex((entry) => entry.time >= statisticStartDateTime)
: -1
let lastDayCount = lastFansTimeIndex >= 0 ? fansHistory.value[lastFansTimeIndex].count : 0
// 生成完整的小时序列
// 生成完整的序列
while (currentTime <= endTime) {
if (lastFansTimeIndex > -1) {
const tempData = fansHistory.value[lastFansTimeIndex]
const found = isSameHour(tempData?.time, currentTime) ? tempData : undefined
const count = found ? found.count : lastDayCount
lastDayCount = count
lastFansTimeIndex += found ? 1 : 0
const dayEndTime = startOfDay(currentTime).getTime()
while (true) {
const data = fansHistory.value[lastFansTimeIndex]
if (!data) {
completeTimeSeries.push({
time: currentTime,
count: count,
change: found ? true : false,
})
} else {
completeTimeSeries.push({
time: currentTime,
count: 0,
count: lastDayCount,
change: false,
})
break
}
if ((fansHistory.value[lastFansTimeIndex + 1]?.time ?? Number.MAX_VALUE) > dayEndTime) {
const changed = data.count != lastDayCount
lastDayCount = data.count
completeTimeSeries.push({
time: currentTime,
count: lastDayCount,
change: changed,
})
break
}
currentTime = addHours(currentTime, 1)
lastFansTimeIndex++;
}
currentTime = addDays(currentTime, 1)
}
// 计算日增量数据
let previousDayCount = completeTimeSeries[0].count
completeTimeSeries.forEach((entry, index, array) => {
if (index === 0 || !isSameDay(entry.time, array[index - 1].time)) {
if (index > 0) {
const dailyIncrement = entry.count - previousDayCount
fansIncreacement.push({
time: startOfHour(array[index - 1].time),
time: startOfDay(array[index - 1].time),
count: dailyIncrement,
// timeString: format(array[index - 1].time, 'yyyy-MM-dd'),
})
@@ -158,7 +164,7 @@ function getOptions() {
} else if (index === array.length - 1) {
const dailyIncrement = entry.count - previousDayCount
fansIncreacement.push({
time: startOfHour(entry.time),
time: startOfDay(entry.time),
count: dailyIncrement,
// timeString: format(array[index - 1].time, 'yyyy-MM-dd'),
})
@@ -171,6 +177,7 @@ function getOptions() {
const guardsIncreacement = [] as { time: number; count: number; timeString: string }[]
const guards = [] as { time: number; count: number; timeString: string }[]
if (guardHistory.value && guardHistory.value.length > 0) {
// 生成完整的天序列
let currentGuardTime = startTime
let lastDayGuardCount = 0
@@ -178,25 +185,39 @@ function getOptions() {
time: Date
count: number
}[] = []
let lastGuardTimeIndex = 0
while (currentGuardTime <= endTime) {
const found = guardHistory.value?.find((f) => isSameDay(currentGuardTime, f.time))
const count = found ? found.count : lastDayGuardCount
lastDayGuardCount = count
const dayEndTime = startOfDay(currentGuardTime).getTime()
while (true) {
const data = guardHistory.value[lastGuardTimeIndex]
if (!data) {
completeGuardTimeSeries.push({
time: currentGuardTime,
count: lastDayGuardCount,
})
break
}
if ((guardHistory.value[lastGuardTimeIndex + 1]?.time ?? Number.MAX_VALUE) > dayEndTime) {
lastDayGuardCount = data.count
completeGuardTimeSeries.push({
time: currentGuardTime,
count: count,
count: lastDayGuardCount,
})
break
}
currentGuardTime = startOfDay(addDays(currentGuardTime, 1))
lastGuardTimeIndex++;
}
currentGuardTime = addDays(currentGuardTime, 1)
}
completeGuardTimeSeries.forEach((g) => {
if (!isSameDay(g.time, lastDay)) {
if (!isSameDay(g.time, new Date(lastDay * 1000))) {
guardsIncreacement.push({
time: lastDayGuards,
count: lastDay == 0 ? 0 : g.count - lastDayGuards,
//将timeString转换为yyyy-MM-dd HH
timeString: format(g.time, 'yyyy-MM-dd'),
})
guards.push({
@@ -208,6 +229,8 @@ function getOptions() {
lastDayGuards = g.count
}
})
}
const upstatViewIncreace: { time: number; value: number }[] = []
const upstatLikeIncreace: { time: number; value: number }[] = []
if (upstatHistory.value && upstatHistory.value.length > 0) {
@@ -270,7 +293,7 @@ function getOptions() {
yAxis: [
{
type: 'value',
name: '每小时粉丝数',
name: '粉丝数',
},
{
type: 'value',
@@ -564,7 +587,8 @@ onMounted(async () => {
<NCard v-else size="small">
<NAlert type="warning">
由于B站继续收紧风控策略, 本站已无法再爬取相关数据, 请需要使用此功能的用户下载并安装1.0.6.4及以上版本的
<NButton text type="info" tag="a" href="https://www.yuque.com/megghy/dez70g/vfvcyv3024xvaa1p" target="_blank"> VTsuruEventFetcher </NButton>
<NButton text type="info" tag="a" href="https://www.yuque.com/megghy/dez70g/vfvcyv3024xvaa1p" target="_blank">
VTsuruEventFetcher </NButton>
来帮助本站获取你的数据记录
</NAlert>
<br />