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()) let startTime = new Date(accountInfo.value?.createAt ?? Date.now())
if (startTime < statisticStartDate) startTime = statisticStartDate if (startTime < statisticStartDate) startTime = statisticStartDate
startTime = startOfHour(startTime)
const endTime = new Date() const endTime = new Date()
if (fansHistory.value) { if (fansHistory.value) {
@@ -117,50 +118,55 @@ function getOptions() {
: fansHistory.value.findIndex((entry) => entry.time >= statisticStartDateTime) : fansHistory.value.findIndex((entry) => entry.time >= statisticStartDateTime)
: -1 : -1
let lastDayCount = lastFansTimeIndex >= 0 ? fansHistory.value[lastFansTimeIndex].count : 0 let lastDayCount = lastFansTimeIndex >= 0 ? fansHistory.value[lastFansTimeIndex].count : 0
// 生成完整的小时序列 // 生成完整的序列
while (currentTime <= endTime) { while (currentTime <= endTime) {
if (lastFansTimeIndex > -1) { const dayEndTime = startOfDay(currentTime).getTime()
const tempData = fansHistory.value[lastFansTimeIndex] while (true) {
const found = isSameHour(tempData?.time, currentTime) ? tempData : undefined const data = fansHistory.value[lastFansTimeIndex]
const count = found ? found.count : lastDayCount if (!data) {
lastDayCount = count
lastFansTimeIndex += found ? 1 : 0
completeTimeSeries.push({ completeTimeSeries.push({
time: currentTime, time: currentTime,
count: count, count: lastDayCount,
change: found ? true : false,
})
} else {
completeTimeSeries.push({
time: currentTime,
count: 0,
change: false, 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 let previousDayCount = completeTimeSeries[0].count
completeTimeSeries.forEach((entry, index, array) => { completeTimeSeries.forEach((entry, index, array) => {
if (index === 0 || !isSameDay(entry.time, array[index - 1].time)) { if (index === 0 || !isSameDay(entry.time, array[index - 1].time)) {
if (index > 0) { if (index > 0) {
const dailyIncrement = entry.count - previousDayCount const dailyIncrement = entry.count - previousDayCount
fansIncreacement.push({ fansIncreacement.push({
time: startOfHour(array[index - 1].time), time: startOfDay(array[index - 1].time),
count: dailyIncrement, count: dailyIncrement,
//timeString: format(array[index - 1].time, 'yyyy-MM-dd'), // timeString: format(array[index - 1].time, 'yyyy-MM-dd'),
}) })
} }
previousDayCount = entry.count previousDayCount = entry.count
} else if (index === array.length - 1) { } else if (index === array.length - 1) {
const dailyIncrement = entry.count - previousDayCount const dailyIncrement = entry.count - previousDayCount
fansIncreacement.push({ fansIncreacement.push({
time: startOfHour(entry.time), time: startOfDay(entry.time),
count: dailyIncrement, count: dailyIncrement,
//timeString: format(array[index - 1].time, 'yyyy-MM-dd'), // 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 guardsIncreacement = [] as { time: number; count: number; timeString: string }[]
const guards = [] 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 currentGuardTime = startTime
let lastDayGuardCount = 0 let lastDayGuardCount = 0
@@ -178,25 +185,39 @@ function getOptions() {
time: Date time: Date
count: number count: number
}[] = [] }[] = []
let lastGuardTimeIndex = 0
while (currentGuardTime <= endTime) { while (currentGuardTime <= endTime) {
const found = guardHistory.value?.find((f) => isSameDay(currentGuardTime, f.time)) const dayEndTime = startOfDay(currentGuardTime).getTime()
const count = found ? found.count : lastDayGuardCount while (true) {
lastDayGuardCount = count 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({ completeGuardTimeSeries.push({
time: currentGuardTime, time: currentGuardTime,
count: count, count: lastDayGuardCount,
}) })
break
}
currentGuardTime = startOfDay(addDays(currentGuardTime, 1)) lastGuardTimeIndex++;
}
currentGuardTime = addDays(currentGuardTime, 1)
} }
completeGuardTimeSeries.forEach((g) => { completeGuardTimeSeries.forEach((g) => {
if (!isSameDay(g.time, lastDay)) { if (!isSameDay(g.time, new Date(lastDay * 1000))) {
guardsIncreacement.push({ guardsIncreacement.push({
time: lastDayGuards, time: lastDayGuards,
count: lastDay == 0 ? 0 : g.count - lastDayGuards, count: lastDay == 0 ? 0 : g.count - lastDayGuards,
//将timeString转换为yyyy-MM-dd HH
timeString: format(g.time, 'yyyy-MM-dd'), timeString: format(g.time, 'yyyy-MM-dd'),
}) })
guards.push({ guards.push({
@@ -208,6 +229,8 @@ function getOptions() {
lastDayGuards = g.count lastDayGuards = g.count
} }
}) })
}
const upstatViewIncreace: { time: number; value: number }[] = [] const upstatViewIncreace: { time: number; value: number }[] = []
const upstatLikeIncreace: { time: number; value: number }[] = [] const upstatLikeIncreace: { time: number; value: number }[] = []
if (upstatHistory.value && upstatHistory.value.length > 0) { if (upstatHistory.value && upstatHistory.value.length > 0) {
@@ -270,7 +293,7 @@ function getOptions() {
yAxis: [ yAxis: [
{ {
type: 'value', type: 'value',
name: '每小时粉丝数', name: '粉丝数',
}, },
{ {
type: 'value', type: 'value',
@@ -564,7 +587,8 @@ onMounted(async () => {
<NCard v-else size="small"> <NCard v-else size="small">
<NAlert type="warning"> <NAlert type="warning">
由于B站继续收紧风控策略, 本站已无法再爬取相关数据, 请需要使用此功能的用户下载并安装1.0.6.4及以上版本的 由于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> </NAlert>
<br /> <br />
@@ -579,7 +603,7 @@ onMounted(async () => {
</template> </template>
<NSpace vertical> <NSpace vertical>
<NText strong>所有数据改为每天更新一次</NText> <NText strong>所有数据改为每天更新一次</NText>
<NDivider style="margin: 0"/> <NDivider style="margin: 0" />
<NText delete :depth="3"> <NText delete :depth="3">
粉丝数: 200粉以下: 每3天一次, 200-1000: 每24小时一次, 1000-10000: 每6小时一次, 10000粉以上: 每小时一次 粉丝数: 200粉以下: 每3天一次, 200-1000: 每24小时一次, 1000-10000: 每6小时一次, 10000粉以上: 每小时一次
</NText> </NText>