Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -14,21 +14,59 @@ TAKEOFF_DATA = {
|
|
| 14 |
4000: {-29.855142153032396: 893.021578409569, 30.908216625593553: 2077.7544028370503},
|
| 15 |
5000: {-37.61856103864879: 878.2112159644166, 30.775981246618983: 2307.1707639598485},
|
| 16 |
}
|
| 17 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
MIN_CHART_WEIGHT_LBS = 2050.0
|
| 19 |
|
| 20 |
def _interpolate_1d(x, x_points, y_points):
|
|
|
|
| 21 |
if x <= x_points[0]: return y_points[0]
|
| 22 |
if x >= x_points[-1]: return y_points[-1]
|
| 23 |
for i in range(len(x_points) - 1):
|
| 24 |
if x_points[i] <= x <= x_points[i+1]:
|
| 25 |
x1, x2 = x_points[i], x_points[i+1]
|
| 26 |
y1, y2 = y_points[i], y_points[i+1]
|
|
|
|
| 27 |
return y1 + (y2 - y1) * ((x - x1) / (x2 - x1))
|
| 28 |
return y_points[0]
|
| 29 |
|
| 30 |
def _get_distance_at_temp_and_alt(temp, alt, data):
|
| 31 |
alt_points = sorted(data.keys())
|
|
|
|
| 32 |
alt_low, alt_high = -1, -1
|
| 33 |
if alt <= alt_points[0]: alt_low = alt_high = alt_points[0]
|
| 34 |
elif alt >= alt_points[-1]: alt_low = alt_high = alt_points[-1]
|
|
@@ -37,13 +75,19 @@ def _get_distance_at_temp_and_alt(temp, alt, data):
|
|
| 37 |
if alt_points[i] <= alt <= alt_points[i+1]:
|
| 38 |
alt_low, alt_high = alt_points[i], alt_points[i+1]
|
| 39 |
break
|
|
|
|
|
|
|
| 40 |
temp_points_low = sorted(data[alt_low].keys())
|
| 41 |
dist_points_low = [data[alt_low][t] for t in temp_points_low]
|
| 42 |
dist_at_alt_low = _interpolate_1d(temp, temp_points_low, dist_points_low)
|
|
|
|
| 43 |
if alt_low == alt_high: return dist_at_alt_low
|
|
|
|
|
|
|
| 44 |
temp_points_high = sorted(data[alt_high].keys())
|
| 45 |
dist_points_high = [data[alt_high][t] for t in temp_points_high]
|
| 46 |
dist_at_alt_high = _interpolate_1d(temp, temp_points_high, dist_points_high)
|
|
|
|
| 47 |
return _interpolate_1d(alt, [alt_low, alt_high], [dist_at_alt_low, dist_at_alt_high])
|
| 48 |
|
| 49 |
def _calculate_weight_correction(base_distance, weight_lbs):
|
|
@@ -56,96 +100,122 @@ def _calculate_weight_correction(base_distance, weight_lbs):
|
|
| 56 |
weight_correction_delta = distance_at_actual_weight - distance_at_reference_weight
|
| 57 |
return weight_correction_delta
|
| 58 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
def _calculate_headwind_correction(wind_knots):
|
| 60 |
-
# This function calculates the wind correction delta for HEADWIND.
|
| 61 |
x_points = [0.16104294478526526, 15.04722311914756]
|
| 62 |
y_points = [1139.2960929932183, 847.9173393606702]
|
| 63 |
distance_at_actual_wind = _interpolate_1d(wind_knots, x_points, y_points)
|
| 64 |
distance_at_zero_wind = _interpolate_1d(0, x_points, y_points)
|
| 65 |
-
|
| 66 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 67 |
|
| 68 |
def _calculate_tailwind_correction(wind_knots):
|
| 69 |
-
# This function calculates the wind correction delta for TAILWIND.
|
| 70 |
x_points = [0.16104294478526526, 5.268404907975452]
|
| 71 |
y_points = [1139.2960929932183, 1414.1427187600893]
|
| 72 |
distance_at_actual_wind = _interpolate_1d(wind_knots, x_points, y_points)
|
| 73 |
distance_at_zero_wind = _interpolate_1d(0, x_points, y_points)
|
| 74 |
-
|
| 75 |
-
return wind_correction_delta
|
| 76 |
|
| 77 |
-
def calculate_density_altitude(pressure_altitude_ft, outside_air_temp_c):
|
| 78 |
-
"""
|
| 79 |
-
Calculates density altitude based on pressure altitude and outside air temperature.
|
| 80 |
-
"""
|
| 81 |
-
# Step 1: Calculate the ISA standard temperature at the given pressure altitude.
|
| 82 |
-
isa_temp_c = 15 - (2 * (pressure_altitude_ft / 1000))
|
| 83 |
|
| 84 |
-
|
| 85 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 86 |
|
| 87 |
-
|
|
|
|
|
|
|
| 88 |
|
| 89 |
def calculate_takeoff_roll(indicated_altitude_ft, qnh_hpa, temperature_c, weight_kg, wind_type, wind_speed, safety_factor):
|
| 90 |
-
#
|
| 91 |
-
|
| 92 |
-
# Step 0: Convert aircraft mass from kg to lbs for internal calculations
|
| 93 |
weight_lbs = weight_kg * 2.20462
|
| 94 |
-
|
| 95 |
-
# Step 1: Calculate Pressure Altitude from Indicated Altitude and QNH
|
| 96 |
pressure_altitude = indicated_altitude_ft + ((1013.2 - qnh_hpa) * 27)
|
| 97 |
-
|
| 98 |
-
# Step 2: Calculate Density Altitude
|
| 99 |
density_altitude = calculate_density_altitude(pressure_altitude, temperature_c)
|
| 100 |
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
if wind_type == "Headwind":
|
| 107 |
-
|
| 108 |
elif wind_type == "Tailwind":
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 116 |
|
| 117 |
return (
|
|
|
|
| 118 |
f"{pressure_altitude:.0f} ft",
|
| 119 |
f"{density_altitude:.0f} ft",
|
| 120 |
-
|
| 121 |
-
f"{
|
| 122 |
-
f"{
|
| 123 |
-
f"{
|
| 124 |
-
f"{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 125 |
)
|
| 126 |
|
| 127 |
# --- Custom CSS for Styling the Columns ---
|
| 128 |
-
# This CSS will style the textboxes within the columns that have the specific classes.
|
| 129 |
custom_css = """
|
| 130 |
-
.
|
| 131 |
-
.
|
| 132 |
-
.
|
| 133 |
-
.
|
| 134 |
-
.
|
|
|
|
|
|
|
|
|
|
| 135 |
"""
|
| 136 |
|
| 137 |
# --- Gradio Interface Definition ---
|
| 138 |
with gr.Blocks(theme=gr.themes.Soft(), css=custom_css) as demo:
|
| 139 |
-
gr.Markdown(
|
| 140 |
-
"""
|
| 141 |
-
# PA-28-181 Takeoff Ground Roll Calculator
|
| 142 |
-
Enter the conditions below to calculate the takeoff distance.
|
| 143 |
-
"""
|
| 144 |
-
)
|
| 145 |
|
| 146 |
with gr.Row():
|
| 147 |
# Column 1: Inputs
|
| 148 |
-
with gr.Column(scale=2):
|
| 149 |
altitude = gr.Slider(minimum=0, maximum=8000, value=2000, step=50, label="Indicated Altitude (ft)")
|
| 150 |
qnh = gr.Slider(minimum=950, maximum=1050, value=1013.2, step=0.1, label="QNH (hPa)")
|
| 151 |
temp = gr.Slider(minimum=-40, maximum=40, value=21, step=1, label="Outside Air Temp (°C)")
|
|
@@ -154,24 +224,39 @@ with gr.Blocks(theme=gr.themes.Soft(), css=custom_css) as demo:
|
|
| 154 |
wind_speed = gr.Slider(minimum=0, maximum=20, value=8, step=1, label="Wind Speed (knots)")
|
| 155 |
safety_factor = gr.Slider(minimum=1.0, maximum=2.0, value=1.0, step=0.05, label="Safety Factor")
|
| 156 |
|
| 157 |
-
# Column 2:
|
| 158 |
-
with gr.Column(scale=2, elem_classes="
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
|
|
|
| 162 |
weight_delta_output = gr.Textbox(label="4. Weight Correction Delta", interactive=False)
|
| 163 |
-
dist_after_weight_output = gr.Textbox(label="5.
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
# Column 3:
|
| 167 |
-
with gr.Column(scale=
|
| 168 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 169 |
|
| 170 |
inputs = [altitude, qnh, temp, weight, wind_type, wind_speed, safety_factor]
|
| 171 |
-
outputs = [
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 172 |
|
| 173 |
btn = gr.Button("Calculate", variant="primary")
|
| 174 |
btn.click(fn=calculate_takeoff_roll, inputs=inputs, outputs=outputs)
|
| 175 |
|
| 176 |
-
|
| 177 |
-
demo.launch()
|
|
|
|
| 14 |
4000: {-29.855142153032396: 893.021578409569, 30.908216625593553: 2077.7544028370503},
|
| 15 |
5000: {-37.61856103864879: 878.2112159644166, 30.775981246618983: 2307.1707639598485},
|
| 16 |
}
|
| 17 |
+
|
| 18 |
+
TAKEOFF_DATA_50Ft = {
|
| 19 |
+
1000 : {-5.699053711848606: 1500, 4.250299880047962: 1770.491803278689, 12.581634013061446: 2024.5901639344265, 21.543382646941225: 2319.6721311475417, 29.2123150739704: 2598.3606557377057},
|
| 20 |
+
2000 : {-14.972007464676082:1494.6680885097298,
|
| 21 |
+
-8.914956011730212:1681.9514796054377,
|
| 22 |
+
-0.6291655558517704:1942.5486536923481,
|
| 23 |
+
5.737136763529719:2154.3588376432945,
|
| 24 |
+
12.092775259930704:2382.564649426819,
|
| 25 |
+
28.936283657691277:2985.670487869901},
|
| 26 |
+
3000 : {-23.417755265262592:1480.0053319114895,
|
| 27 |
+
-18.011197014129564:1667.422020794454,
|
| 28 |
+
-12.60463876299653:1854.8387096774186,
|
| 29 |
+
-5.60917088776327:2099.306851506264,
|
| 30 |
+
-0.21860837110104114:2311.3169821380957,
|
| 31 |
+
10.26392961876833:2694.4148227139426,
|
| 32 |
+
21.370301252999198:3118.368435083977,
|
| 33 |
+
28.978938949613436:3420.087976539589},
|
| 34 |
+
4000 : {-35.78245801119701:1490.735803785657,
|
| 35 |
+
-27.155425219941343:1726.6728872300714,
|
| 36 |
+
-21.73287123433751:1889.496134364169,
|
| 37 |
+
-12.828579045587837:2199.1468941615562,
|
| 38 |
+
-3.62036790189282:2541.5222607304713,
|
| 39 |
+
2.0954412156758337:2753.4657424686748,
|
| 40 |
+
10.64782724606772:3104.1722207411353,
|
| 41 |
+
20.122633964276204:3536.6568914956006,
|
| 42 |
+
28.63236470274593:3952.9458810983733},
|
| 43 |
+
5000 : { -37.53132498000533:1679.6187683284456,
|
| 44 |
+
-28.595041322314046:1940.0826446280985,
|
| 45 |
+
-18.11783524393494:2331.378299120234,
|
| 46 |
+
-8.621700879765399:2731.0717142095436,
|
| 47 |
+
1.519594774726741:3138.829645427885,
|
| 48 |
+
12.1940815782458:3726.806185017328,
|
| 49 |
+
20.047987203412433:4151.426286323647,
|
| 50 |
+
25.03332444681419:4486.470274593441},
|
| 51 |
+
}
|
| 52 |
+
REFERENCE_WEIGHT_LBS = 2850.0
|
| 53 |
MIN_CHART_WEIGHT_LBS = 2050.0
|
| 54 |
|
| 55 |
def _interpolate_1d(x, x_points, y_points):
|
| 56 |
+
if not x_points or not y_points: return 0
|
| 57 |
if x <= x_points[0]: return y_points[0]
|
| 58 |
if x >= x_points[-1]: return y_points[-1]
|
| 59 |
for i in range(len(x_points) - 1):
|
| 60 |
if x_points[i] <= x <= x_points[i+1]:
|
| 61 |
x1, x2 = x_points[i], x_points[i+1]
|
| 62 |
y1, y2 = y_points[i], y_points[i+1]
|
| 63 |
+
if (x2 - x1) == 0: return y1
|
| 64 |
return y1 + (y2 - y1) * ((x - x1) / (x2 - x1))
|
| 65 |
return y_points[0]
|
| 66 |
|
| 67 |
def _get_distance_at_temp_and_alt(temp, alt, data):
|
| 68 |
alt_points = sorted(data.keys())
|
| 69 |
+
if not alt_points: return 0
|
| 70 |
alt_low, alt_high = -1, -1
|
| 71 |
if alt <= alt_points[0]: alt_low = alt_high = alt_points[0]
|
| 72 |
elif alt >= alt_points[-1]: alt_low = alt_high = alt_points[-1]
|
|
|
|
| 75 |
if alt_points[i] <= alt <= alt_points[i+1]:
|
| 76 |
alt_low, alt_high = alt_points[i], alt_points[i+1]
|
| 77 |
break
|
| 78 |
+
|
| 79 |
+
if alt_low not in data: return 0
|
| 80 |
temp_points_low = sorted(data[alt_low].keys())
|
| 81 |
dist_points_low = [data[alt_low][t] for t in temp_points_low]
|
| 82 |
dist_at_alt_low = _interpolate_1d(temp, temp_points_low, dist_points_low)
|
| 83 |
+
|
| 84 |
if alt_low == alt_high: return dist_at_alt_low
|
| 85 |
+
|
| 86 |
+
if alt_high not in data: return dist_at_alt_low
|
| 87 |
temp_points_high = sorted(data[alt_high].keys())
|
| 88 |
dist_points_high = [data[alt_high][t] for t in temp_points_high]
|
| 89 |
dist_at_alt_high = _interpolate_1d(temp, temp_points_high, dist_points_high)
|
| 90 |
+
|
| 91 |
return _interpolate_1d(alt, [alt_low, alt_high], [dist_at_alt_low, dist_at_alt_high])
|
| 92 |
|
| 93 |
def _calculate_weight_correction(base_distance, weight_lbs):
|
|
|
|
| 100 |
weight_correction_delta = distance_at_actual_weight - distance_at_reference_weight
|
| 101 |
return weight_correction_delta
|
| 102 |
|
| 103 |
+
|
| 104 |
+
def _calculate_weight_correction_50ft(base_distance, weight_lbs):
|
| 105 |
+
if weight_lbs >= REFERENCE_WEIGHT_LBS:
|
| 106 |
+
return 0.0
|
| 107 |
+
x_points = [2074.7658688865768, 2545.629552549428]
|
| 108 |
+
y_points = [1557.622268470344, 2718.652445369407]
|
| 109 |
+
distance_at_actual_weight = _interpolate_1d(weight_lbs, x_points, y_points)
|
| 110 |
+
distance_at_reference_weight = _interpolate_1d(REFERENCE_WEIGHT_LBS, x_points, y_points)
|
| 111 |
+
weight_correction_delta = distance_at_actual_weight - distance_at_reference_weight
|
| 112 |
+
return weight_correction_delta
|
| 113 |
+
|
| 114 |
+
|
| 115 |
def _calculate_headwind_correction(wind_knots):
|
|
|
|
| 116 |
x_points = [0.16104294478526526, 15.04722311914756]
|
| 117 |
y_points = [1139.2960929932183, 847.9173393606702]
|
| 118 |
distance_at_actual_wind = _interpolate_1d(wind_knots, x_points, y_points)
|
| 119 |
distance_at_zero_wind = _interpolate_1d(0, x_points, y_points)
|
| 120 |
+
return distance_at_actual_wind - distance_at_zero_wind
|
| 121 |
+
|
| 122 |
+
def _calculate_headwind_correction_50ft(wind_knots):
|
| 123 |
+
x_points = [-0.4118297401879545, 14.90049751243781]
|
| 124 |
+
y_points = [2083.6557950985825, 1657.0849456421615]
|
| 125 |
+
distance_at_actual_wind = _interpolate_1d(wind_knots, x_points, y_points)
|
| 126 |
+
distance_at_zero_wind = _interpolate_1d(0, x_points, y_points)
|
| 127 |
+
return distance_at_actual_wind - distance_at_zero_wind
|
| 128 |
+
|
| 129 |
|
| 130 |
def _calculate_tailwind_correction(wind_knots):
|
|
|
|
| 131 |
x_points = [0.16104294478526526, 5.268404907975452]
|
| 132 |
y_points = [1139.2960929932183, 1414.1427187600893]
|
| 133 |
distance_at_actual_wind = _interpolate_1d(wind_knots, x_points, y_points)
|
| 134 |
distance_at_zero_wind = _interpolate_1d(0, x_points, y_points)
|
| 135 |
+
return distance_at_actual_wind - distance_at_zero_wind
|
|
|
|
| 136 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 137 |
|
| 138 |
+
def _calculate_tailwind_correction_50ft(wind_knots):
|
| 139 |
+
x_points = [-0.10779436152570554, 4.483139856274192]
|
| 140 |
+
y_points = [1681.684171733924, 2061.912658927585]
|
| 141 |
+
distance_at_actual_wind = _interpolate_1d(wind_knots, x_points, y_points)
|
| 142 |
+
distance_at_zero_wind = _interpolate_1d(0, x_points, y_points)
|
| 143 |
+
return distance_at_actual_wind - distance_at_zero_wind
|
| 144 |
|
| 145 |
+
def calculate_density_altitude(pressure_altitude_ft, outside_air_temp_c):
|
| 146 |
+
isa_temp_c = 15 - (2 * (pressure_altitude_ft / 1000))
|
| 147 |
+
return pressure_altitude_ft + (120 * (outside_air_temp_c - isa_temp_c))
|
| 148 |
|
| 149 |
def calculate_takeoff_roll(indicated_altitude_ft, qnh_hpa, temperature_c, weight_kg, wind_type, wind_speed, safety_factor):
|
| 150 |
+
# Common calculations
|
|
|
|
|
|
|
| 151 |
weight_lbs = weight_kg * 2.20462
|
|
|
|
|
|
|
| 152 |
pressure_altitude = indicated_altitude_ft + ((1013.2 - qnh_hpa) * 27)
|
|
|
|
|
|
|
| 153 |
density_altitude = calculate_density_altitude(pressure_altitude, temperature_c)
|
| 154 |
|
| 155 |
+
# --- 0ft (Ground Roll) Calculation Path ---
|
| 156 |
+
base_distance_0ft = _get_distance_at_temp_and_alt(temperature_c, pressure_altitude, TAKEOFF_DATA)
|
| 157 |
+
weight_delta_0ft = _calculate_weight_correction(base_distance_0ft, weight_lbs)
|
| 158 |
+
distance_after_weight_0ft = base_distance_0ft + weight_delta_0ft
|
| 159 |
+
wind_delta_0ft = 0.0
|
| 160 |
if wind_type == "Headwind":
|
| 161 |
+
wind_delta_0ft = _calculate_headwind_correction(wind_speed)
|
| 162 |
elif wind_type == "Tailwind":
|
| 163 |
+
wind_delta_0ft = _calculate_tailwind_correction(wind_speed)
|
| 164 |
+
distance_after_wind_0ft = distance_after_weight_0ft + wind_delta_0ft
|
| 165 |
+
final_distance_ft_0ft = distance_after_wind_0ft * safety_factor
|
| 166 |
+
final_distance_m_0ft = final_distance_ft_0ft * 0.3048
|
| 167 |
+
|
| 168 |
+
# --- 50ft Obstacle Calculation Path ---
|
| 169 |
+
base_distance_50ft = _get_distance_at_temp_and_alt(temperature_c, pressure_altitude, TAKEOFF_DATA_50Ft)
|
| 170 |
+
weight_delta_50ft = _calculate_weight_correction_50ft(base_distance_50ft, weight_lbs)
|
| 171 |
+
distance_after_weight_50ft = base_distance_50ft + weight_delta_50ft
|
| 172 |
+
wind_delta_50ft = 0.0
|
| 173 |
+
if wind_type == "Headwind":
|
| 174 |
+
wind_delta_50ft = _calculate_headwind_correction_50ft(wind_speed)
|
| 175 |
+
elif wind_type == "Tailwind":
|
| 176 |
+
wind_delta_50ft = _calculate_tailwind_correction_50ft(wind_speed)
|
| 177 |
+
distance_after_wind_50ft = distance_after_weight_50ft + wind_delta_50ft
|
| 178 |
+
final_distance_ft_50ft = distance_after_wind_50ft * safety_factor
|
| 179 |
+
final_distance_m_50ft = final_distance_ft_50ft * 0.3048
|
| 180 |
|
| 181 |
return (
|
| 182 |
+
# Common outputs for environmental conditions
|
| 183 |
f"{pressure_altitude:.0f} ft",
|
| 184 |
f"{density_altitude:.0f} ft",
|
| 185 |
+
# 0ft outputs for Column 2
|
| 186 |
+
f"{base_distance_0ft:.1f} ft",
|
| 187 |
+
f"{weight_delta_0ft:.1f} ft",
|
| 188 |
+
f"{distance_after_weight_0ft:.1f} ft",
|
| 189 |
+
f"{wind_delta_0ft:.1f} ft",
|
| 190 |
+
# 50ft outputs for Column 3
|
| 191 |
+
f"{base_distance_50ft:.1f} ft",
|
| 192 |
+
f"{weight_delta_50ft:.1f} ft",
|
| 193 |
+
f"{distance_after_weight_50ft:.1f} ft",
|
| 194 |
+
f"{wind_delta_50ft:.1f} ft",
|
| 195 |
+
# Final outputs for Column 4
|
| 196 |
+
f"{final_distance_ft_0ft:.0f} ft\n{final_distance_m_0ft:.0f} m",
|
| 197 |
+
f"{final_distance_ft_50ft:.0f} ft\n{final_distance_m_50ft:.0f} m"
|
| 198 |
)
|
| 199 |
|
| 200 |
# --- Custom CSS for Styling the Columns ---
|
|
|
|
| 201 |
custom_css = """
|
| 202 |
+
.input-column .gradio-slider label > span, .input-column .gradio-radio label > span { color: #1E8449 !important; font-weight: bold !important; }
|
| 203 |
+
.comp-0ft-column .gradio-textbox { background-color: #FEF9E7 !important; border-color: #F39C12 !important; }
|
| 204 |
+
.comp-0ft-column .gradio-textbox > label > span { color: #B9770E !important; }
|
| 205 |
+
.comp-50ft-column .gradio-textbox { background-color: #FADBD8 !important; border-color: #E74C3C !important; }
|
| 206 |
+
.comp-50ft-column .gradio-textbox > label > span { color: #C0392B !important; }
|
| 207 |
+
.output-column .gradio-textbox { background-color: #EBF5FB !important; border-color: #3498DB !important; }
|
| 208 |
+
.output-column .gradio-textbox > label > span { color: #2980B9 !important; }
|
| 209 |
+
.output-column textarea { font-size: 1.2em !important; font-weight: bold !important; text-align: center !important; }
|
| 210 |
"""
|
| 211 |
|
| 212 |
# --- Gradio Interface Definition ---
|
| 213 |
with gr.Blocks(theme=gr.themes.Soft(), css=custom_css) as demo:
|
| 214 |
+
gr.Markdown("# PA-28-181 Takeoff Performance Calculator")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 215 |
|
| 216 |
with gr.Row():
|
| 217 |
# Column 1: Inputs
|
| 218 |
+
with gr.Column(scale=2, elem_classes="input-column"):
|
| 219 |
altitude = gr.Slider(minimum=0, maximum=8000, value=2000, step=50, label="Indicated Altitude (ft)")
|
| 220 |
qnh = gr.Slider(minimum=950, maximum=1050, value=1013.2, step=0.1, label="QNH (hPa)")
|
| 221 |
temp = gr.Slider(minimum=-40, maximum=40, value=21, step=1, label="Outside Air Temp (°C)")
|
|
|
|
| 224 |
wind_speed = gr.Slider(minimum=0, maximum=20, value=8, step=1, label="Wind Speed (knots)")
|
| 225 |
safety_factor = gr.Slider(minimum=1.0, maximum=2.0, value=1.0, step=0.05, label="Safety Factor")
|
| 226 |
|
| 227 |
+
# Column 2: 0ft Computations
|
| 228 |
+
with gr.Column(scale=2, elem_classes="comp-0ft-column"):
|
| 229 |
+
gr.Markdown("### Ground Roll (0ft) Computations")
|
| 230 |
+
pressure_alt_output = gr.Textbox(label="1. Pressure Altitude", interactive=False)
|
| 231 |
+
density_alt_output = gr.Textbox(label="2. Density Altitude", interactive=False)
|
| 232 |
+
base_dist_output = gr.Textbox(label="3. Base Distance", interactive=False)
|
| 233 |
weight_delta_output = gr.Textbox(label="4. Weight Correction Delta", interactive=False)
|
| 234 |
+
dist_after_weight_output = gr.Textbox(label="5. Dist. After Weight Adj.", interactive=False)
|
| 235 |
+
wind_delta_output_0ft = gr.Textbox(label="6. Wind Correction Delta", interactive=False)
|
| 236 |
+
|
| 237 |
+
# Column 3: 50ft Computations
|
| 238 |
+
with gr.Column(scale=2, elem_classes="comp-50ft-column"):
|
| 239 |
+
gr.Markdown("### 50ft Obstacle Computations")
|
| 240 |
+
base_dist_50ft_output = gr.Textbox(label="3. Base Distance", interactive=False)
|
| 241 |
+
weight_delta_50ft_output = gr.Textbox(label="4. Weight Correction Delta", interactive=False)
|
| 242 |
+
dist_after_weight_50ft_output = gr.Textbox(label="5. Dist. After Weight Adj.", interactive=False)
|
| 243 |
+
wind_delta_output_50ft = gr.Textbox(label="6. Wind Correction Delta", interactive=False)
|
| 244 |
+
|
| 245 |
+
# Column 4: Final Output
|
| 246 |
+
with gr.Column(scale=1, elem_classes="output-column"):
|
| 247 |
+
gr.Markdown("### Final Distances")
|
| 248 |
+
output_distance_0ft = gr.Textbox(label="Ground Roll", interactive=False, lines=2)
|
| 249 |
+
output_distance_50ft = gr.Textbox(label="To Clear 50ft", interactive=False, lines=2)
|
| 250 |
|
| 251 |
inputs = [altitude, qnh, temp, weight, wind_type, wind_speed, safety_factor]
|
| 252 |
+
outputs = [
|
| 253 |
+
pressure_alt_output, density_alt_output,
|
| 254 |
+
base_dist_output, weight_delta_output, dist_after_weight_output, wind_delta_output_0ft,
|
| 255 |
+
base_dist_50ft_output, weight_delta_50ft_output, dist_after_weight_50ft_output, wind_delta_output_50ft,
|
| 256 |
+
output_distance_0ft, output_distance_50ft
|
| 257 |
+
]
|
| 258 |
|
| 259 |
btn = gr.Button("Calculate", variant="primary")
|
| 260 |
btn.click(fn=calculate_takeoff_roll, inputs=inputs, outputs=outputs)
|
| 261 |
|
| 262 |
+
demo.launch()
|
|
|