souvik0306 commited on
Commit
59def3e
·
1 Parent(s): b7e906d
Files changed (4) hide show
  1. flight_route_ui.py +67 -0
  2. main.py +5 -0
  3. optimizer.py +1 -1
  4. weather.py +0 -20
flight_route_ui.py ADDED
@@ -0,0 +1,67 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import pandas as pd
3
+ from optimizer import *
4
+ from weather import *
5
+ from flight_distance import * # Assuming this function is defined in your aircraft capabilities module
6
+
7
+ # Load airport data and aircraft data from CSV files
8
+ airport_df = pd.read_csv(r'airport.csv') # Adjust the path to your CSV file
9
+ aircraft_df = pd.read_csv(r'aircraft.csv') # Adjust the path to your CSV file
10
+
11
+ # Create a combined option list with both IATA codes and airport names
12
+ airport_options = [f"{row['IATA']} - {row['Airport_Name']}" for _, row in airport_df.iterrows()]
13
+
14
+ # Ensure the correct column is used for aircraft types
15
+ aircraft_type_column = 'Aircraft' # Adjust if your column name is different
16
+ if aircraft_type_column not in aircraft_df.columns:
17
+ raise ValueError(f"Column '{aircraft_type_column}' not found in aircraft_types.csv. Available columns: {aircraft_df.columns}")
18
+
19
+ aircraft_options = aircraft_df[aircraft_type_column].tolist()
20
+
21
+ # Function to determine if a route can be flown
22
+ def check_route(airport_selections, aircraft_type):
23
+ # Extract IATA codes from the selected options
24
+ airports = [selection.split(" - ")[0] for selection in airport_selections]
25
+
26
+ # Get coordinates for selected airports as a dictionary {IATA: (latitude, longitude)}
27
+ lat_long_dict = get_airport_lat_long(airports) # Ensure this function returns a dictionary in the expected format
28
+
29
+ # Pass only the required details in the expected format for the weather function
30
+ raw_weather = fetch_weather_for_all_routes(airports, lat_long_dict) # This should receive the correct lat_long_dict
31
+
32
+ # Extract route factors (e.g., conditions impacting the route)
33
+ route_factors = extract_route_factors(raw_weather)
34
+
35
+ # Calculate distances between selected airports
36
+ trip_distance = calculate_distances(airports)
37
+
38
+ # Ensure the graph is bidirectional
39
+ for (a, b), dist in list(trip_distance.items()):
40
+ trip_distance[(b, a)] = dist
41
+
42
+ # Find the optimal route
43
+ optimal_route, optimal_distance = find_optimal_route(airports, trip_distance, route_factors)
44
+
45
+ # Check if the aircraft can fly the route without refueling
46
+ result = can_fly_route(aircraft_type, airports)
47
+
48
+ # Convert all dictionary keys to strings for JSON compatibility
49
+ return {
50
+ "Optimal Route": " -> ".join(optimal_route) + f" -> {optimal_route[0]}",
51
+ "Total Adjusted Distance/Cost": str(optimal_distance), # Convert to string if necessary
52
+ "Can Fly Route": str(result) # Convert to string if necessary
53
+ }
54
+
55
+ # Gradio Interface
56
+ with gr.Blocks() as demo:
57
+ gr.Markdown("## Airport Route Feasibility Checker")
58
+ airport_selector = gr.Dropdown(airport_options, multiselect=True, label="Select Airports (IATA - Name)")
59
+ aircraft_selector = gr.Dropdown(aircraft_options, label="Select Aircraft Type")
60
+ check_button = gr.Button("Check Route Feasibility")
61
+
62
+ result_output = gr.JSON(label="Result")
63
+
64
+ check_button.click(fn=check_route, inputs=[airport_selector, aircraft_selector], outputs=result_output)
65
+
66
+ # Launch the Gradio app
67
+ demo.launch()
main.py CHANGED
@@ -29,3 +29,8 @@ optimal_route, optimal_distance = find_optimal_route(airport_identifiers, trip_d
29
  print("Optimal Route:", " -> ".join(optimal_route) + f" -> {optimal_route[0]}")
30
  print("Total Adjusted Distance/Cost:", optimal_distance)
31
 
 
 
 
 
 
 
29
  print("Optimal Route:", " -> ".join(optimal_route) + f" -> {optimal_route[0]}")
30
  print("Total Adjusted Distance/Cost:", optimal_distance)
31
 
32
+ aircraft_type = input("Enter the aircraft type: ")
33
+
34
+ # Check if the aircraft can fly the route without refuel
35
+ result = can_fly_route(aircraft_type, airport_identifiers)
36
+ print(result)
optimizer.py CHANGED
@@ -95,7 +95,7 @@ def find_optimal_route(airports, distances, route_factors):
95
  try:
96
  current_distance = calculate_route_distance(route, distances, route_factors)
97
  if current_distance < min_distance:
98
- min_distance = current_distance
99
  best_route = route
100
  except ValueError as e:
101
  print(e) # Log the error to debug missing segments
 
95
  try:
96
  current_distance = calculate_route_distance(route, distances, route_factors)
97
  if current_distance < min_distance:
98
+ min_distance = round(current_distance,2)
99
  best_route = route
100
  except ValueError as e:
101
  print(e) # Log the error to debug missing segments
weather.py CHANGED
@@ -87,23 +87,3 @@ def fetch_weather_for_all_routes(airport_identifiers, airports):
87
 
88
  return route_factors
89
 
90
- # # Example usage
91
- # airports = {
92
- # 'SIN': (1.3644, 103.9915), # Singapore Changi Airport
93
- # 'LAX': (33.9416, -118.4085), # Los Angeles International Airport
94
- # 'JFK': (40.6413, -73.7781), # John F. Kennedy International Airport
95
- # 'CDG': (49.0097, 2.5479), # Charles de Gaulle Airport
96
- # 'LHR': (51.4700, -0.4543) # London Heathrow Airport
97
- # }
98
-
99
- # airport_identifiers = ['SIN', 'LAX', 'JFK', 'CDG', 'LHR'] # Replace with actual identifiers
100
-
101
- # # Fetch the weather along all possible routes
102
- # route_weather = fetch_weather_for_all_routes(airport_identifiers, airports)
103
-
104
- # # Display the weather data for each route
105
- # for route, factors in route_weather.items():
106
- # print(f"Route: {route}")
107
- # for factor in factors:
108
- # print(f" Segment: {factor['segment']}, Weather: {factor['weather']}, Temperature: {factor['temperature']} °C")
109
- # print()
 
87
 
88
  return route_factors
89