def tally_readings_per_second ( data ) :
time_tallies = dict ( )
for item in data :
key = item [ 0 ]
if ( key in time_tallies ) :
time_tallies [ key ] = time_tallies [ key ] + 1
else :
time_tallies [ key ] = 1
return time_tallies
def total_count_for_each_reading_per_second ( time_tallies ) :
tally_totals = dict ( )
for val in time_tallies . values ( ) :
if ( val in tally_totals ) :
tally_totals [ val ] = ( tally_totals [ val ] ) + 1
else :
tally_totals [ val ] = 1
return tally_totals
def get_rps_above ( threshold , readings ) :
times = list ( )
for k , v in readings . items ( ) :
if ( v > = threshold ) :
times . append ( k )
return times
def find_flickers ( selected_readings , all_readings ) :
selected = dict ( )
for current_selected_reading in selected_readings :
readings = list ( )
for current_reading in all_readings :
if ( current_selected_reading == current_reading [ 0 ] ) :
readings . append ( current_reading [ 1 ] )
selected [ current_selected_reading ] = readings
return selected
def find_readings_with_lights_on ( flicker_entries ) :
filtered_readings = list ( )
for time , reading in flicker_entries . items ( ) :
for item in reading :
val = int ( item )
if ( val > 39 ) :
filtered_readings . append ( ( time , reading ) )
return filtered_readings