U
    7h                  6   @   s0  d dl mZmZ d dlmZ d dlZd dlmZ e  ede	 Z
e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)d*d+d,d-d.d/d0d1d2d3d4d5d6d7d8d9d:d;g6d<d=d>d?d@dAdBdCdDdEdFdGdHgdIdJdKdLdMdNdOdPdQdRdSdTdUdVdWdXdYgdZd[d\d]d^d_d`dadbdcdddedfdgdhgdiZdjdk Zedl e Zedm eednZeD ]$Zedoed   dpedq  dr qXeds eedtZe Zd Ze ZzzeD ]Z\ZeeZeedueedvZejZee7 Zed kredoe dwe dxe dy qe  edze  W n< ek
r^ Z ze   ed{e   W 5 dZ[X Y nX ed| eed}ZeD ]$Zedoed   dpedq  dr qzed~ dD ]lZede!  d eeddeiZe Z"e"re"D ] \Z#Z$ede# dpe$ dr qned qW 5 Q R X ed dS )    )create_enginetext)ConfigN)load_dotenvDATABASE_URLzcode.execodez
cursor.exeZ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.exepython3ZnpmZyarnZpipZpip3z
chrome.exezfirefox.exez
msedge.exez	opera.exez	brave.exezvivaldi.exeZsafariziexplore.exebrowserZchromiumzgoogle-chromeZfirefoxzmicrosoft-edgezfilezilla.exez
winscp.exez	putty.exezmobaxterm.exez	mysql.exezpsql.exezpgadmin4.exeZ
phpmyadminZapacheZnginxZhttpdZsshZsshdZ	systemctlZdockerzdocker-composeZkubectlzspotify.exezvlc.exezmpv.exezwmplayer.exez	steam.exezepicgameslauncher.exezwhatsapp.exeztelegram.exez
signal.exezmessenger.exeZspotifyZvlcZmpvZ	rhythmboxztelegram-desktop)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_sqlalchemy.py	<genexpr>6   s     z!categorize_app.<locals>.<genexpr>)lower
CATEGORIESitemsany)app_namecategoryappsr   r   r   categorize_app.   s    
r   z)=== Categorizing All Activity Records ===z"
1. Current category distribution:a  
        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...zw
        SELECT DISTINCT application_name
        FROM activity_records
        WHERE application_name IS NOT NULL
    z
                UPDATE activity_records
                SET category = :category
                WHERE application_name = :app_name
            )r   r   z -> z (z	 records)u   
✅ Total records updated: u   
❌ Error during update: z
3. New category distribution:z
        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 = :category
            GROUP BY application_name
            ORDER BY count DESC
            LIMIT 5
        r   z      - z      (no applications)uO   
✅ Categorization complete! Your dashboard should now show proper categories.)%Z
sqlalchemyr   r   Zconfigr   osZdotenvr   getenvZget_database_urlr   Zenginer   r   printZconnectZconnZexecuteresultrowZfetchallZ	app_namesZtotal_updatedZbeginZtransr   r   ZrowcountupdatedZcommit	ExceptioneZrollbackupperr   r   countr   r   r   r   <module>   s4                                                                               !"


 "
	