Make backend better for use with web workers
parent
f23e70e497
commit
f2df83c42e
21
satnogs.py
21
satnogs.py
|
@ -135,35 +135,32 @@ def updateTLE():
|
||||||
def map_view():
|
def map_view():
|
||||||
return render_template("map.html")
|
return render_template("map.html")
|
||||||
|
|
||||||
@app.route('/api/activestations')
|
@app.route('/api/active_stations')
|
||||||
def api_active_stations():
|
def api_active_stations():
|
||||||
sations = []
|
sations = []
|
||||||
for x in Stations:
|
for x in Stations:
|
||||||
sations.append([x["name"],x["lat"],x["lng"]])
|
sations.append([x["name"],x["lat"],x["lng"]])
|
||||||
return json.dumps(Stations)
|
return json.dumps(Stations)
|
||||||
|
|
||||||
@app.route('/api/occuringobservations')
|
@app.route('/api/stations_from_sat/<int:norad>')
|
||||||
def api_occuring_observations():
|
def api_occuring_observations(norad):
|
||||||
obs = []
|
obs = []
|
||||||
for x in Passes:
|
for x in Passes:
|
||||||
obs.append(x.id)
|
if x.norad == norad:
|
||||||
|
obs.append(x.ground_station)
|
||||||
|
|
||||||
return json.dumps(obs)
|
return json.dumps(obs)
|
||||||
|
|
||||||
@app.route('/api/occuringsats')
|
@app.route('/api/occuring_sats')
|
||||||
def api_occuring_sats():
|
def api_occuring_sats():
|
||||||
obs = {}
|
|
||||||
tle = {}
|
tle = {}
|
||||||
for x in Passes:
|
for x in Passes:
|
||||||
if x.satellite['norad_cat_id'] not in TLEs.keys():
|
if x.satellite['norad_cat_id'] not in TLEs.keys():
|
||||||
q = fetch_tle_of_observation(x.id)
|
q = fetch_tle_of_observation(x.id)
|
||||||
TLEs[ x.norad ] = [str(x.satellite["name"]),str(q[0]),str(q[1])]
|
TLEs[ x.norad ] = [str(x.satellite["name"]),str(q[0]),str(q[1])]
|
||||||
tle[x.norad] = TLEs[x.norad]
|
tle[x.norad] = TLEs[x.norad]
|
||||||
if not x.norad in obs.keys():
|
|
||||||
obs[x.norad] = []
|
return json.dumps(tle)
|
||||||
obs[x.norad].append({"ground_station":x.ground_station,"start":x.start.isoformat(),"end":x.end.isoformat()})
|
|
||||||
|
|
||||||
|
|
||||||
return json.dumps([obs,tle])
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,16 @@
|
||||||
|
importScripts("https://bundle.run/satellite.js@3.0.0")
|
||||||
|
|
||||||
|
norad = 0
|
||||||
|
passes = []
|
||||||
|
TLE = []
|
||||||
|
|
||||||
|
onmessage = function(e) {
|
||||||
|
if(e[0] == 1){
|
||||||
|
norad = e[1]
|
||||||
|
TLE = e[2]
|
||||||
|
passes = e[3]
|
||||||
|
}
|
||||||
|
var workerResult = 'Result: ' + (e.data[0] * e.data[1]);
|
||||||
|
console.log('Posting message back to main script');
|
||||||
|
postMessage(workerResult);
|
||||||
|
}
|
|
@ -7,8 +7,7 @@
|
||||||
crossorigin=""></script>
|
crossorigin=""></script>
|
||||||
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
|
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
|
||||||
<script src=" https://unpkg.com/@joergdietrich/leaflet.terminator@1.0.0/L.Terminator.js"></script>
|
<script src=" https://unpkg.com/@joergdietrich/leaflet.terminator@1.0.0/L.Terminator.js"></script>
|
||||||
<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
|
|
||||||
<script src="https://bundle.run/satellite.js@3.0.0"></script>
|
|
||||||
|
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
|
@ -74,6 +73,40 @@ var active_station = L.icon({
|
||||||
}).addTo(mymap);
|
}).addTo(mymap);
|
||||||
|
|
||||||
|
|
||||||
|
function UpdateMap(e) {
|
||||||
|
var satPos = e[0]
|
||||||
|
var links = e[1]
|
||||||
|
}
|
||||||
|
|
||||||
|
$.get("/api/activestations", function(data, status){
|
||||||
|
data = JSON.parse(data)
|
||||||
|
Object.keys(data).forEach(function(key){
|
||||||
|
sat = light_sat
|
||||||
|
if(data[key]["eclipsed"]){
|
||||||
|
sat = dark_sat
|
||||||
|
}
|
||||||
|
if(data[key]["image"] != null){
|
||||||
|
image = data[key]["image"]
|
||||||
|
if(data[key]["eclipsed"]){
|
||||||
|
image = image + "-dark.png"
|
||||||
|
}else{
|
||||||
|
image = image + "-light.png"
|
||||||
|
}
|
||||||
|
|
||||||
|
sat = L.icon({
|
||||||
|
iconUrl: image,
|
||||||
|
iconSize: [40, 40],
|
||||||
|
iconAnchor: [20, 20],
|
||||||
|
popupAnchor: [0, 0],
|
||||||
|
|
||||||
|
});
|
||||||
|
}
|
||||||
|
marker = L.marker(data[key]["lat_lng"],{icon: sat,zIndexOffset:1000}).addTo(mymap);
|
||||||
|
marker.bindPopup("<b>Name: "+data[key]["name"]+"</b><br><b>Norad: "+key+"</b><br><b>Eclipsed?: "+data[key]["eclipsed"]);
|
||||||
|
sats[key] = marker;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
//Ground Stations
|
//Ground Stations
|
||||||
// marker = L.marker({{x["lat_lng"]}},{icon: station,zIndexOffset:-1000}).addTo(mymap);
|
// marker = L.marker({{x["lat_lng"]}},{icon: station,zIndexOffset:-1000}).addTo(mymap);
|
||||||
//marker.bindPopup("<b>Name: {{x['name']}}</b>")
|
//marker.bindPopup("<b>Name: {{x['name']}}</b>")
|
||||||
|
|
Loading…
Reference in New Issue