ashok2216 commited on
Commit
28e6931
·
verified ·
1 Parent(s): 0d141ca

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +43 -42
app.py CHANGED
@@ -298,6 +298,48 @@ Provide a clear and concise answer focusing on the specific information requeste
298
  response += f"- {key.replace('_', ' ').title()}: {value}\n"
299
  return response
300
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
301
  def flight_tracking(flight_view_level, country, local_time_zone, flight_info, airport, color):
302
  # Get cached location data
303
  loc = get_location(country)
@@ -327,49 +369,8 @@ def flight_tracking(flight_view_level, country, local_time_zone, flight_info, ai
327
  (airport_country_loc['Longitude'] >= lon_min) &
328
  (airport_country_loc['Longitude'] <= lon_max)]
329
 
330
- def get_traffic_gdf():
331
- # Get cached flight data
332
- json_dict = fetch_flight_data(lat_min, lat_max, lon_min, lon_max)
333
-
334
- if not json_dict or not json_dict.get('states'):
335
- st.warning("No flight data available for the selected area.")
336
- return None
337
-
338
- try:
339
- unix_timestamp = int(json_dict["time"])
340
- local_timezone = pytz.timezone(local_time_zone)
341
- local_time = datetime.fromtimestamp(unix_timestamp, local_timezone).strftime('%Y-%m-%d %H:%M:%S')
342
-
343
- # Optimize DataFrame creation
344
- state_df = pd.DataFrame(json_dict["states"], columns=columns)
345
- state_df['time'] = local_time
346
-
347
- # Create GeoDataFrame more efficiently
348
- gdf = gpd.GeoDataFrame(
349
- state_df,
350
- geometry=gpd.points_from_xy(state_df.longitude, state_df.latitude),
351
- crs="EPSG:4326"
352
- )
353
-
354
- # Display information
355
- st.title("Live Flight Tracker")
356
- st.subheader('Flight Details', divider='rainbow')
357
- st.write('Location: {0}'.format(loc))
358
- st.write('Current Local Time: {0}-{1}:'.format(local_time, local_time_zone))
359
- st.write("Minimum_latitude is {0} and Maximum_latitude is {1}".format(lat_min, lat_max))
360
- st.write("Minimum_longitude is {0} and Maximum_longitude is {1}".format(lon_min, lon_max))
361
- st.write('Number of Visible Flights: {}'.format(len(json_dict['states'])))
362
- st.write('Plotting the flight: {}'.format(flight_info))
363
- st.subheader('Map Visualization', divider='rainbow')
364
- st.write('****Click ":orange[Update Map]" Button to Refresh the Map****')
365
- return gdf
366
-
367
- except Exception as e:
368
- st.error(f"Error processing flight data: {str(e)}")
369
- return None
370
-
371
  # Get traffic data
372
- geo_df = get_traffic_gdf()
373
  if geo_df is None:
374
  return
375
 
 
298
  response += f"- {key.replace('_', ' ').title()}: {value}\n"
299
  return response
300
 
301
+ @st.cache_data(ttl=60) # Cache for 1 minute
302
+ def get_traffic_gdf(lat_min, lat_max, lon_min, lon_max, local_time_zone, loc, flight_info):
303
+ # Get cached flight data
304
+ json_dict = fetch_flight_data(lat_min, lat_max, lon_min, lon_max)
305
+
306
+ if not json_dict or not json_dict.get('states'):
307
+ st.warning("No flight data available for the selected area.")
308
+ return None
309
+
310
+ try:
311
+ unix_timestamp = int(json_dict["time"])
312
+ local_timezone = pytz.timezone(local_time_zone)
313
+ local_time = datetime.fromtimestamp(unix_timestamp, local_timezone).strftime('%Y-%m-%d %H:%M:%S')
314
+
315
+ # Optimize DataFrame creation
316
+ state_df = pd.DataFrame(json_dict["states"], columns=columns)
317
+ state_df['time'] = local_time
318
+
319
+ # Create GeoDataFrame more efficiently
320
+ gdf = gpd.GeoDataFrame(
321
+ state_df,
322
+ geometry=gpd.points_from_xy(state_df.longitude, state_df.latitude),
323
+ crs="EPSG:4326"
324
+ )
325
+
326
+ # Display information
327
+ st.title("Live Flight Tracker")
328
+ st.subheader('Flight Details', divider='rainbow')
329
+ st.write('Location: {0}'.format(loc))
330
+ st.write('Current Local Time: {0}-{1}:'.format(local_time, local_time_zone))
331
+ st.write("Minimum_latitude is {0} and Maximum_latitude is {1}".format(lat_min, lat_max))
332
+ st.write("Minimum_longitude is {0} and Maximum_longitude is {1}".format(lon_min, lon_max))
333
+ st.write('Number of Visible Flights: {}'.format(len(json_dict['states'])))
334
+ st.write('Plotting the flight: {}'.format(flight_info))
335
+ st.subheader('Map Visualization', divider='rainbow')
336
+ st.write('****Click ":orange[Update Map]" Button to Refresh the Map****')
337
+ return gdf
338
+
339
+ except Exception as e:
340
+ st.error(f"Error processing flight data: {str(e)}")
341
+ return None
342
+
343
  def flight_tracking(flight_view_level, country, local_time_zone, flight_info, airport, color):
344
  # Get cached location data
345
  loc = get_location(country)
 
369
  (airport_country_loc['Longitude'] >= lon_min) &
370
  (airport_country_loc['Longitude'] <= lon_max)]
371
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
372
  # Get traffic data
373
+ geo_df = get_traffic_gdf(lat_min, lat_max, lon_min, lon_max, local_time_zone, loc, flight_info)
374
  if geo_df is None:
375
  return
376