diff --git a/satnogs.py b/satnogs.py index 9b7e98c..c5778db 100644 --- a/satnogs.py +++ b/satnogs.py @@ -11,7 +11,7 @@ from satnogs_api_client.satnogs_api_client import DB_BASE_URL, get_paginated_end from satellite_tle import fetch_tles from skyfield.api import EarthSatellite, utc, load import numpy -#from pympler import muppy, summary + scheduler = BackgroundScheduler() app = Flask(__name__) @@ -25,12 +25,13 @@ Stations = [] StationsByID = {} TLEs = defaultdict(list) Transmitters = defaultdict(dict) +Raw_Transmitters = {} StationsPasses = defaultdict(list) SatDescrip = defaultdict(str) CZMLOnline = [] CZMLTesting = [] CZMLOffline = [] - +TransmitterStats = [] def getFuture(): @@ -50,7 +51,6 @@ def getFuture(): # obs = get_paginated_endpoint("https://network.satnogs.org/api/observations/?end="+End+"&format=json&start="+Start) # for x in obs: # norads[x["id"]] = x["noard_cat_id"] - print("Ended") Observations = defaultdict(list) for x in passes: if x["ground_station"] == None: @@ -127,7 +127,7 @@ def updateTLE(): print('\nTLEs for {} of {} requested satellites found ({} satellites with temporary norad ids skipped).'.format(len(tles), len(satnogs_db_norad_ids), len(temporary_norad_ids))) -@scheduler.scheduled_job('interval', days=1) +@scheduler.scheduled_job('interval', days=0.5) def updateTransmitters(): global Transmitters global SatDescrip @@ -136,13 +136,40 @@ def updateTransmitters(): print("Updating Transmitters") temp = requests.get("https://db.satnogs.org/api/transmitters/").json() for x in temp: + Raw_Transmitters[x["uuid"]] = x Transmitters[x["uuid"]] = [x["description"], [random.randint(0, 255), random.randint(0, 255), random.randint(0, 255), 255]] SatDescrip[x["norad_cat_id"]] = "" #for x in Transmitters.keys(): for x in temp: SatDescrip[x["norad_cat_id"]] += '
'+Transmitters[x["uuid"]][0]+'
' print("Finished Updating Transmitters") + updateTransmitterStats() + +def updateTransmitterStats(): + print("Updating Transmitter Stats") + global TransmitterStats + TransmitterStats = [] + transmitterStats = get_paginated_endpoint("https://network.satnogs.org/api/transmitters/") + satellites = requests.get("https://db.satnogs.org/api/satellites/").json() + sats = {} + for x in satellites: + sats[x["norad_cat_id"]] = x + for x in transmitterStats: + try: + transmitter = Raw_Transmitters[x["uuid"]] + stat = x["stats"] + sat = sats[transmitter["norad_cat_id"]] + stat["transmitter_name"] = transmitter["description"] + stat["sat_name"] = sat["name"] + stat["norad"] = transmitter["norad_cat_id"] + TransmitterStats.append(stat) + except: + pass + TransmitterStats.sort(key=lambda x: x["success_rate"],reverse = True) + print("Finished Updating Transmitter Stats") + + @scheduler.scheduled_job('interval', minutes=15)#hours=1) def updatePasses(): getFuture() @@ -283,103 +310,23 @@ def rotating(): speed = request.args.get('speed', default = '30', type = str) return render_template("rotating.html",url="/czml",speed=speed) -@app.route("/station/") -def index_station(station_id): - return render_template("index.html",url="/czml/"+str(station_id)) - @app.route("/czml") def api_czml(): return json.dumps(CZMLOnline) @app.route("/czmloff") -def api_czml1(): +def api_czmloff(): return json.dumps(CZMLOffline) @app.route("/czmltest") -def api_czml2(): +def api_czmltest(): return json.dumps(CZMLTesting) -@app.route("/czml/") -def api_station(station_id): - czml = [] - doc = {} - doc["id"] = "document" - doc["name"] = "sats" - doc["version"] = "1.0" - doc["clock"] = {} - doc["clock"]["interval"] = "0000-00-00T00:00:00Z/9999-12-31T24:00:00Z" - doc["clock"]["currentTime"] = datetime.utcnow().isoformat() + "Z" - doc["clock"]["step"] = "SYSTEM_CLOCK" - czml.append(doc) +@app.route("/transmitterstats") +def transmitterStats(): + return render_template("transmitterstats.html",stats=TransmitterStats) - for x in Stations: - if x["id"] == station_id: - color = [0, 230, 64, 255] - if x["status"] == "Testing": - color = [248, 148, 6, 255] - if x["status"] == "Offline": - color = [255, 0, 0, 50] - station = {} - station["id"] = str(x["id"]) - station["name"] = x["name"] - station["point"] = {} - station["show"] = True - station["point"]["color"] = {} - station["point"]["color"]["rgba"] = color - station["point"]["outlineColor"] = {} - station["point"]["outlineColor"]["rgba"] = [255, 255, 255, color[3]] - station["point"]["outlineWidth"] = 2.0 - station["position"] = {} - station["point"]["pixelSize"] = 7.0 - station["position"]["cartographicDegrees"] = [x["lng"], x['lat'], x["altitude"]] - station["description"] = "ID: " + str(x["id"]) + "
Total Observations: " - station["description"] += str(x["observations"]) + "
Status: " + x["status"] + "
QTH: " - station["description"] += x["qthlocator"] + "
Description: " + x["description"] - czml.append(station) - break - AliveSats = [] - for y in StationsPasses[station_id]: - sat = {} - sat["id"] = str(y["id"]) - sat["name"] = TLEs[y["norad"]][0] - sat["show"] = True - sat["point"] = {} - sat["point"]["color"] = {} - sat["point"]["color"]["rgba"] = [255, 0, 0, 255] - sat["point"]["pixelSize"] = 8.0 - sat["position"] = {} - sat["position"]["cartographicDegrees"] = [] - sat["description"] = SatDescrip[y["norad"]] - temp = y["start"] - satObj = EarthSatellite(TLEs[y["norad"]][1], TLEs[y["norad"]][2], TLEs[y["norad"]][0]) - time = 0 - sat["position"]["interpolationAlgorithm"] = "LAGRANGE" - sat["position"]["interpolationDegree"] = 5 - sat["position"]["epoch"] = (y["start"].isoformat() + "Z").replace("+00:00", "") - sat["path"] = {"show": {"interval": (y["start"].isoformat()+"Z").replace("+00:00", "") + "/" + ((y["end"]).isoformat() + "Z").replace("+00:00", ""), "boolean": True}, "width": 2, "material": {"solidColor": {"color": {"rgba": [0, 255, 0, 255]}}}, "leadTime": 100000, "trailTime": 1} - - - while temp <= y["end"]: - subpoint = satObj.at(ts.utc(temp)).subpoint() - lat = subpoint.latitude.degrees - lng = subpoint.longitude.degrees - if numpy.isnan(lat): - break - elevation = subpoint.elevation.m - sat["position"]["cartographicDegrees"].extend([time, lng, lat, elevation]) - time += 60 - temp = temp + timedelta(minutes=1) - else: - czml.append(sat) - AliveSats.append(str(y["id"])) - for y in StationsPasses[station_id]: - if str(y["id"]) in AliveSats: - sat = {} - sat["id"] = str(y["id"])+"Link" - sat["polyline"] = {"show": {"interval": (y["start"].isoformat()+"Z").replace("+00:00", "") + "/" + ((y["end"]).isoformat()+"Z").replace("+00:00", ""), "boolean": True}, "width": 2, "material": {"solidColor": {"color": {"rgba": y["transmitter"][1]}}}, "followSurface": False, "positions": {"references": [str(y["id"]) + "#position", str(station_id) + "#position"]}} - czml.append(sat) - return json.dumps(czml) updateStations() diff --git a/templates/transmitterstats.html b/templates/transmitterstats.html new file mode 100644 index 0000000..4430f07 --- /dev/null +++ b/templates/transmitterstats.html @@ -0,0 +1,47 @@ + + + + + + + + + + + + + + + + + + + +{% for x in stats%} + + + + + + + + + + + + +{% endfor %} + +
“NORAD ID”SatelliteTransmitterTotalGoodGood/Total %BadBad/Total %UnknownUnknown/Total %
{{x.norad}}{{x.sat_name}}{{x.transmitter_name}}{{x.total_count}}{{x.good_count}}{{x.success_rate}}%{{x.bad_count}}{{x.bad_rate}}%{{x.unvetted_count}}{{x.unvetted_rate}}%
\ No newline at end of file