o
    3gw                     @  s   d Z ddlmZ ddgZddlmZmZ ddlmZ ddl	m
Z
 dd
dZddlmZmZmZ ddlmZ eG dd dZdddZdddZddlmZmZ dddZdS ) zg
[[https://github.com/nomeata/arbtt#arbtt-the-automatic-rule-based-time-tracker][Arbtt]] time tracking
    )annotationsijsoncffi)IterableSequence)	dataclass)PathreturnSequence[Path]c                  C  sR   zddl m}  W n ty   ddlm} |d g  Y S w ddlm} || jS )Nr   )arbtt)lowzCouldn't find 'arbtt' config section, falling back to the default capture.log (usually in HOME dir). Add 'arbtt' section with logfiles = '' to suppress this warning.   )	get_files)	my.configr   ImportErrormy.core.warningsr   corer   logfiles)user_configr   r    r   "/home/garg/my-data/HPI/my/arbtt.pyinputs   s   
r   )JsonPathIshdatetime_aware)fromisoformatc                   @  s6   e Zd ZU dZded< edddZedd	d
ZdS )Entryz
    For the format reference, see
    https://github.com/nomeata/arbtt/blob/e120ad20b9b8e753fbeb02041720b7b5b271ab20/src/DumpFormat.hs#L39-L46
    r   jsonr	   r   c                 C  sf   | j d }d}t|}||k r!|d d d||   d }t|S ||kr/|d |d  d }t|S )Ndate   0Zr   )r   lenr   )selfdselenldsr   r   r   dt+   s   
zEntry.dt
str | Nonec                 C  sb   dd | j d D }t|d }|d u rd S t|d }|d u s"J ||d }|d }| d| S )Nc                 s  s    | ]	}|d  r|V  qdS )activeNr   ).0wr   r   r   	<genexpr>>   s    zEntry.active.<locals>.<genexpr>windowsprogramtitlez: )r   next)r$   aitaa2ptr   r   r   r*   ;   s   

zEntry.activeN)r	   r   )r	   r)   )__name__
__module____qualname____doc____annotations__propertyr(   r*   r   r   r   r   r   !   s   
 r   Iterable[Entry]c            	   	   #  s    t t } ddg t| dkr g}n	 fdd| D }ddlm}m} dd lm  m} |D ]0}|||d }|j	}|d usBJ |
|dD ]}t|d	V  qHW d    n1 s[w   Y  q0d S )
Nz
arbtt-dumpz--format=jsonr   c                   s   g | ]
}g  d |qS )z	--logfiler   r+   fbaser   r   
<listcomp>V   s    zentries.<locals>.<listcomp>)PIPEPopen)stdoutitem)r   )listr   r#   
subprocessrC   rD   ijson.backends.yajl2_cffibackends
yajl2_cffirE   itemsr   )	inpscmdsrC   rD   r   cmdr5   outr   r   r@   r   entriesL   s"   
rQ   Nonec                    s`   ddl m}  ddlm} | t  fddt D }dd |D }||tj dtj d d S )	Nr   )Freezer)
magic_fillc                 3  s    | ]}  |V  qd S N)freeze)r+   efreezerr   r   r-   f   s    z fill_influxdb.<locals>.<genexpr>c                 s  s    | ]
}|j d ur|V  qd S rU   )r*   r>   r   r   r   r-   i   s    :)name)core.freezerrS   core.influxdbrT   r   rQ   r8   r7   )rS   rT   fitr   rX   r   fill_influxdbb   s   r_   r   )Statsstatr`   c                   C  s   t tS rU   )ra   rQ   r   r   r   r   statss   s   rb   N)r	   r
   )r	   r=   )r	   rR   )r	   r`   )r:   
__future__r   REQUIREScollections.abcr   r   dataclassesr   pathlibr   r   my.corer   r   r   my.core.compatr   r   rQ   r_   r   r`   ra   rb   r   r   r   r   <module>   s    

*
