def alt_stats(path, numOfDays): xtraExpense = 0 weeks = math.ceil(float(numOfDays / 7)) totalDist = 0 totalPetCost = 600 * weeks totalDiesCost = 700 * weeks totalTrainCost = 2415 * weeks totalTrainTime = 0 totalCarTime = 0 i = 0 data = Data_Manager() for conn in path: start = conn[0] end = conn[1] connect = data.find_connect(start, end) if connect == None: dist = conn[2] dies = diesel(dist) pet = petrol(dist) time = get_time(dist) connect = Connection(conn[0], conn[1], 0, dies, pet, 0, time, dist) totalDist += connect.distance totalPetCost += connect.costByPetrol totalDiesCost += connect.costByDiesel if connect.costByTrain == 0: totalTrainCost += connect.costByPetrol + 115 totalTrainTime += connect.timeByCar totalTrainTime += connect.timeByTrain totalCarTime += connect.timeByCar if(totalPetCost + totalCarTime < totalTrainCost + totalCarTime): if(totalPetCost < totalDiesCost): return totalPetCost, totalCarTime, totalDist else: return totalDiesCost, totalCarTime, totalDist elif(totalDiesCost + totalCarTime < totalTrainCost + totalCarTime): return totalDiesCost, totalCarTime, totalDist else: return totalTrainCost, totalTrainTime, totalDist print("---Alternate atistics comparing different travel methods---") print(" *Costs are based on weekly rates using only car or train,") print(" *When calculating Train, uses price for petrol when train is not availaable") print() print(" By Train: ----") print(str.format(" Cost: ${0:.6}, Time: {1:.4} hours, Distance: {2:.6} km ({3:.6} miles)", totalTrainCost, totalTrainTime / 60, totalDist, totalDist * .621371)) print() print(" By Petrol Car: ----") print(str.format(" Cost: ${0:.6}, Time: {1:.4} hours, Distance: {2:.6} km ({3:.6} miles)", totalPetCost, totalCarTime / 60, totalDist, totalDist * .621371)) print() print(" By Diesel Car: ----") print(str.format(" Cost: ${0:.6}, Time: {1:.4} hours, Distance: {2:.6} km ({3:.6} miles)", totalDiesCost, totalCarTime / 60, totalDist, totalDist * .621371))
def print_results(a): totalDist = 0; totalCost = 0; totalTime = 0; i = 0; data = Data_Manager() print("---------Trip Through Germany - Shortest Path---------") print() print("---------Tracing path based on either Petrol, Diesel or Train per city on the path-------") print("Starting City:", data.city_by_key(a[0][0])) for conn in a: i += 1 start = conn[0] end = conn[1] city = data.city_by_key(start) connect = data.find_connect(start, end) if connect == None: dist = conn[2] dies = diesel(dist) pet = petrol(dist) time = get_time(dist) connect = Connection(conn[0], conn[1], 0, dies, pet, 0, time, dist) dist, type, cost, time = connect.opt_weight() totalDist += dist totalCost += cost totalTime += time print("Stop:", i, "--", city, conn[1]) print(str.format("Distance Traveled: {0:.4} km, by {1}, Travel Cost: ${2:.5}, Time Traveled: {3:.4} minutes", float(dist), type, float(cost), float(time))) print("-----------------------------------------------------------") print() print(" Result Totals for Alternating Methods: ----") print(str.format(" Cost: ${0:.6}, Time: {1:.4} hours, Distance: {2:.6} km ({3:.6} miles)", totalCost, totalTime / 60, totalDist, totalDist * .621371)) print()