
    f%                     (    d dl Z d dlZ G d d      Zy)    Nc                   8    e Zd ZdZd	dZd
dZd Zd Zd Zd Z	y)Otriaz+basic functions for a collection of reportsc                     || _         || _        g | _        i | _        i | _        |j                  D ]  }| j                  j                  |        y N)e
do_verboselive
cache_sent
cache_seleappend)selferimpr   repcodes       !/home/ernad/ernad/python/otria.py__init__zOtria.__init__
   sJ    $	 zzGIIW% "    Nc                    || j                  |       | j                  }g }i }| j                  D ]  }|j                  |   }|j                  d   }|j
                  j                  |      }	|	|j                  |       P|j                  j                  |	      }
|j                  d   }|j
                  j                  ||
      }t        j                  j                  |      dd }t        |      dk(  r)d|
 }|d| z  }t        |t         j"                         |||<    g }|D ]   }|dd }|||vs|j                  |       " t%        |d	
      }g }|D ]R  }g }|D ]!  }|dd }||k7  r|j                  |dd        # t%        |      }|D ]  }|j                  | d|         T g }|r|D ]  }t        |dz   ||   z           |D ]  }|j                  ||          || _         |D ]  }|j                  |        |S )Nsentselectedr      zno selected at sent  in file
   T)reverse   _ )timely_by_issuedater   r	   reportstaged	very_lastr   f	issuedatelast_by_issuedateospathbasenamelenprintsysstderrsortedsorted_by_timely)r   r   r%   r   natal_reportsrepcode_critsr   r    sent_dirlast_sent_fufilast_sent_issuedateselected_dir	crit_fufi	crit_banamsgfound_issuedatescritfound_issuedatesorted_issuedatessorted_crits	sub_critsthis_found_issuedatesub_critsorted_repcodess                           r   	by_timelyzOtria.by_timely   sO    $$Y/FFyyGXXg&F||F+HSS]]84N%$$W-"###--"?!<<
3L--l.ACI((3Ab9I9~",-@,ABgY''c

+'.M)$# !& !D"1RjO&&66 ''8 " ##3TB0OI%'+Abz$'?:  b-	 &
 y)I%##&7q
$CD &  1 $dSj=#667 % D""=#67$3D! ! %G""7+ % r   c                 (   i ddl m}  || j                        | _         | j                  D ]H  }| j                   j	                  |d      }|d|<   't
        j                  j                  |      |<   J t        | j                  fd      }|S )Nr   )Moclatrainc                     |    S r    xcritss    r   <lambda>z%Otria.by_train_size.<locals>.<lambda>Z   s	    %(r   key)	moclarD   r   r	   findr'   r(   getsizer.   )r   rD   r   
train_fufirA   rJ   s        @r   by_train_sizezOtria.by_train_sizeP   sz    466]
yyG':J!!"g!#!<g ! !0BCr   c                    | j                   }t        | d      s| j                          g }g }| j                  D ]  }|j                  |   j                  d      }||j                  |       5|j                  |   j                  dd      }||j                  |       it        j                  j                  |      }t        j                  j                  |      }||kD  s|j                  |        | j                  D ];  }||v r||v r|j                  |   j                         r+|j                  |       = |S )Nr/   r   modelz*.model)kind)r   hasattrrB   r/   r    lastr   r'   r(   getmtimehas_it_labour)	r   r   skippedorderedr   	last_sent
last_modellast_model_mtimelast_sent_mtimes	            r   by_model_urgezOtria.by_model_urge]   s.   FFt/0NN,,G)..v6I w''*//i/HJ!w'!ww//
; gg..y9O/1w' -" ,,G'!'!xx ..0NN7# - r   c                 |    | j                         }t        |      }|dz   }i }d}|D ]  }|dz  }||z
  |z  ||<    |S )zGcaculates a fraction to add to numbers to prioritize high otria reportsg?r      )rB   r*   )r   repcodestotal
total_plusoutpositionr   s          r   to_fractionzOtria.to_fraction   sW    >>#HS[
GMH!H,
:CL   
r   c                 L   | j                   }g }i }i |j                  D ]7  }|j                  |   }|| j                  vr7|j                  d   }|j
                  j                  |      | j                  |<   || j                  |   vrj| j                  |   |   ||<   || j                  vr7|j                  d   }|j
                  j                  |      | j                  |<   || j                  |   vr"t        d| d| t        j                         |j                  |       | j                  |   |   }	|j                  j                  |	      |<   : t        |fd      }
i }|
D ]
  }||   ||<    | j                   r|D ]  }t        d| d	||   z           |S )
Nr   r   zotria: no select for sent r   r   c                     |    S r   rG   rH   s    r   rK   z+Otria.timely_by_issuedate.<locals>.<lambda>   s	    U1Xr   rL   zotria r   )r   reportsr    r
   r!   r"   firstsr   lastsr+   r,   r-   r   r$   shotir.   r   )r   r%   r   repcode_list
sent_fufisr   r    	sent_fudi	sele_fudi	sele_fufirA   rf   rJ   s               @r   r   zOtria.timely_by_issuedate   s   FF
yyGXXg&Fdoo-"LL0	+,33::i+@( 88"&//'":9"EJwdoo-"LL4	+,3399Y+?( 8829+T'K::'(0;ISSYYy1E'N# !$ !3EF&G%g.CL '??yk+c'l:; 
r   )F)FN)
__name__
__module____qualname____doc__r   rB   rR   r`   rh   r   rG   r   r   r   r      s%    57rL
r   r   )r,   r'   r   rG   r   r   <module>rx      s    
 	f fr   