Spaces:
Sleeping
Sleeping
File size: 3,465 Bytes
a7db64a 7b17a2d bb56ab3 7b17a2d a7db64a 7b17a2d a7db64a 7b17a2d a7db64a 7b17a2d a7db64a 7b17a2d a7db64a bb56ab3 34b54e8 a7db64a 7b17a2d a7db64a 7b17a2d a7db64a 7b17a2d a7db64a 7b17a2d a7db64a 7b17a2d a7db64a 7b17a2d a7db64a b7e906d 7b17a2d b7e906d 7b17a2d b7e906d 7b17a2d b7e906d 7b17a2d b7e906d 7b17a2d b7e906d 7b17a2d b7e906d |
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 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
import pandas as pd
from math import radians, sin, cos, sqrt, asin
import time
### Modular Flight Calculation Functions ###
def get_aircraft_details(aircraft_type):
"""
Fetch aircraft details based on the given aircraft type.
"""
csv_file = 'aircraft.csv'
df = pd.read_csv(csv_file)
if aircraft_type not in df['Aircraft'].values:
return f"Aircraft type '{aircraft_type}' not found in the dataset."
aircraft_details = df[df['Aircraft'] == aircraft_type][[
'Range_km', 'Fuel_Consumption_kg/hr', 'Cruising Speed (kts)',
'Speed_kmh', 'MaxFlightTime_hr', 'Max_Fuel_Capacity_kg']]
return aircraft_details.to_dict(orient='records')[0]
def get_airport_lat_long(identifiers):
"""
Get latitude and longitude for a list of airport identifiers (IATA codes).
"""
csv_file = 'airport.csv'
start_time = time.time()
df = pd.read_csv(csv_file)
read_time = time.time() - start_time
print(f"CSV file read in {read_time:.4f} seconds")
df_filtered = df[df['Airport_Name'].isin(identifiers) | df['IATA'].isin(identifiers)]
lat_long_dict = {row['IATA']: (row['Lat'], row['Long']) for _, row in df_filtered.iterrows()}
return lat_long_dict
def haversine_distance(lat1, lon1, lat2, lon2):
"""
Calculate the Haversine distance between two points on Earth (in kilometers).
"""
R = 6371.0 # Earth radius in kilometers
lat1, lon1, lat2, lon2 = map(radians, [lat1, lon1, lat2, lon2])
dlat, dlon = lat2 - lat1, lon2 - lon1
a = sin(dlat / 2)**2 + cos(lat1) * cos(lat2) * sin(dlon / 2)**2
return round(R * 2 * asin(sqrt(a)), 2)
def calculate_distances(airport_identifiers):
"""
Calculate the distance between each pair of airports.
"""
lat_long_dict = get_airport_lat_long(airport_identifiers)
distances = {}
for i in range(len(airport_identifiers)):
for j in range(i + 1, len(airport_identifiers)):
airport1, airport2 = airport_identifiers[i], airport_identifiers[j]
lat1, lon1 = lat_long_dict[airport1]
lat2, lon2 = lat_long_dict[airport2]
distances[(airport1, airport2)] = haversine_distance(lat1, lon1, lat2, lon2)
return distances
def calculate_fuel_and_time_for_segment(segment_distance, aircraft_specs):
"""
Calculate the fuel and time required for a single flight segment.
"""
cruising_speed = aircraft_specs['Speed_kmh']
fuel_burn_rate = aircraft_specs['Fuel_Consumption_kg/hr']
max_fuel_capacity = aircraft_specs['Max_Fuel_Capacity_kg']
reserve_fuel_percentage = 0.05 # 5% reserve fuel
climb_speed, descent_speed = 300, 350
climb_time, descent_time = 15 / 60, 10 / 60 # in hours
climb_distance = climb_speed * climb_time
descent_distance = descent_speed * descent_time
# Calculate cruise distance
cruise_distance = segment_distance - (climb_distance + descent_distance)
cruise_distance = max(0, cruise_distance) # Ensure cruise distance is not negative
# Calculate flight time for each phase
cruise_time = cruise_distance / cruising_speed
total_flight_time = climb_time + cruise_time + descent_time
# Calculate fuel required
fuel_required = total_flight_time * fuel_burn_rate
reserve_fuel = reserve_fuel_percentage * max_fuel_capacity
total_fuel_with_reserve = fuel_required + reserve_fuel
return total_fuel_with_reserve, total_flight_time
|