
import sqlite3
import pandas as pd
from web.services.feature_service import FeatureService
from web.config import Config
from web.app import create_app

def check_distribution():
    app = create_app()
    with app.app_context():
        # Get a player ID from L3
        conn = sqlite3.connect(Config.DB_L3_PATH)
        row = conn.execute("SELECT steam_id_64 FROM dm_player_features LIMIT 1").fetchone()
        if not row:
            print("No players in L3")
            return
        
        sid = row[0]
        print(f"Checking distribution for {sid}...")
        
        dist = FeatureService.get_roster_features_distribution(sid)
        if not dist:
            print("Distribution returned None")
            return
            
        keys_to_check = [
            'eco_avg_damage_per_1k', # Working
            'eco_rating_eco_rounds', # Working
            'eco_kd_ratio', # Broken
            'eco_avg_rounds', # Broken
            'pace_avg_time_to_first_contact', # Working
            'pace_trade_kill_rate', # Working
            'pace_opening_kill_time', # Broken
            'pace_avg_life_time' # Broken
        ]
        
        print(f"{'Key':<35} | {'Present':<7} | {'Value'}")
        print("-" * 60)
        for k in keys_to_check:
            is_present = k in dist
            val = dist.get(k)
            print(f"{k:<35} | {str(is_present):<7} | {val}")

if __name__ == "__main__":
    check_distribution()
