U
    !ΨhU  γ                   @   s  d Z ddlmZmZ ddlmZ ddlZed e dd‘Ze	d e	d	 zJeeZ
e
 ‘ .Ze ed
‘Ze ‘ Ze	d e	ded   e	ded   e	ded   e ed‘Ze ‘ Ze	d e	ded   e	ded   e	ded  ded   e ed‘Ze ‘ Ze	d erreD ]0Ze	ded  ded  ded dd q>ne	d e ed ‘Ze ‘ Ze	d! eD ]VZed rΐed dd"  d#nd$Ze	d%ed  d&ed  d'e d(ed   qe	d) e ed*‘Ze ‘ Zedkr,e	d%e d+ e ed,‘Ze ‘ Zedkr\e	d-e d. e ed/‘Ze ‘ Zedk re	d0e d1 W 5 Q R X W nh ek
r  Z zHe	d2 e	de  e	d3 e	d4 e	d5 e	d6 e	d7e  W 5 dZ[X Y nX dS )8z6
Quick database check for developer and activity data
ι    )Ϊcreate_engineΪtext)Ϊload_dotenvNz.envΪDATABASE_URLz7postgresql://postgres:asdf1234@localhost:5432/timesheetu   π Quick Database Checkz2==================================================a  
            SELECT 
                COUNT(*) as total_developers,
                COUNT(CASE WHEN active = true THEN 1 END) as active_developers,
                COUNT(CASE WHEN api_token IS NOT NULL THEN 1 END) as with_tokens
            FROM developers
        u   
π₯ DEVELOPERS:z
   Total: z   Active: ι   z   With Tokens: ι   a@  
            SELECT 
                COUNT(*) as total_records,
                COUNT(DISTINCT developer_id) as developers_with_data,
                MIN(timestamp) as oldest_activity,
                MAX(timestamp) as newest_activity
            FROM activity_records
            WHERE developer_id IS NOT NULL
        u   
π ACTIVITIES:z   Total Records: z   Developers with Data: z   Date Range: z to ι   a:  
            SELECT 
                developer_id,
                COUNT(*) as activities_today,
                SUM(duration) / 3600.0 as hours_today
            FROM activity_records
            WHERE DATE(timestamp) = CURRENT_DATE
            GROUP BY developer_id
            ORDER BY hours_today DESC
        u   
π TODAY'S ACTIVITY:z   z: z activities, z.2fz hoursz   No activity recorded todayzέ
            SELECT 
                developer_id,
                name,
                api_token,
                created_at
            FROM developers
            ORDER BY created_at DESC
            LIMIT 10
        u!   
π DEVELOPER LIST (Recent 10):ι   z...zNo tokenz   - z (ID: z) - Token: z - Created: u   
β οΈ  POTENTIAL ISSUES:zΕ
            SELECT COUNT(*)
            FROM developers d
            LEFT JOIN activity_records ar ON d.developer_id = ar.developer_id
            WHERE ar.id IS NULL AND d.active = true
        z( active developers have NO activity dataz±
            SELECT COUNT(DISTINCT developer_id)
            FROM activity_records
            WHERE developer_id IN ('test', 'demo', 'example', 'john_doe', 'jane_doe')
        z   - Found z test/demo developers with datazΞ
            SELECT COUNT(*)
            FROM information_schema.columns
            WHERE table_name = 'developers'
            AND column_name IN ('ip_address', 'activitywatch_port', 'last_sync')
        z*   - Missing some tracking columns (found z/3)u   
β Database Connection Error:z
Please check:z1. PostgreSQL is runningz2. Database 'timesheet' existsz%3. .env file has correct DATABASE_URLz
Current DATABASE_URL: )Ϊ__doc__Z
sqlalchemyr   r   Zdotenvr   ΪosΪgetenvr   ΪprintZengineZconnectZconnZexecuteΪresultZfetchoneZ	dev_statsZ	act_statsZfetchallZ
today_dataZdevZ
developersZtoken_displayZscalarZno_activity_countZ	test_dataZcolumn_countΪ	ExceptionΪe© r   r   ϊ./quick_db_check.pyΪ<module>   sp   
0$0


