From f2df83c42e6e5dc1bde2526e9fc5c26f8a087ea2 Mon Sep 17 00:00:00 2001 From: wgaylord Date: Tue, 18 Dec 2018 20:30:14 -0600 Subject: [PATCH] Make backend better for use with web workers --- satnogs.py | 21 +++++++++------------ static/Worker.js | 16 ++++++++++++++++ templates/map.html | 37 +++++++++++++++++++++++++++++++++++-- 3 files changed, 60 insertions(+), 14 deletions(-) create mode 100644 static/Worker.js diff --git a/satnogs.py b/satnogs.py index b45e4d0..ce672c6 100644 --- a/satnogs.py +++ b/satnogs.py @@ -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/') +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) diff --git a/static/Worker.js b/static/Worker.js new file mode 100644 index 0000000..d86248a --- /dev/null +++ b/static/Worker.js @@ -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); +} \ No newline at end of file diff --git a/templates/map.html b/templates/map.html index 3e7dfea..46347c5 100644 --- a/templates/map.html +++ b/templates/map.html @@ -7,8 +7,7 @@ crossorigin=""> - - + @@ -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("Name: "+data[key]["name"]+"
Norad: "+key+"
Eclipsed?: "+data[key]["eclipsed"]); + sats[key] = marker; + }); + }); + //Ground Stations // marker = L.marker({{x["lat_lng"]}},{icon: station,zIndexOffset:-1000}).addTo(mymap); //marker.bindPopup("Name: {{x['name']}}")