temptours+tours
This commit is contained in:
57
engine/engine_components/course_config.py
Normal file
57
engine/engine_components/course_config.py
Normal file
@ -0,0 +1,57 @@
|
||||
# engine/engine_components/course_config.py
|
||||
|
||||
from datetime import datetime
|
||||
import pytz
|
||||
from engine.logger import log_debug, log_warn
|
||||
|
||||
LOCAL_TZ = "America/Toronto"
|
||||
|
||||
|
||||
def load_course_config(cur, con_id: int):
|
||||
"""
|
||||
Charge toutes les configs det_type = 2 (config de course)
|
||||
et retourne start_time / end_time convertis en datetime LOCAL.
|
||||
"""
|
||||
|
||||
sql = """
|
||||
SELECT det_clef, det_value1
|
||||
FROM reader_config_detail
|
||||
WHERE det_type = 2
|
||||
AND det_ref1_id = %s
|
||||
"""
|
||||
cur.execute(sql, (con_id,))
|
||||
rows = cur.fetchall()
|
||||
|
||||
cfg = {}
|
||||
|
||||
for row in rows:
|
||||
clef = row["det_clef"]
|
||||
val = row["det_value1"]
|
||||
cfg[clef] = val
|
||||
|
||||
tz = pytz.timezone(LOCAL_TZ)
|
||||
|
||||
start = None
|
||||
end = None
|
||||
|
||||
# Convertir start_time si présent
|
||||
if "clef_start_time" in cfg:
|
||||
try:
|
||||
start = tz.localize(datetime.fromtimestamp(int(cfg["clef_start_time"])))
|
||||
except Exception as e:
|
||||
log_warn(f"[CONFIG][CON {con_id}] start_time invalide: {e}")
|
||||
|
||||
# Convertir fin_time si présent
|
||||
if "clef_fin_time" in cfg:
|
||||
try:
|
||||
end = tz.localize(datetime.fromtimestamp(int(cfg["clef_fin_time"])))
|
||||
except Exception as e:
|
||||
log_warn(f"[CONFIG][CON {con_id}] end_time invalide: {e}")
|
||||
|
||||
log_debug(f"[CONFIG COURSE] con_id={con_id} start={start} end={end}")
|
||||
|
||||
return {
|
||||
"start_time": start,
|
||||
"end_time": end,
|
||||
"raw": cfg
|
||||
}
|
||||
Reference in New Issue
Block a user