1
0
Fork 0

Make backend better for use with web workers

merge-requests/1/head
wgaylord 2018-12-18 20:30:14 -06:00
parent f23e70e497
commit f2df83c42e
3 changed files with 60 additions and 14 deletions

View File

@ -135,35 +135,32 @@ def updateTLE():
def map_view():
return render_template("map.html")
@app.route('/api/activestations')
@app.route('/api/active_stations')
def api_active_stations():
sations = []
for x in Stations:
sations.append([x["name"],x["lat"],x["lng"]])
return json.dumps(Stations)
@app.route('/api/occuringobservations')
def api_occuring_observations():
@app.route('/api/stations_from_sat/<int:norad>')
def api_occuring_observations(norad):
obs = []
for x in Passes:
obs.append(x.id)
if x.norad == norad:
obs.append(x.ground_station)
return json.dumps(obs)
@app.route('/api/occuringsats')
@app.route('/api/occuring_sats')
def api_occuring_sats():
obs = {}
tle = {}
for x in Passes:
if x.satellite['norad_cat_id'] not in TLEs.keys():
q = fetch_tle_of_observation(x.id)
TLEs[ x.norad ] = [str(x.satellite["name"]),str(q[0]),str(q[1])]
tle[x.norad] = TLEs[x.norad]
if not x.norad in obs.keys():
obs[x.norad] = []
obs[x.norad].append({"ground_station":x.ground_station,"start":x.start.isoformat(),"end":x.end.isoformat()})
return json.dumps([obs,tle])
return json.dumps(tle)

16
static/Worker.js 100644
View File

@ -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);
}

View File

@ -7,8 +7,7 @@
crossorigin=""></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 async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<script src="https://bundle.run/satellite.js@3.0.0"></script>
</head>
@ -74,6 +73,40 @@ var active_station = L.icon({
}).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
// marker = L.marker({{x["lat_lng"]}},{icon: station,zIndexOffset:-1000}).addTo(mymap);
//marker.bindPopup("<b>Name: {{x['name']}}</b>")