fix: zero division error

This commit is contained in:
alikia2x (寒寒) 2025-03-11 23:50:21 +08:00
parent bce4161501
commit e12275dbd4
Signed by: alikia2x
GPG Key ID: 56209E0CCD8420C6

View File

@ -90,8 +90,25 @@ export async function getShortTermEtaPrediction(client: Client, aid: number) {
) )
SELECT SELECT
CASE CASE
WHEN n.views > 100000 THEN (1000000 - n.views) / ((n.views - o.views) / (EXTRACT(EPOCH FROM (n.created_at - o.created_at)) + 0.01)) WHEN n.views > 100000
ELSE (100000 - n.views) / ((n.views - o.views) / (EXTRACT(EPOCH FROM (n.created_at - o.created_at)) + 0.01)) THEN
(1000000 - n.views) -- Views remaining
/
(
(n.views - o.views) -- Views delta
/
(EXTRACT(EPOCH FROM (n.created_at - o.created_at)) + 0.001) -- Time delta in seconds
+ 0.001
) -- Increment per second
ELSE
(100000 - n.views) -- Views remaining
/
(
(n.views - o.views) -- Views delta
/
(EXTRACT(EPOCH FROM (n.created_at - o.created_at)) + 0.001) -- Time delta in seconds
+ 0.001
) -- Increment per second
END AS eta END AS eta
FROM old_snapshot o, new_snapshot n; FROM old_snapshot o, new_snapshot n;
`, `,