qkrm commited on
Commit
b57a89a
·
verified ·
1 Parent(s): b7e875d

feat: baseline stats restore on empty DB

Browse files
Files changed (1) hide show
  1. server/main.py +28 -0
server/main.py CHANGED
@@ -57,6 +57,34 @@ def _record(kind: str, verdict: str | None = None) -> None:
57
  )
58
 
59
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
60
  class AnalyzeRequest(BaseModel):
61
  text: str
62
 
 
57
  )
58
 
59
 
60
+ # 2026-07-08 재배포로 초기화되기 전의 집계. DB가 비어 있으면(재배포 직후) 1회 복원한다.
61
+ BASELINE_DAY = "2026-07-08"
62
+ BASELINE = [
63
+ ("visit", None, 26),
64
+ ("analyze", "bad", 52),
65
+ ("analyze", "ok", 25),
66
+ ("analyze", "na", 114),
67
+ ("singo", None, 1),
68
+ ]
69
+
70
+
71
+ def _seed_baseline() -> None:
72
+ with _db_lock, _db() as conn:
73
+ (count,) = conn.execute("SELECT COUNT(*) FROM events").fetchone()
74
+ if count:
75
+ return
76
+ ts = f"{BASELINE_DAY}T00:00:00+09:00"
77
+ rows = []
78
+ for kind, verdict, n in BASELINE:
79
+ rows.extend([(kind, verdict, BASELINE_DAY, ts)] * n)
80
+ conn.executemany(
81
+ "INSERT INTO events (kind, verdict, day, ts) VALUES (?, ?, ?, ?)", rows
82
+ )
83
+
84
+
85
+ _seed_baseline()
86
+
87
+
88
  class AnalyzeRequest(BaseModel):
89
  text: str
90