feat: overhaul UI styling, improve templates, enhance services and tests
This commit is contained in:
+21
-24
@@ -13,33 +13,33 @@ def get_trends_data(db: Session) -> dict:
|
||||
thirty_days_ago = (date.today() - timedelta(days=30)).isoformat()
|
||||
|
||||
# 1. 按日论文数量(近 30 天)
|
||||
daily_rows = db.execute(text("""
|
||||
daily_rows = db.execute(
|
||||
text("""
|
||||
SELECT paper_date, COUNT(*) as cnt
|
||||
FROM papers
|
||||
WHERE paper_date >= :start_date
|
||||
GROUP BY paper_date
|
||||
ORDER BY paper_date ASC
|
||||
"""), {"start_date": thirty_days_ago}).fetchall()
|
||||
daily_counts = [
|
||||
{"date": str(row[0]), "count": row[1]}
|
||||
for row in daily_rows
|
||||
]
|
||||
"""),
|
||||
{"start_date": thirty_days_ago},
|
||||
).fetchall()
|
||||
daily_counts = [{"date": str(row[0]), "count": row[1]} for row in daily_rows]
|
||||
|
||||
# 2. 热门标签 Top 20
|
||||
tag_rows = db.execute(text("""
|
||||
tag_rows = db.execute(
|
||||
text("""
|
||||
SELECT tag, COUNT(*) as cnt
|
||||
FROM paper_tags
|
||||
GROUP BY tag
|
||||
ORDER BY cnt DESC
|
||||
LIMIT 20
|
||||
""")).fetchall()
|
||||
top_tags = [
|
||||
{"tag": row[0], "count": row[1]}
|
||||
for row in tag_rows
|
||||
]
|
||||
""")
|
||||
).fetchall()
|
||||
top_tags = [{"tag": row[0], "count": row[1]} for row in tag_rows]
|
||||
|
||||
# 3. Upvotes 分布
|
||||
upvote_rows = db.execute(text("""
|
||||
upvote_rows = db.execute(
|
||||
text("""
|
||||
SELECT
|
||||
CASE
|
||||
WHEN upvotes >= 100 THEN '100+'
|
||||
@@ -53,25 +53,22 @@ def get_trends_data(db: Session) -> dict:
|
||||
FROM papers
|
||||
GROUP BY bucket
|
||||
ORDER BY MIN(upvotes) DESC
|
||||
""")).fetchall()
|
||||
upvotes_dist = [
|
||||
{"range": row[0], "count": row[1]}
|
||||
for row in upvote_rows
|
||||
]
|
||||
""")
|
||||
).fetchall()
|
||||
upvotes_dist = [{"range": row[0], "count": row[1]} for row in upvote_rows]
|
||||
|
||||
# 4. 总结完成率
|
||||
summary_rows = db.execute(text("""
|
||||
summary_rows = db.execute(
|
||||
text("""
|
||||
SELECT
|
||||
COALESCE(ss.status, 'none') as status,
|
||||
COUNT(*) as cnt
|
||||
FROM papers p
|
||||
LEFT JOIN summary_status ss ON ss.paper_id = p.id
|
||||
GROUP BY status
|
||||
""")).fetchall()
|
||||
summary_completion = [
|
||||
{"status": row[0], "count": row[1]}
|
||||
for row in summary_rows
|
||||
]
|
||||
""")
|
||||
).fetchall()
|
||||
summary_completion = [{"status": row[0], "count": row[1]} for row in summary_rows]
|
||||
|
||||
return {
|
||||
"daily_counts": daily_counts,
|
||||
|
||||
Reference in New Issue
Block a user