Spaces:
Paused
Paused
| """Verify the fixes""" | |
| import sys, os | |
| 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)).count() | |
| cats = db.session.execute(text("SELECT COUNT(DISTINCT category) FROM employee_kpi_values WHERE week_start='2026-07-06'")).scalar() | |
| users = db.session.execute(text("SELECT COUNT(DISTINCT user_id) FROM employee_kpi_values WHERE week_start='2026-07-06'")).scalar() | |
| print(f"Week 2026-07-06: {records} records, {cats} categories, {users} users") | |
| print() | |
| result = db.session.execute(text("SELECT category, COUNT(*) as cnt FROM employee_kpi_values WHERE week_start='2026-07-06' GROUP BY category ORDER BY category")) | |
| for row in result: | |
| print(f" {row.category:15s}: {row.cnt}") | |
| print() | |
| # Key metrics after fixes | |
| print("--- Key metrics after fixes ---") | |
| for cat, mname in [ | |
| ('Visits', '#LAS'), | |
| ('HTS', 'HTS packs'), | |
| ('HTS', '% sales tran. w/o HTS'), | |
| ('HTS', '%, carton from HTS transactions'), | |
| ('Eqosystem', '% успешных визитов'), | |
| ]: | |
| r = EmployeeKpiValue.query.filter_by(week_start=date(2026, 7, 6), category=cat, metric_name=mname).all() | |
| vals = [float(v.fact_value) for v in r if v.fact_value] | |
| plans = [float(v.plan_value) for v in r if v.plan_value] | |
| avg_fact = sum(vals)/len(vals) if vals else 0 | |
| avg_plan = sum(plans)/len(plans) if plans else 0 | |
| print(f" {cat:12s} {mname:40s} n={len(r):2d} fact_avg={avg_fact:.2f} plan_avg={avg_plan:.2f}") | |
| # Show individual LAS values | |
| print("\n--- LAS per employee ---") | |
| r = EmployeeKpiValue.query.filter_by(week_start=date(2026, 7, 6), category='Visits', metric_name='#LAS').all() | |
| for rec in r: | |
| from models import User | |
| u = User.query.get(rec.user_id) | |
| print(f" {u.full_name if u else '?'}: {rec.fact_value}") | |
| print("\n--- HTS packs per employee ---") | |
| r = EmployeeKpiValue.query.filter_by(week_start=date(2026, 7, 6), category='HTS', metric_name='HTS packs').all() | |
| for rec in r: | |
| from models import User | |
| u = User.query.get(rec.user_id) | |
| print(f" {u.full_name if u else '?'}: {rec.fact_value}") | |