from find_it import find_closest
from tm2secs2tm import time2secs,secs2time,format_time
def find_nearest_time(look_for,target_data):
    what=time2secs(look_for)
    where=[time2secs(t) for t in target_data]
    res=find_closest(what,where)
    return(secs2time(res))

row_data={}
with open('PaceData.xlsx') as paces:
    column_headings=paces.readline().strip().split(',')
    column_headings.pop(0)
    for each_line in paces:
        row=each_line.strip().split(',')
        row_label=row.pop(0)
        inner_dict={}
        for n in range(len(column_headings)):
            inner_dict[format_time(row[n])]=column_headings[n]
        row_data[row_label]=inner_dict
        
distance_run=input('Enter the distance attempted:')
recorded_time=input('Enter the recorded time:')
predicted_distance=input('Enter the distance you want a prediction for:')

closet_time=find_nearest_time(format_time(recorded_time),row_data[distance_run])
closet_column_heading=row_data[distance_run][closet_time]
prediction=[k for k in row_data[predicted_distance].keys() if row_data[predicted_distance][k]==closet_column_heading]
'''print(column_heading)
prediction=[k for k in row_data['20k'].keys() if row_data['20k'][k]==column_heading]
print(find_nearest_time('1:01:01',['1:00:00','2:00:00','1:01:00']))'''
print(prediction)