
    Evi                    T    d Z ddlmZ ddlmZ ddlmZ ddlmZ g dZ	dddZ
ddZdS )u  Org snapshot builder — assembles a daily view of all projects from mock data.

The snapshot is the unit the user-aware agent operates on.
When the RT agent exists, it will push a pre-built snapshot instead of this module
computing it on demand.

Shape:
    {
        "date": "2026-03-15",
        "org": "Tata Steel",
        "projects": {
            "bf3-coal-supply": {
                "emails": [...],        # emails dated <= snapshot_date, project-tagged
                "tickets": [...],       # tickets created <= snapshot_date, project-tagged
                "open_tickets": int,
                "critical_tickets": int,
            },
            ...
        }
    }
    )annotations)date)EMAILS)TICKETS)zbf3-coal-supplyzdie-casting-maintenanceziron-ore-opszsafety-compliancezenterprise-brainzclient-deliveryzq2-capacity-planningNsnapshot_datestr | date | Nonereturndictc                   | d} t          |           i }t          D ]ffdt          D             }fdt          D             }d |D             }d |D             }||t	          |          t	          |          d|<   gd|d	S )
zBuild the org snapshot for a given date (defaults to latest data date).

    Only includes emails and tickets on or before snapshot_date so the agent
    sees a point-in-time view, not the full history.
    Nz
2026-03-20c                ^    g | ])}|                     d           k    |d         k    '|*S )projectr   get).0ecutoffr   s     </var/www/html/ai-enterprise-brain/data/mock_data/snapshot.py
<listcomp>z"build_snapshot.<locals>.<listcomp>5   sH     
 
 
uuY7**qyF/B/B /B/B/B    c                ^    g | ])}|                     d           k    |d         k    '|*S )r   createdr   )r   tr   r   s     r   r   z"build_snapshot.<locals>.<listcomp>9   sH     
 
 
uuY7**q|v/E/E /E/E/Er   c                &    g | ]}|d          dv|S )status)Done r   r   s     r   r   z"build_snapshot.<locals>.<listcomp>=   s&    KKKaak.J.J.J.J.Jr   c                *    g | ]}|d          dk    |S )priorityCriticalr   r   s     r   r   z"build_snapshot.<locals>.<listcomp>>   s&    KKK!q}
/J/JA/J/J/Jr   )emailsticketsopen_ticketscritical_ticketsz
Tata Steel)r   orgprojects)str	_PROJECTSr   r   len)r   r&   r!   r"   r#   criticalr   r   s         @@r   build_snapshotr+   )   s     $F "H 
 

 
 
 
 

 
 

 
 
 
 

 
 
 LK7KKKKK|KKK -- #H	
 
   r   snapshotuserc                    |d         t          |                    dg                     }i }| d                                         D ])\  }}||vr
fd|d         D             }i |d|i||<   *i | d|iS )zuReturn a copy of the snapshot containing only projects the user is on,
    and only emails visible to that user.
    emailr&   c                D    g | ]}|                     d g           v |S )recipients_visible_tor   )r   r   
user_emails     r   r   z#filter_for_user.<locals>.<listcomp>Z   s=     
 
 
QUU#:B???? ???r   r!   )setr   items)r,   r-   user_projectsfiltered_projectsproject_keyproject_datavisible_emailsr2   s          @r   filter_for_userr:   N   s     gJR0011M)+%-j%9%?%?%A%A 
 
!\m++
 
 
 
#H-
 
 
*
*
n*
 *
+&&

%  r   )N)r   r   r	   r
   )r,   r
   r-   r
   r	   r
   )__doc__
__future__r   datetimer   data.mock_data.emailsr   data.mock_data.ticketsr   r(   r+   r:   r   r   r   <module>r@      s    , # " " " " "       ( ( ( ( ( ( * * * * * *  	" " " " "J     r   