Spaces:
Configuration error
Configuration error
| import pandas as pd | |
| from config import TH_PHONE_MIN, TH_CHAT_MIN, TH_CORRIDOR_MIN, ALERTS_CSV | |
| def check_and_log_alerts(summary_minutes): | |
| # summary_minutes: tid -> metrics | |
| rows = [] | |
| for tid, mm in summary_minutes.items(): | |
| alerts = [] | |
| if mm['phone_min'] >= TH_PHONE_MIN: | |
| alerts.append(f"Track {tid} phone time {mm['phone_min']} min >= {TH_PHONE_MIN}") | |
| if mm['chat_min'] >= TH_CHAT_MIN: | |
| alerts.append(f"Track {tid} chat time {mm['chat_min']} min >= {TH_CHAT_MIN}") | |
| if mm['corridor_min'] >= TH_CORRIDOR_MIN: | |
| alerts.append(f"Track {tid} corridor time {mm['corridor_min']} min >= {TH_CORRIDOR_MIN}") | |
| if alerts: | |
| rows.append({'track_id': tid, 'alerts': '; '.join(alerts)}) | |
| if rows: | |
| df = pd.DataFrame(rows) | |
| try: | |
| old = pd.read_csv(ALERTS_CSV) | |
| df = pd.concat([old, df], ignore_index=True) | |
| except Exception: | |
| pass | |
| df.to_csv(ALERTS_CSV, index=False) | |
| return rows | |