from services import log_services
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 ( )
# print(readings.values())
for k , v in readings . items ( ) :
# print([k, v])
if ( v > = threshold ) :
times . append ( k )
return times
def find_flickers ( selected_readings , all_readings ) :
selected = dict ( )
# log_services.print_list(selected_readings)
# print(all_readings[1])
# print(type(all_readings[0]))
for current_selected_reading in selected_readings :
readings = list ( )
for current_reading in all_readings :
# print(f"Checking {item} is in {x}...")
if ( current_selected_reading == current_reading [ 0 ] ) :
# selected[item] = x[1]
# print(f"Added {item}.")
# selected.append( (item, x[1]) )
readings . append ( current_reading [ 1 ] )
selected [ current_selected_reading ] = readings
return selected