Skip to content

Commit e1353f8

Browse files
Update metadata handling with more comprehensive tracking and Grafana queries
Co-authored-by: zohair.ul.hasan <[email protected]>
1 parent 3cf81cd commit e1353f8

File tree

2 files changed

+67
-7
lines changed

2 files changed

+67
-7
lines changed

src/db.py

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -210,16 +210,33 @@ def create_tables(cur: cursor) -> None:
210210

211211

212212
def update_metadata(cur: cursor) -> None:
213+
# Import here to avoid circular imports
214+
import config
215+
from quarter_utils import get_quarter_name
216+
213217
tz = timezone("US/Eastern")
214218
current_datetime = datetime.now(tz).strftime("%m/%d/%y %I:%M %p")
215-
cur.execute(
219+
220+
# Get current quarter information
221+
quarter_name = get_quarter_name(config.quarter)
222+
223+
# Update multiple metadata values
224+
metadata_updates = [
225+
('last_updated', current_datetime),
226+
('current_year', config.year),
227+
('current_quarter', config.quarter),
228+
('current_quarter_name', quarter_name),
229+
('current_term', f"{quarter_name} {config.year}")
230+
]
231+
232+
cur.executemany(
216233
"""
217-
INSERT INTO metadata (key, value)
218-
VALUES ('last_updated', %s)
219-
ON CONFLICT (key)
220-
DO UPDATE SET value = EXCLUDED.value;
221-
""",
222-
(current_datetime,),
234+
INSERT INTO metadata (key, value)
235+
VALUES (%s, %s)
236+
ON CONFLICT (key)
237+
DO UPDATE SET value = EXCLUDED.value;
238+
""",
239+
metadata_updates,
223240
)
224241

225242

src/grafana_queries.sql

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
-- Query to get the current term for display in Grafana dashboard
2+
-- This can be used in a Text panel or Stat panel
3+
SELECT value as current_term
4+
FROM metadata
5+
WHERE key = 'current_term';
6+
7+
-- Query to get last updated time
8+
SELECT value as last_updated
9+
FROM metadata
10+
WHERE key = 'last_updated';
11+
12+
-- Query to get all metadata for dashboard information
13+
SELECT
14+
CASE
15+
WHEN key = 'current_term' THEN 'Current Term'
16+
WHEN key = 'last_updated' THEN 'Last Updated'
17+
WHEN key = 'current_year' THEN 'Academic Year'
18+
WHEN key = 'current_quarter_name' THEN 'Quarter'
19+
ELSE key
20+
END as label,
21+
value
22+
FROM metadata
23+
WHERE key IN ('current_term', 'last_updated', 'current_year', 'current_quarter_name')
24+
ORDER BY
25+
CASE key
26+
WHEN 'current_term' THEN 1
27+
WHEN 'last_updated' THEN 2
28+
WHEN 'current_year' THEN 3
29+
WHEN 'current_quarter_name' THEN 4
30+
ELSE 5
31+
END;
32+
33+
-- Query for a single stat panel showing the current term
34+
SELECT
35+
value as "Current Term"
36+
FROM metadata
37+
WHERE key = 'current_term';
38+
39+
-- Query for dashboard title or header with dynamic content
40+
SELECT
41+
CONCAT('Drexel Course Scheduler - ', value) as dashboard_title
42+
FROM metadata
43+
WHERE key = 'current_term';

0 commit comments

Comments
 (0)