Spaces:
Paused
Paused
| """Check current DB state""" | |
| import sys, os, inspect | |
| import importlib.util | |
| # Ensure we can import from the project root | |
| script_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) | |
| os.chdir(script_dir) | |
| if script_dir not in sys.path: | |
| sys.path.insert(0, script_dir) | |
| from app import create_app | |
| from extensions import db | |
| from models import EmployeeKpiValue | |
| from datetime import date | |
| from sqlalchemy import text | |
| app = create_app() | |
| with app.app_context(): | |
| records = EmployeeKpiValue.query.filter_by( | |
| week_start=date(2026, 7, 6), | |
| category='Deg Set' | |
| ).all() | |
| print("Deg Set records:") | |
| for r in records: | |
| print(f" user_id={r.user_id} metric={r.metric_name} fact={r.fact_value}") | |
| print() | |
| result = db.session.execute(text(""" | |
| SELECT ekv.category, ekv.metric_name, COUNT(*) as cnt, | |
| MIN(CAST(ekv.fact_value AS REAL)) as mn, | |
| MAX(CAST(ekv.fact_value AS REAL)) as mx, | |
| ROUND(AVG(CAST(ekv.fact_value AS REAL)),2) as avg | |
| FROM employee_kpi_values ekv | |
| WHERE ekv.week_start = '2026-07-06' | |
| GROUP BY ekv.category, ekv.metric_name | |
| ORDER BY ekv.category, ekv.metric_name | |
| """)) | |
| for row in result: | |
| print(f"{row.category:15s} {row.metric_name:45s} cnt={row.cnt} min={row.mn:.2f} max={row.mx:.2f} avg={row.avg:.2f}") | |