Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,17 +1,83 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import folium
|
| 3 |
from folium import plugins
|
|
|
|
| 4 |
import pandas as pd
|
| 5 |
from datetime import datetime
|
| 6 |
import time
|
| 7 |
import numpy as np
|
| 8 |
import plotly.graph_objects as go
|
| 9 |
from plotly.subplots import make_subplots
|
| 10 |
-
from opensky_api import OpenSkyApi # OpenSky API 클래스 import
|
| 11 |
|
| 12 |
# OpenSky API 인증 정보
|
| 13 |
USERNAME = "seawolf2357"
|
| 14 |
PASSWORD = "Time2175!@"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
api = OpenSkyApi(USERNAME, PASSWORD)
|
| 16 |
|
| 17 |
def get_states(bounds=None, max_retries=3):
|
|
@@ -19,25 +85,25 @@ def get_states(bounds=None, max_retries=3):
|
|
| 19 |
for attempt in range(max_retries):
|
| 20 |
try:
|
| 21 |
if bounds:
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
bounds
|
| 25 |
-
bounds
|
| 26 |
-
bounds
|
| 27 |
-
|
| 28 |
-
)
|
| 29 |
else:
|
| 30 |
states = api.get_states()
|
| 31 |
|
| 32 |
-
if states:
|
| 33 |
return {'states': states.states}
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
|
| 42 |
except Exception as e:
|
| 43 |
print(f"Error fetching data: {e}")
|
|
@@ -47,6 +113,8 @@ def get_states(bounds=None, max_retries=3):
|
|
| 47 |
return None
|
| 48 |
return None
|
| 49 |
|
|
|
|
|
|
|
| 50 |
def create_monitoring_dashboard(states):
|
| 51 |
"""Create monitoring dashboard using Plotly"""
|
| 52 |
if not states:
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import folium
|
| 3 |
from folium import plugins
|
| 4 |
+
import requests
|
| 5 |
import pandas as pd
|
| 6 |
from datetime import datetime
|
| 7 |
import time
|
| 8 |
import numpy as np
|
| 9 |
import plotly.graph_objects as go
|
| 10 |
from plotly.subplots import make_subplots
|
|
|
|
| 11 |
|
| 12 |
# OpenSky API 인증 정보
|
| 13 |
USERNAME = "seawolf2357"
|
| 14 |
PASSWORD = "Time2175!@"
|
| 15 |
+
|
| 16 |
+
class OpenSkyApi:
|
| 17 |
+
def __init__(self, username=None, password=None):
|
| 18 |
+
self.auth = (username, password) if username and password else None
|
| 19 |
+
self.base_url = "https://opensky-network.org/api"
|
| 20 |
+
|
| 21 |
+
def get_states(self, time_secs=0, icao24=None, bbox=None):
|
| 22 |
+
"""Retrieve state vectors for a given time."""
|
| 23 |
+
params = {"time": int(time_secs) if time_secs else int(time.time())}
|
| 24 |
+
|
| 25 |
+
if icao24:
|
| 26 |
+
params["icao24"] = icao24
|
| 27 |
+
if bbox:
|
| 28 |
+
params.update({
|
| 29 |
+
"lamin": bbox[0],
|
| 30 |
+
"lamax": bbox[1],
|
| 31 |
+
"lomin": bbox[2],
|
| 32 |
+
"lomax": bbox[3]
|
| 33 |
+
})
|
| 34 |
+
|
| 35 |
+
try:
|
| 36 |
+
response = requests.get(
|
| 37 |
+
f"{self.base_url}/states/all",
|
| 38 |
+
params=params,
|
| 39 |
+
auth=self.auth,
|
| 40 |
+
timeout=15
|
| 41 |
+
)
|
| 42 |
+
if response.status_code == 200:
|
| 43 |
+
return StateVector(response.json())
|
| 44 |
+
else:
|
| 45 |
+
print(f"Error {response.status_code}: {response.text}")
|
| 46 |
+
return None
|
| 47 |
+
except Exception as e:
|
| 48 |
+
print(f"Error fetching data: {e}")
|
| 49 |
+
return None
|
| 50 |
+
|
| 51 |
+
class StateVector:
|
| 52 |
+
def __init__(self, states_json):
|
| 53 |
+
self.time = states_json.get('time', 0)
|
| 54 |
+
self.states = []
|
| 55 |
+
|
| 56 |
+
if states_json.get('states'):
|
| 57 |
+
for state in states_json['states']:
|
| 58 |
+
self.states.append(State(state))
|
| 59 |
+
|
| 60 |
+
class State:
|
| 61 |
+
def __init__(self, state_array):
|
| 62 |
+
self.icao24 = state_array[0]
|
| 63 |
+
self.callsign = state_array[1]
|
| 64 |
+
self.origin_country = state_array[2]
|
| 65 |
+
self.time_position = state_array[3]
|
| 66 |
+
self.last_contact = state_array[4]
|
| 67 |
+
self.longitude = state_array[5]
|
| 68 |
+
self.latitude = state_array[6]
|
| 69 |
+
self.geo_altitude = state_array[7]
|
| 70 |
+
self.on_ground = state_array[8]
|
| 71 |
+
self.velocity = state_array[9]
|
| 72 |
+
self.true_track = state_array[10]
|
| 73 |
+
self.vertical_rate = state_array[11]
|
| 74 |
+
self.sensors = state_array[12]
|
| 75 |
+
self.baro_altitude = state_array[13]
|
| 76 |
+
self.squawk = state_array[14]
|
| 77 |
+
self.spi = state_array[15]
|
| 78 |
+
self.position_source = state_array[16] if len(state_array) > 16 else None
|
| 79 |
+
|
| 80 |
+
# OpenSky API 인스턴스 생성
|
| 81 |
api = OpenSkyApi(USERNAME, PASSWORD)
|
| 82 |
|
| 83 |
def get_states(bounds=None, max_retries=3):
|
|
|
|
| 85 |
for attempt in range(max_retries):
|
| 86 |
try:
|
| 87 |
if bounds:
|
| 88 |
+
bbox = (
|
| 89 |
+
bounds['lamin'],
|
| 90 |
+
bounds['lamax'],
|
| 91 |
+
bounds['lomin'],
|
| 92 |
+
bounds['lomax']
|
| 93 |
+
)
|
| 94 |
+
states = api.get_states(bbox=bbox)
|
| 95 |
else:
|
| 96 |
states = api.get_states()
|
| 97 |
|
| 98 |
+
if states and states.states:
|
| 99 |
return {'states': states.states}
|
| 100 |
+
|
| 101 |
+
if attempt < max_retries - 1:
|
| 102 |
+
wait_time = min(2 ** attempt, 60)
|
| 103 |
+
print(f"Retrying in {wait_time} seconds...")
|
| 104 |
+
time.sleep(wait_time)
|
| 105 |
+
continue
|
| 106 |
+
return None
|
| 107 |
|
| 108 |
except Exception as e:
|
| 109 |
print(f"Error fetching data: {e}")
|
|
|
|
| 113 |
return None
|
| 114 |
return None
|
| 115 |
|
| 116 |
+
|
| 117 |
+
|
| 118 |
def create_monitoring_dashboard(states):
|
| 119 |
"""Create monitoring dashboard using Plotly"""
|
| 120 |
if not states:
|