-
Notifications
You must be signed in to change notification settings - Fork 0
/
Route.py
72 lines (55 loc) · 2.2 KB
/
Route.py
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
from datetime import timedelta
class Route:
def __init__(self, origin, destination) -> None:
self.origin = origin
self.destination = destination
self.travel_modes = []
self.travel_distances = []
self.travel_durations = []
self.origin_destination_pairs = []
self.waypoints = []
self.total_duration = -1
self.total_distance = -1
def setTravelModes(self, travel_modes: list):
self.travel_modes = travel_modes
def getTravelModes(self):
return self.travel_modes
def getTransfersTimes(self):
return len(self.travel_modes)
def setTravelDistances(self, travel_distances: list):
self.travel_distances = travel_distances
def setTravelDurations(self, travel_durations: list):
self.travel_durations = travel_durations
def setWaypoints(self, waypoints: list):
self.waypoints = waypoints
def getWaypoints(self):
return self.waypoints
def setPartialOriginDestinationPairs(self, origin_destination_pairs: list):
self.origin_destination_pairs = origin_destination_pairs
def setTotalDuration(self, total_duration):
self.total_duration = total_duration
def getTotalDuration(self):
return self.total_duration
def setTotalDistance(self, total_distance):
self.total_distance = total_distance
def getTotalWalkingDuration(self) -> int:
total_time = 0
for i, travel_mode in enumerate(self.travel_modes):
if travel_mode[0] == "Walking":
total_time += self.travel_durations[i]
return total_time
def getTotalTransportingDuration(self) -> int:
total_time = 0
for i, travel_mode in enumerate(self.travel_modes):
if travel_mode[0] != "Walking":
total_time += self.travel_durations[i]
return total_time
@staticmethod
def str_distance(distance):
"""format distance value from meter to kilo meter"""
return f"{round(distance / 1000, 3)} km"
@staticmethod
def str_duration(duration):
"""format duration value from seconds to h:m:s"""
convert = str(timedelta(seconds=duration))
return convert