Hello I am using Python to calculate the distance that user walked. I am determining whether they walked or not by speed. If there speed was slower than 5m/s, they I will consider as walking. But I am having trouble making this function. Could you help me out how to make function for this? So far my input is manually put another function called "make_timestamped_loc" and calculating the distance by function called "total_dist" Here is my code...
import ctp17hw1
dic_loc = []
def make_timestamped_loc(La, Lng, TS):
new_loc = {}
new_loc['latitude'] = La
new_loc['longitude'] = Lng
new_loc['timestamp'] = int(TS)
dic_loc.append(new_loc)
make_timestamped_loc(37.481236, 126.952733, 1483196400)
make_timestamped_loc(37.310045, 127.101255, 1408323255)
make_timestamped_loc(37.383065, 126.672596, 1508322531)
make_timestamped_loc(37.383065, 116.672596, 1444999230)
# make_timestamped_loc(37.383065, 112.672596, 1444999230) #error sample
print(dic_loc)
def sort_locs(sortingDict):
newlist = sorted(sortingDict, key=lambda k: k['timestamp'])
for i in range(len(dic_loc) - 1, -1, -1):
dic_loc.remove(dic_loc[i])
for i in range(len(newlist)):
for j in range(len(newlist)):
if (newlist[i]['timestamp'] == newlist[j]['timestamp']
and (newlist[i]['latitude'] != newlist[j]['latitude'] or newlist[i]['longitude'] != newlist[j]['longitude'])
and i != j):
raise ValueError('There is duplicated location on same time!')
sortingDict.append(newlist[i])
sort_locs(dic_loc)
def total_dist(sortedDict):
totalDist = 0;
for i in range(len(sortedDict) - 1):
sm = ctp17hw1.dist(sortedDict[i]["latitude"], sortedDict[i]["longitude"], sortedDict[i+1]["latitude"], sortedDict[i+1]["longitude"])
totalDist = totalDist + sm
return totalDist
total_dist(dic_loc)
print(total_dist(dic_loc))
ctp17hw1 is another file for calculating the distance. I am confusing because of Unix time. Thank you very much