1
0
Fork 0

Upload from dying server

master
root 2019-10-31 11:33:14 -05:00
parent 7b1366ad37
commit bd0b8c411f
2 changed files with 83 additions and 89 deletions

View File

@ -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"]] += '<div class="trans" style="background-color:#'+str("%02x" % Transmitters[x["uuid"]][1][0])+str("%02x" % Transmitters[x["uuid"]][1][1])+str("%02x" % Transmitters[x["uuid"]][1][2])+'";>'+Transmitters[x["uuid"]][0]+'</div>'
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/<int:station_id>")
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/<int:station_id>")
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"] = "<b>ID: " + str(x["id"]) + "</b><br><b>Total Observations: "
station["description"] += str(x["observations"]) + "</b><br><b>Status: " + x["status"] + "</b><br><b>QTH: "
station["description"] += x["qthlocator"] + "</b><br></b>Description: </b>" + 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()

View File

@ -0,0 +1,47 @@
<style>
table {
border-collapse: collapse;
width: 100%;
}
th, td {
text-align: center;
padding: 8px;
}
tr:nth-child(even) {background-color: #f2f2f2;}
</style>
<table>
<thead>
<tr>
<th>“NORAD ID”</th>
<th>Satellite</th>
<th>Transmitter</th>
<th>Total</th>
<th>Good</th>
<th>Good/Total %</th>
<th>Bad</th>
<th>Bad/Total %</th>
<th>Unknown</th>
<th>Unknown/Total %</th>
</tr>
</thead>
<tbody>
{% for x in stats%}
<tr>
<td>{{x.norad}}</td>
<td>{{x.sat_name}}</td>
<td>{{x.transmitter_name}}</td>
<td>{{x.total_count}}</td>
<td>{{x.good_count}}</td>
<td>{{x.success_rate}}%</td>
<td>{{x.bad_count}}</td>
<td>{{x.bad_rate}}%</td>
<td>{{x.unvetted_count}}</td>
<td>{{x.unvetted_rate}}%</td>
</tr>
{% endfor %}
</tbody>
</table>