This repository has been archived by the owner on Aug 2, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcombinations.py
71 lines (58 loc) · 2.28 KB
/
combinations.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
class FlightCombinations:
def __init__(self, prem_flight, sec_flight):
'''
args : instance of the Flight class
prem_flight : the first flight
sec_flight : the second flight
'''
self._first_flight = prem_flight
self._second_flight = sec_flight
self._is_valid = self._check_combination()
def is_valid(self)->bool:
'''return if the combination of the flight are possible'''
return self._is_valid
def _check_combination(self)->bool:
if self._possible_destinations() and self._acceptable_time():
return True
else:
return False
def _possible_destinations(self)->bool:
'''
return:
true if possible destinations between 2 flights
else false
possible:
a->b b->c
'''
if (self._first_flight.arrival_destination() == self._second_flight.departure_destination()) and (
self._first_flight.departure_destination() != self._second_flight.arrival_destination()):
return True
else:
return False
def _acceptable_time(self)->bool:
'''
if the time difference between arrival of the first flight and departure of the second
is between 1 and 4 hours
return : bool
'''
time_delta = self._second_flight.departure_time() - self._first_flight.arrival_time()
time_hours = time_delta.seconds/3600
if time_hours >= 1 and time_hours <= 4:
return True
else:
return False
def max_allowed_bags(self)->int:
''' return the maximum allowed bags for both flight'''
return min(
self._first_flight.max_allowed_bags(),
self._second_flight.max_allowed_bags()
)
def total_price(self, total_bags=0)->int:
'''return the sum of the total price of both flights'''
return (
self._first_flight.total_price(total_bags=total_bags) +
self._second_flight.total_price(total_bags=total_bags)
)
def info_flights(self):
''' return the basic info about the two flights'''
return {'first flight': self._first_flight.info_flight(), 'second flight': self._second_flight.info_flight()}