U
    h|                  1   @   s  d dl Z d dlZd dlmZ e  edZedddZed  dZ	ed d	Z
e
d  dZe jed  eedkred nd
e
d e	d  e	d dZe Zddddddddddddddddddddd d!d"d#d$d%d&d'd(d)d*d+d,d-d.d/d0d1d2d3d4d5d6d7d8d9d:d;d<g1d=d>d?d@dAdBdCdDdEg	dFdGdHdIdJdKdLdMdNdOdPgdQdRdSdTdUdVdWdXdYdZg
d[Zd\d] Zed^ ed_ ed` e D ] \ZZedae dbe dc q~edd ede e Zd ZeD ]T\ZeeZedfeef ejZee7 Zed kredae dge dhe di qe  edje  edk edl e D ] \ZZedae dbe dc qHedm dnD ]fZedoe  d edpef e Z e re D ] \Z!Zedqe! dbe dc qnedr qve"  e"  eds dS )t    N)load_dotenvDATABASE_URLzpostgresql:// @:   /Z5432)ZhostZportZdatabaseuserZpasswordzcode.execodez
cursor.execursorz
devenv.exeznotepad++.exezsublime_text.exezatom.exezbrackets.exeZvimZemacszpycharm.exezpycharm64.exezidea.exez
idea64.exezwebstorm.exezphpstorm.exezrubymine.exez
goland.exez	clion.exez	rider.exezdatagrip.exezstudio64.exezeclipse.exeznetbeans.exezword.exezwinword.exez	excel.exezpowerpnt.exezoutlook.exez	teams.exez	slack.exezdiscord.exezzoom.exez	skype.exez
notion.exezobsidian.exezonenote.exezevernote.exeZterminalzcmd.exezpowershell.exeZbashzgit-bash.exezpostman.exezinsomnia.exezgit.exez
python.exeznode.exez
chrome.exezfirefox.exez
msedge.exez	opera.exez	brave.exezvivaldi.exeZsafariziexplore.exebrowserzfilezilla.exez
winscp.exez	putty.exezmobaxterm.exez	mysql.exezpsql.exezpgadmin4.exeZ
phpmyadminZapacheZnginxZhttpdzspotify.exezvlc.exezmpv.exezwmplayer.exez	steam.exezepicgameslauncher.exezwhatsapp.exeztelegram.exez
signal.exezmessenger.exe)productivityr   servernon-workc                    sD   | sdS |    t D ]&\}}t fdd|D r|  S qdS )z+Categorize an application based on its nameuncategorizedc                 3   s   | ]}| kV  qd S )N ).0appZ	app_lowerr   ./categorize_all_activities.py	<genexpr>>   s     z!categorize_app.<locals>.<genexpr>)lower
CATEGORIESitemsany)app_namecategoryappsr   r   r   categorize_app6   s    
r   z)=== Categorizing All Activity Records ===z"
1. Current category distribution:z
    SELECT 
        CASE 
            WHEN category IS NULL OR category = '' THEN 'NULL/Empty'
            ELSE category 
        END as cat,
        COUNT(*) as count
    FROM activity_records
    GROUP BY cat
    ORDER BY count DESC
z   z: z recordsz5
2. Updating categories based on application names...zg
    SELECT DISTINCT application_name
    FROM activity_records
    WHERE application_name IS NOT NULL
zc
        UPDATE activity_records
        SET category = %s
        WHERE application_name = %s
    z -> z (z	 records)u   
✅ Total records updated: z
3. New category distribution:zp
    SELECT category, COUNT(*) as count
    FROM activity_records
    GROUP BY category
    ORDER BY count DESC
z$
4. Sample categorized applications:)r   r   r   r   r   z
   z
        SELECT DISTINCT application_name, COUNT(*) as count
        FROM activity_records
        WHERE category = %s
        GROUP BY application_name
        ORDER BY count DESC
        LIMIT 5
    z      - z      (no applications)uO   
✅ Categorization complete! Your dashboard should now show proper categories.)#Zpsycopg2osZdotenvr   getenvr   replacesplitZ
conn_partsZ	user_passZhost_dbZ	host_portZconnectlenZconnr   Zcurr   r   printZexecuteZfetchallcatcountZ	app_namesZtotal_updatedr   r   ZrowcountupdatedZcommitupperr   r   closer   r   r   r   <module>   s  
                                                             



 
	