def total_journey_time(): t = Train("Express One", 50, 100) c1 = City("City 1", 0, 3, 300) j = Journey(t, [c1], 200) print(j.total_journey_time()) #,300) t = Train("Express One", 50, 10) c1 = City("City 1", 0, 3, 300) c2 = City("City 2", 0, 3003, 300) j = Journey(t, [c1, c2], 200) print(j.total_journey_time()) #,900)
def check_timetable(timetables: dict, last_check: int) -> int: file_name = f"tt-{NAME}" try: stat_info = os.stat(file_name) if stat_info.st_mtime > last_check: last_check = int(time.time()) # Clear all the old entries timetables.clear() with open(file_name, "r") as in_file: # We are not interested in the header info lines = in_file.readlines()[1:] for line in lines: line = line.strip("\n") info = line.split(",") journey = Journey(line, info[-1], info[0], info[-2]) if journey.destination not in timetables.keys(): timetables[journey.destination] = [] timetables[journey.destination].append(journey) except FileNotFoundError: print(f"{file_name} for node {NAME} not found, exiting") sys.exit(0) return last_check
def city_arrival_time(): #t = Train("Express One", 50, 100) #c1 = City("City 1",0,3,300) #j = Journey(t,[c1],200) #print(j.city_arrival_time(c1)) # 200 #t = Train("Express One", 50, 10) #c1 = City("City 1",0,3,300) #c2 = City("City 2",0,3003,300) #j = Journey(t,[c1,c2],200) #print(j.city_arrival_time(c2)) # 800 #t = Train("Express One", 50, 10) #c1 = City("City 1",100,3,120) #c2 = City("City 2",78,300,300) #j = Journey(t,[c1,c2],1000) #print(j.city_arrival_time(c1)) #,1000 ##print(j.city_arrival_time(c2)) # 1149 t = Train("Express One", 50, 10) c1 = City("City 1", 100, 3, 120) c2 = City("City 2", 78, 300, 300) c3 = City("City 3", 50, 100, 240) j = Journey(t, [c1, c2, c3], 1000) print(j.city_arrival_time(c3)) # 1469
def CityInJourney(): t = Train("Express One", 50, 100) c1 = City("City 1", 5, 10, 600) cities = [c1, City("City 2", 2, 3, 900), City("City 3", 0, 0, 300)] j = Journey(t, cities, 200) r = j.city_in_journey(c1) print(r) print(j.city_in_journey("City 1"))
def AddDest(): t = Train("Express One", 50, 100) c1 = City("City 1", 5, 10, 600) c2 = City("City 2", 2, 3, 900) j = Journey(t, [c1, c2], 200) print(j) ct = City("City 3", 8, 4, 440) j.add_destination(ct) print(j)
def TotalJourneyDistance(): #t = Train("Express One", 50, 100) #c1 = City("City 1",0,3,300) #j = Journey(t,[c1],200) #print(j.total_journey_distance()) # 0 t = Train("Express One", 50, 100) c1 = City("City 1", 0, 3, 300) c2 = City("City 2", 0, 8, 300) j = Journey(t, [c1, c2], 200) print(j.total_journey_distance()) # 5
def JourneyTestSTR(): t = Train("Express One", 50, 100) c1 = City("City 1", 5, 10, 600) c2 = City("City 2", 2, 3, 900) c3 = City("City 3", 0, 0, 300) c4 = City("City 4", 12, 4, 1000) j = Journey(t, [c1, c2, c3, c4], 200) #MyTrain = Train("Norman", 324, 65) #(name, max passengers, fps) #Journey1 = Journey(MyTrain, ["aaa", "bbb", "ccc", "ddd", "eee", "fff"], 4060) print(j)
def NewJourney(): #MyTrain = Train("Norman", 100, 22) #(name, max passengers, fps) #Journey1 = Journey(MyTrain, ["xxx", "yyy"], 4000) #print(Journey1) #MyTrain1 = "" #Journey2 = Journey(MyTrain1, ["aaa", "bbb"], 4000) #print(Journey2) t = Train("Express One", 50, 100) j = Journey(t, [], 0) print(j.__str__())
def CheckJourney(): #t = Train("Express One", 50, 100) #c1 = City("City 1",5,10,600) #c2 = City("City 2",2,3,900) #c3 = City("City 3", 0,0,300) #c4 = City("City 4", 12,4,1000) #c5 = City("City 5", 12,4,1000) #j = Journey(t,[c1,c2,c3,c4],200) #print(j.check_journey_includes(c5,c2)) t = Train("Express One", 50, 100) c1 = City("City 1", 5, 10, 600) c2 = City("City 2", 2, 3, 900) c3 = City("City 3", 0, 0, 300) c4 = City("City 4", 12, 4, 1000) j = Journey(t, [c1, c2, c3, c4], 200) print(j.check_journey_includes(c3, c2))
def get_journeys(departure_point, arrival_point, departure_date, region): mode = 'journeys?' starting_from = 'from=' + departure_point going_to = 'to=' + arrival_point at_time = 'datetime=' + departure_date url_final = ROOT_URL + region + mode + starting_from + '&' + going_to + '&' + at_time data = requests.get( url=url_final, auth=(get_tokens('navitia'), '')) #url = recherche vers navitia et auth = notre username/pwd print(url_final) data = data.json()["journeys"][ 0] #on stock dans la variable data la partie du json intéréssante pour la suite du processus #je crée un objet journey et je lui donne les données json journey = Journey( data["sections"][1]["from"] ["name"], #je récupère le nom du point de départ data["sections"][1]["to"] ["name"], #je récupère le nom du point d'arrivée data[ "requested_date_time"], #je récupère la date demandé par l'utilisateur data["departure_date_time"], #je récupère la date de départ du trajet data["arrival_date_time"], #je récupère la date d arrivée du trajet data["duration"], #je récupère le temps du trajet data["sections"][1]["display_informations"] ["physical_mode"], #je récupère le type de transport en commun data["sections"][1]["display_informations"] ["name"], #je récupère le nom du trajet data["sections"][1]["display_informations"] ["network"], #je récupère le nom du réseau de transport data["sections"][1]["display_informations"] ["trip_short_name"], #je récupère l'ID du trajet data["sections"][1]["stop_date_times"] ) #je récupère le tableau de tout les arrets du trajet return journey
def AllPassengersAccommodated(): #t = Train("Express One", 50, 100) #c1 = City("City 1",0,3,300) #j = Journey(t,[c1],200) #print(j.all_passengers_accommodated([5],[5])) # False #no passenger to be unloaded #t = Train("Express One", 50, 100) #c1 = City("City 1",0,3,300) #j = Journey(t,[c1],200) #print(j.all_passengers_accommodated([0],[100])) # False) #too many to load #t = Train("Express One", 50, 10) #c1 = City("City 1",0,3,300) #j = Journey(t,[c1],200) #print(j.all_passengers_accommodated([0],[30])) # ,True) t = Train("Express One", 50, 10) c1 = City("City 1", 0, 3, 300) c2 = City("City 2", 78, 300, 300) j = Journey(t, [c1, c2], 200) print(j.all_passengers_accommodated([0, 40], [30, 10])) #,False)
def aa_test(): MyTrain = Train("Chuggington", 100, 22) #(name, max passengers, fps) MyCity1 = City("Philly", 9, 20, 50) name = MyTrain.name MyTrain.num_passengers = 60 #LoadPassengers = MyTrain.load_passengers(5) #TimeTravel = MyTrain.time_to_travel(2200) UnloadPassengers = MyTrain.unload_passengers(50) #print(name) #print(MyTrain) # print(LoadPassengers) #print(TimeTravel) #print(TrainCapacityException(5,"full")) #print(TrainCapacityException(15,"empty")) #print(UnloadPassengers) #print(MyCity.distance_to_city("fairfax")) #MyCity2 = City("Vegas", 9, 22, 100) #print(MyCity1.__eq__(MyCity2)) #MyTrain1 = "" Journey1 = Journey(MyTrain1, "gfagfgagf", 4000)
def __init__(self, builder): self.builder = builder Journey(builder.startCharacterJourney())