<s> """<STR_LIT>""" <EOL> import sys <EOL> import json <EOL> import datetime <EOL> from . import util <EOL> timediff = lambda a , b : str ( datetime . timedelta ( seconds = int ( a - b ) ) ) <EOL> class Times ( object ) : <EOL> def __init__ ( self ) : <EOL> self . entry = [ ] <EOL> def load ( self , file_path ) : <EOL> self . entry = json . load ( open ( file_path ) ) <EOL> def save ( self , file_path ) : <EOL> util . json_dump ( self . entry , file_path ) <EOL> def add_task ( self , task_id , name , start , stop , args = None ) : <EOL> self . entry . append ( dict ( task_id = task_id , name = name , start = start , <EOL> stop = stop , args = args ) ) <EOL> def positions ( self , prop , start , stop ) : <EOL> span = stop - start <EOL> if not span : <EOL> return "<STR_LIT>" <EOL> start_rel = ( prop [ "<STR_LIT:start>" ] - start ) / span <EOL> stop_rel = ( prop [ "<STR_LIT>" ] - start ) / span <EOL> line_len = <NUM_LIT> <EOL> a = int ( start_rel * line_len ) <EOL> b = int ( ( stop_rel - start_rel ) * line_len ) or <NUM_LIT:1> <EOL> c = line_len - a - b <EOL> return a , b , c <EOL> def time_line ( self , prop , start , stop ) : <EOL> a , b , c = self . positions ( prop , start , stop ) <EOL> pr = <NUM_LIT:10> <EOL> return "<STR_LIT>" % ( <EOL> "<STR_LIT:U+0020>" * pr , "<STR_LIT:->" * a , "<STR_LIT:#>" * b , "<STR_LIT:->" * c , <EOL> timediff ( prop [ "<STR_LIT>" ] , prop [ "<STR_LIT:start>" ] ) ) <EOL> def pointer_line ( self , prop , start , stop ) : <EOL> a , b , c = self . positions ( prop , start , stop ) <EOL> if b == <NUM_LIT:1> : <EOL> t = "<STR_LIT>" <EOL> b = <NUM_LIT:0> <EOL> else : <EOL> t = "<STR_LIT>" <EOL> b -= <NUM_LIT:2> <EOL> t0 = timediff ( prop [ "<STR_LIT:start>" ] , start ) <EOL> t1 = timediff ( prop [ "<STR_LIT>" ] , start ) <EOL> begin = a + <NUM_LIT:10> - len ( t0 ) - <NUM_LIT:1> <EOL> return "<STR_LIT>" % ( "<STR_LIT:U+0020>" * begin , t0 , "<STR_LIT:U+0020>" * b , t , t1 ) <EOL> def print_report ( self ) : <EOL> for chunk in self . iter_report ( ) : <EOL> sys . stdout . write ( chunk ) <EOL> sys . stdout . flush ( ) <EOL> def iter_report ( self ) : <EOL> if not self . entry : <EOL> return <EOL> first_start = min ( e [ "<STR_LIT:start>" ] for e in self . entry ) <EOL> last_stop = max ( e [ "<STR_LIT>" ] for e in self . entry ) <EOL> out = [ ] <EOL> for prop in self . entry : <EOL> out . append ( ( prop [ "<STR_LIT:start>" ] , <EOL> "<STR_LIT>" % ( prop [ "<STR_LIT>" ] , prop [ "<STR_LIT:name>" ] ) , <EOL> self . time_line ( prop , first_start , last_stop ) , <EOL> self . pointer_line ( prop , first_start , last_stop ) ) ) <EOL> out . sort ( ) <EOL> longest = max ( len ( e [ <NUM_LIT:1> ] ) for e in out ) <EOL> f = "<STR_LIT>" % ( longest , longest ) <EOL> for start , title , tl , pl in out : <EOL> yield f % ( title , tl , "<STR_LIT>" , pl ) </s>
