Skip to content

Commit 5063915

Browse files
committed
remove weekly baselines & trigger
1 parent d6d0949 commit 5063915

2 files changed

Lines changed: 1 addition & 60 deletions

File tree

modules/sqlite_helpers.py

Lines changed: 0 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -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-
]

server.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,7 @@ def debug():
130130
# dump all contents of the tables sorted by created_at for both tables
131131
leetcode_snapshots = sqlite_helpers.get_all_leetcode_snapshots(SQLITE_FILE_NAME)
132132
users = sqlite_helpers.get_all_users(SQLITE_FILE_NAME)
133-
weekly_baselines = sqlite_helpers.get_all_weekly_baselines(SQLITE_FILE_NAME)
134-
return {"leetcode_snapshots": leetcode_snapshots, "users": users, "weekly_baselines": weekly_baselines}
133+
return {"leetcode_snapshots": leetcode_snapshots, "users": users}
135134

136135

137136
@app.get("/phone")

0 commit comments

Comments
 (0)