2626# Cache configuration
2727REPORT_CACHE_MAX_AGE = 86400 # 24 hours - reports regenerate daily
2828
29+ # Station code to name mapping (for incidents that only have codes)
30+ STATION_NAMES = {
31+ 'WE' : 'West Portal' ,
32+ 'FH' : 'Forest Hill' ,
33+ 'CA' : 'Castro' ,
34+ 'CH' : 'Church' ,
35+ 'VN' : 'Van Ness' ,
36+ 'CC' : 'Civic Center' ,
37+ 'PO' : 'Powell' ,
38+ 'MO' : 'Montgomery' ,
39+ 'EM' : 'Embarcadero' ,
40+ 'MN' : 'Main' ,
41+ 'FP' : 'Folsom' ,
42+ 'TT' : 'Temporary Terminal' ,
43+ 'CT' : 'Chinatown' ,
44+ 'US' : 'Union Square' ,
45+ 'YB' : 'Yerba Buena' ,
46+ }
47+
2948# Track if we've restored from GCS this session
3049_gcs_restored = False
3150
@@ -287,6 +306,7 @@ def log_status_check(status, best_status, detection_data, timestamp):
287306 delays_bunching = detection_data .get ('delays_bunching' , [])
288307
289308 # Platform holds
309+ # detection.py uses 'station' for code and 'name' for station name
290310 for delay in delays_platforms :
291311 cursor .execute ('''
292312 INSERT INTO delay_incidents (check_id, timestamp, type, station, station_name, direction)
@@ -295,15 +315,17 @@ def log_status_check(status, best_status, detection_data, timestamp):
295315 check_id ,
296316 timestamp ,
297317 'platform_hold' ,
298- delay .get ('code ' ),
299- delay .get ('name' ),
318+ delay .get ('station ' ), # station code like 'PO', 'MO'
319+ delay .get ('name' ), # station name like 'Powell', 'Montgomery'
300320 delay .get ('direction' )
301321 ))
302322
303323 # Red segments
324+ # detection.py uses 'from' and 'to' for station codes (not 'from_code')
304325 for delay in delays_segments :
326+ from_code = delay .get ('from' )
305327 details = json .dumps ({
306- 'from' : delay . get ( 'from' ) ,
328+ 'from' : from_code ,
307329 'to' : delay .get ('to' )
308330 })
309331 # Use the 'from' station as the primary station
@@ -314,14 +336,16 @@ def log_status_check(status, best_status, detection_data, timestamp):
314336 check_id ,
315337 timestamp ,
316338 'red_segment' ,
317- delay . get ( ' from_code' ) ,
318- delay .get ('from' ),
339+ from_code ,
340+ STATION_NAMES .get (from_code , from_code ), # lookup name, fallback to code
319341 delay .get ('direction' ),
320342 details
321343 ))
322344
323345 # Train bunching
346+ # detection.py uses 'station' for station code (no separate 'station_code' field)
324347 for delay in delays_bunching :
348+ station_code = delay .get ('station' )
325349 details = json .dumps ({
326350 'train_count' : delay .get ('train_count' )
327351 })
@@ -332,8 +356,8 @@ def log_status_check(status, best_status, detection_data, timestamp):
332356 check_id ,
333357 timestamp ,
334358 'bunching' ,
335- delay . get ( ' station_code' ) ,
336- delay .get ('station' ),
359+ station_code ,
360+ STATION_NAMES .get (station_code , station_code ), # lookup name, fallback to code
337361 delay .get ('direction' ),
338362 details
339363 ))
0 commit comments