feat(web): show cumulative fan range and limit recent records

This commit is contained in:
kairee committed 2026-11-01 02:14:10 +08:00
1 parent b6a9f598b5
commit d8e9a7b0f0
5 files changed
+48 -9

No files matched your search

+19 -2
View File
@@ -894,9 +894,17 @@ class DashboardQueries:
# ------------------------------------------------------------ fans
def fans(self, mid: int | None = None, *, days: int = 90) -> dict[str, Any]:
def fans(
self,
mid: int | None = None,
*,
days: int = 90,
recent_days: int = 14,
) -> dict[str, Any]:
if days < 1:
raise ValueError("days 必须大于 0")
if recent_days < 1 or recent_days > 3650:
raise ValueError("recent_days 必须在 1~3650 之间")
def run(conn: sqlite3.Connection) -> dict[str, Any]:
cfg = self.config_store.get()
@@ -916,7 +924,8 @@ class DashboardQueries:
return {
"mid": None, "name": None, "available": False,
"options": options, "dates": [], "series": [],
"points": [], "days": days,
"points": [], "recent_points": [], "days": days,
"recent_days": recent_days,
}
rows = [
dict(row) for row in conn.execute(
@@ -933,10 +942,16 @@ class DashboardQueries:
"dates": [],
"series": [],
"points": [],
"recent_points": [],
"days": days,
"recent_days": recent_days,
}
latest = max(str(row["stat_date"]) for row in rows if int(row["ok"]) == 1) if any(int(row["ok"]) == 1 for row in rows) else str(rows[-1]["stat_date"])
first_date = str(rows[0]["stat_date"])
recent_start = _date_minus(latest, recent_days - 1)
recent_points = [
row for row in rows if str(row["stat_date"]) >= recent_start
]
start = max(_date_minus(latest, days - 1), first_date)
dates = _date_range(start, latest)
by_date = {str(row["stat_date"]): row for row in rows}
@@ -973,6 +988,8 @@ class DashboardQueries:
"dates": dates,
"series": series,
"points": rows,
"recent_points": recent_points,
"recent_days": recent_days,
"stat_date": current["stat_date"],
"follower": current.get("follower"),
"following": current.get("following"),