Skip to content

Instantly share code, notes, and snippets.

@natyrix
Created October 23, 2022 18:40
Show Gist options
  • Save natyrix/82f22e951fa53819781f47e8960e232e to your computer and use it in GitHub Desktop.
Save natyrix/82f22e951fa53819781f47e8960e232e to your computer and use it in GitHub Desktop.
def calculate_speeds(self, starting_time_list, ending_time_list, distance_list):
speed_list = []
for i in range(len(starting_time_list)):
try:
start_datetime_object = datetime.strptime(starting_time_list[i], '%Y-%m-%d %H:%M:%S')
end_datetime_object = datetime.strptime(ending_time_list[i], '%Y-%m-%d %H:%M:%S')
time_taken = end_datetime_object-start_datetime_object
hrs = time_taken.total_seconds()/3600
speed_list.append(distance_list[i]/hrs)
except Exception as e:
speed_list.append(0.0)
return speed_list
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment