Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import datetime
- class Flight:
- def __init__(self, flight_id=None, pilots=None, crew=None, departing_from=None, departure_date_time=None, destination=None, arrival_date_time=None, airplane=None):
- self.__flight_id = flight_id
- self.__pilots = pilots
- self.__crew = crew
- self.__departing_from = departing_from
- self.__departure_date_time = departure_date_time
- self.__destination = destination
- self.__arrival_date_time = arrival_date_time
- self.__airplane = airplane
- def calc_arrival_time(self):
- ''' Calculates the arrival time of the flight'''
- distance = self.__destination.get_distance()
- ###### WARNING HARD CODED SPEED VALUE ######
- time = int(distance) / 900
- ## TO DO, GIVE AIRPLANES SPEEED UNITS ##
- # Changing the time into a datetime object
- self.__departure_date_time = datetime.datetime.strptime(self.__departure_date_time,"%Y-%m-%dT%H:%M")
- self.__arrival_date_time = self.__departure_date_time + datetime.timedelta(hours=time) # calculation arrival time
- return time # retuns how long it takes to fly
- def is_valid(self):
- valid = True
- if self.__pilots and self.__crew:
- if len(self.__pilots) < 2:
- valid = False
- elif len(self.__crew) < 3:
- valid = False
- elif not self.__flight_id:
- valid = False
- elif not self.__departing_from:
- valid = False
- elif not self.__departure_date_time:
- valid = False
- elif not self.__destination:
- valid = False
- elif not self.__arrival_date_time:
- valid = False
- elif not self.__airplane:
- valid = False
- else:
- valid = False
- return valid
- def edit(self, object_type, item):
- if object_type == "Pilot" or object_type == "Crew":
- worked = self.edit_staff(object_type, item)
- return worked
- def edit_options(self):
- '''Used by the ui to know what he can edit'''
- return ["Pilot", "Crew"]
- def edit_staff(self, staff_type, staff):
- ''' Used by the ui to add new staff members to an existing voyage'''
- if staff_type == "Pilot":
- self.__pilots.append(staff)
- else:
- self.__crew.append(staff)
- return True
- def edit_departure(self, new_departure):
- self.__departing_from = new_departure
- def edit_destination(self, new_destination):
- self.__destination = new_destination
- def edit_departure_time(self, new_time):
- '''Takes in a departure time from the user'''
- if len(new_time) == 16:
- if new_time[4] == '-' and new_time[7] == '-' and new_time[10] == ',' and new_time [13] == ':':
- self.__departure_date_time = new_time.replace(',', "T") # creates a time object
- time = self.calc_arrival_time() # gets the time the flight takes
- return (self.__arrival_date_time, time) # returns the time and arrival date
- return False
- def set_departure_time(self, new_time):
- self.__departure_date_time = new_time
- def set_arrival_time(self, time):
- self.__arrival_date_time = time
- def get_type(self):
- return "voyage"
- def get_date(self):
- return self.__departure_date_time
- def get_staff(self):
- return self.__pilots
- def get_destination(self):
- return self.__destination
- def get_search_reference(self):
- return self.__flight_id
- def save(self):
- if self.__pilots:
- pilots_str = ";".join(self.__pilots)
- else:
- pilots_str = None
- if self.__crew:
- crew_str = ";".join(self.__crew)
- else:
- crew_str = None
- validity = self.is_valid()
- return "{},{},{},{},{},{},{},{}".format(self.__flight_id, self.__departing_from.get_airport_id(), self.__destination.get_airport_id(), self.__departure_date_time, \
- self.__arrival_date_time, pilots_str, crew_str, validity)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement