@@ -34,38 +34,6 @@ def maybe_create_table(sqlite_file: str) -> bool:
3434 );
3535 """
3636 )
37- cursor .execute (
38- """
39- CREATE TABLE IF NOT EXISTS weekly_baselines (
40- id INTEGER PRIMARY KEY AUTOINCREMENT,
41- user_slug TEXT NOT NULL,
42- created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
43- easy INTEGER DEFAULT 0,
44- medium INTEGER DEFAULT 0,
45- hard INTEGER DEFAULT 0
46- );
47- """
48- )
49- cursor .execute (
50- """
51- DROP TRIGGER IF EXISTS first_weekly_snapshot;
52- """
53- )
54- cursor .execute ("DROP TRIGGER IF EXISTS first_weekly_snapshot;" )
55- cursor .execute ("""
56- CREATE TRIGGER first_weekly_snapshot
57- AFTER INSERT ON leetcode_snapshots
58- BEGIN
59- INSERT INTO weekly_baselines (user_slug, easy, medium, hard, created_at)
60- SELECT NEW.user_slug, NEW.easy, NEW.medium, NEW.hard, NEW.created_at
61- WHERE NOT EXISTS (
62- SELECT 1
63- FROM weekly_baselines
64- WHERE user_slug = NEW.user_slug
65- AND strftime('%Y-%W', created_at, 'localtime') = strftime('%Y-%W', NEW.created_at, 'localtime')
66- );
67- END;
68- """ )
6937 cursor .execute ("""
7038 CREATE INDEX IF NOT EXISTS idx_user_created_at
7139 ON leetcode_snapshots(user_slug, created_at);
@@ -281,29 +249,3 @@ def get_all_leetcode_snapshots(sqlite_file: str):
281249 }
282250 for row in rows
283251 ]
284-
285-
286- def get_all_weekly_baselines (sqlite_file : str ):
287- """
288- Get all weekly baselines from the database.
289- """
290- with sqlite3 .connect (sqlite_file ) as conn :
291- cursor = conn .cursor ()
292- cursor .execute (
293- """
294- SELECT user_slug, easy, medium, hard, created_at
295- FROM weekly_baselines
296- ORDER BY created_at DESC
297- """
298- )
299- rows = cursor .fetchall ()
300- return [
301- {
302- "user" : row [0 ],
303- "easy" : row [1 ],
304- "medium" : row [2 ],
305- "hard" : row [3 ],
306- "created_at" : row [4 ],
307- }
308- for row in rows
309- ]
0 commit comments