File size: 1,359 Bytes
04477e7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
"""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}")