-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
49 lines (41 loc) · 1.45 KB
/
Copy pathutils.py
File metadata and controls
49 lines (41 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/usr/bin/python3
# Utility functions
import geopy.distance
import statistics
import pprint
def calculateGPSdistance(location1, location2):
distanceInFeet = geopy.distance.distance(location1, location2).feet
return distanceInFeet
# The normal Python list sorting functions are behaving strangely. I think because the list is a complex type.
# So, we're going back to basics and doing a recursive sort here.
def sortSegments(listToSort):
if len(listToSort) == 1:
return listToSort
shortestSegmentIndex = 0
try:
for idx, [time, points] in listToSort:
if time < listToSort[shortestSegmentIndex][0]:
shortestSegmentIndex = idx
except ValueError:
pprint.pprint(listToSort)
savePoints = listToSort[shortestSegmentIndex][1]
del listToSort[shortestSegmentIndex]
saveItem = [time, savePoints]
return [saveItem].append(sortSegments(listToSort))
def averageFilter(times):
if type(times) == type(int):
return times
if len(times) == 0:
return 0
floatList = [float(x) for x in times]
return sum(floatList)/len(floatList)
# We use statistics.pstdev() here because we're calculating the stdev
# of the entire series, we're not working ith just a sample of lap times,
# we're working with all the lap times.
def stdDevFilter(times):
if len(times) == 0:
return 0
floatList = [float(x) for x in times]
return statistics.pstdev(floatList)
if __name__ == '__main__':
print("This file should not be called directly.")