U
    [Mh                     @   sV   d Z ddlmZmZmZ ddlmZ ddlZddlmZm	Z	 dd Z
edkrRe
  dS )	z>
Fix Working Hours Calculation - Show realistic working hours
    )datetimetimezone	timedelta)SessionLocalN)funcand_c               
   C   s  t  } zztd td tdddtjd}|jddddd}|jd	d
d
dd}td|   td | t	j
tt	j
jdkt	j
j|kt	j
j|kt	j
j  }tdt|  i }d}|D ]}|j}|j}	||	7 }||krddi d||< || d  d7  < || d  |	7  < |j}
|
|| d krRd|| d |
< || d |
  |	7  < qtd|d dd t  td td d}t| dd ddD ]\}}|d }|d }|dkrd }|}d!}n"|d"kr d }|}d#}n|d$krd%}|d& }d'}n|d(krd}d}|d  D ]|\}
}||7 }d)|
 krf||d* 7 }nNd+|
 ksd,|
 kr||7 }n(d-|
 kr||d* 7 }n||d. 7 }q:|dkrt|| d  nd/}d0}n,|d1krd2}|d3 }d4}nd5}|d6 }d7}||7 }|d }t|  d8|dd9|dd:| d; td<|  t|d  d=d ddd>d }|D ]*\}
}|d }td?|
 d8|dd@ qtt  q|d }|| d  }tdA tdB tdC|d dd@ tdD|dd@ tdE|dFdG t  tdH tdI tdJ tdK|dd@ tdLt|dM dd@ |dMkrftdN ntdO t  tdP tdQ tdR tdS tdT tdU W nB tk
r } z"tdV|  dd>l}|  W 5 d>}~X Y nX W 5 |   X d>S )Wz(Show corrected working hours calculationu%   🔧 FIXING WORKING HOURS CALCULATIONz<============================================================i  	      )Ztzinfor   )ZhourZminutesecondZmicrosecond   ;   i?B u   📅 Analyzing z(----------------------------------------   zTotal activities: )count
total_timeappsr      r   r   zTotal time: i  z.2fz hoursu)   📊 REALISTIC WORKING HOURS CALCULATION:z2--------------------------------------------------c                 S   s   | d d S )Nr   r    xr   r   ./fix_working_hours.py<lambda>F       z#fix_working_hours.<locals>.<lambda>T)keyreverseZdevelopmentd   zAll coding/development workdatabasezAll database workZbrowserU   g333333?z;Most browser time is work-related (docs, research, testing)otherZlockappg?ZdatagripZpostmanZsnippingg      ?2   z9Smart analysis of apps (LockApp=90%, DataGrip=100%, etc.)system
   g?z&Minimal work-related system activities   g?zConservative estimatez: u   h total → zh working (z%)z
  Reason: c                 S   s   | d S )Nr   r   r   r   r   r   r      r   Nu     • hu   🎯 FINAL RESULTS:z------------------------------u   📊 Total Time: u   💼 Working Time: u   📈 Productivity Rate: z.1f%u   🔍 COMPARISON:z--------------------z?Current app calculation: ~6.74h (from RealisticHoursCalculator)zManual calculation: zDifference: g(\@u0   ✅ Manual calculation is MORE generous (better)u*   ⚠️ Manual calculation is LESS generousu   💡 RECOMMENDATION:z>For a developer, 7+ hours on September 13th is very realistic!z- 2.51h pure codingz&- 2.72h research/documentation/testingz(- 1.51h breaks/tools during work sessionu   = 6.74h total working time ✅u   ❌ Error: )r   closeprintr   r   ZutcreplacedateZquerymodelsZActivityRecordfilterr   Zuser_idZ	timestampZorder_byZascalllencategorydurationZapplication_namesorteditemslowerintupperabs	Exception	traceback	print_exc)ZdbZtarget_dateZstart_of_dayZ
end_of_dayZ
activitiesZcategory_datar   Zactivityr,   r-   ZappZworking_timedataZcat_timeZ	cat_hoursZwork_percentageZ	work_timereasonZtotal_other_timeZapp_timeZ
work_hoursZtop_appsZ	app_hoursZtotal_working_hoursZproductivity_rateer5   r   r   r   fix_working_hours
   s    





 





("


r:   __main__)__doc__r   r   r   r   r   r(   Z
sqlalchemyr   r   r:   __name__r   r   r   r   <module>   s    )