<s> import bisect <EOL> import time <EOL> import status <EOL> class StatusHistory ( ) : <EOL> """<STR_LIT>""" <EOL> EPOCH_TIME = <NUM_LIT> <EOL> START_TIME = int ( time . time ( ) ) <EOL> def __init__ ( self , uid ) : <EOL> with open ( "<STR_LIT>" . format ( uid = uid ) ) as f : <EOL> self . activity = self . parse_status ( map ( str . strip , f . readlines ( ) ) ) <EOL> def create_time_map ( self , status_list ) : <EOL> status_map = { } <EOL> for item in status_list : <EOL> status_map [ int ( float ( item [ "<STR_LIT:time>" ] ) ) ] = item [ "<STR_LIT:status>" ] <EOL> return status_map <EOL> def parse_status ( self , lines ) : <EOL> activity = [ ] <EOL> seen_times = set ( ) <EOL> for line in lines : <EOL> time , fields = line . split ( "<STR_LIT:|>" ) <EOL> if time not in seen_times : <EOL> seen_times . add ( time ) <EOL> status_obj = status . Status ( int ( float ( time ) ) , fields ) <EOL> activity . append ( status_obj ) <EOL> return activity <EOL> def get_status ( self , time ) : <EOL> """<STR_LIT>""" <EOL> idx = bisect . bisect ( self . activity , time ) <EOL> current_status = self . activity [ max ( <NUM_LIT:0> , idx - <NUM_LIT:1> ) ] <EOL> return current_status <EOL> def normalised ( self , max_time_back_seconds = None , resolution = <NUM_LIT> , status_type = None ) : <EOL> """<STR_LIT>""" <EOL> if max_time_back_seconds is None : <EOL> start_time = self . EPOCH_TIME <EOL> else : <EOL> start_time = self . START_TIME - max_time_back_seconds <EOL> for tick in range ( start_time , self . START_TIME , resolution ) : <EOL> status_obj = self . get_status ( tick ) <EOL> if status_type is None : <EOL> yield status_obj . highest_active_status_type ( ) <EOL> else : <EOL> yield status_obj . _status [ status_type ] </s>
