From 87ceb972dae14d302930083fc0b681e7a4ca5df8 Mon Sep 17 00:00:00 2001 From: wgaylord Date: Wed, 19 Dec 2018 15:25:38 -0600 Subject: [PATCH] Front-end mostly working. Some small bugs. --- satnogs.py | 23 ++++++++-------- static/Worker.js | 52 +++++++++++++++++++++++++++--------- static/satellite.js | 1 + templates/map.html | 65 ++++++++++++++++++++++++++++++++++++++------- 4 files changed, 109 insertions(+), 32 deletions(-) create mode 100644 static/satellite.js diff --git a/satnogs.py b/satnogs.py index 62399cb..d128593 100644 --- a/satnogs.py +++ b/satnogs.py @@ -11,6 +11,7 @@ app = Flask(__name__) Passes = [] +Occuring_sats = {} Stations = [] TLEs = {} @@ -101,9 +102,16 @@ def GetGroundStations(): @scheduler.scheduled_job('interval',minutes=3) def updatePasses(): global Passes + global Occuring_sats print "Updating Passes" Passes = getActive() - + Occuring_sats = {} + 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])] + Occuring_sats[x.norad] = TLEs[x.norad] + @scheduler.scheduled_job('interval',hours=1) def updateStations(): global Stations @@ -121,7 +129,7 @@ def updateTLE(): satnogs_db_norad_ids = satnogs_db_norad_ids - temporary_norad_ids # Fetch TLEs for the satellites of interest - print satnogs_db_norad_ids + tles = fetch_tles(satnogs_db_norad_ids) TLEs = {} for norad_id, (source, tle) in tles.items(): @@ -139,7 +147,7 @@ def map_view(): def api_active_stations(): sations = [] for x in Stations: - sations.append([x["name"],{"lat":x["lat"],"lng":x["lng"]}]) + sations.append({'id':x['id'],'name':x['name'],'lat_lng':[x["lat"],x['lng']]}) return json.dumps(sations) @app.route('/stations_from_sat/') @@ -153,14 +161,7 @@ def api_occuring_observations(norad): @app.route('/occuring_sats') def api_occuring_sats(): - 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] - - return json.dumps(tle) + return json.dumps(Occuring_sats) diff --git a/static/Worker.js b/static/Worker.js index d86248a..e02410c 100644 --- a/static/Worker.js +++ b/static/Worker.js @@ -1,16 +1,44 @@ -importScripts("https://bundle.run/satellite.js@3.0.0") +self.importScripts("satellite.js"); -norad = 0 -passes = [] +norad = "" +groundStations = [] 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 + norad = e.data[0] + TLE = e.data[1] + getStations() +} + +setInterval(function(){ + getStations() +}, 20000); + +setInterval(function(){ + var satrec = self.satellite_js.twoline2satrec(TLE[1],TLE[2]); + var gmst = self.satellite_js.gstime(new Date()); + var positionAndVelocity = self.satellite_js.propagate(satrec, new Date()); + var positionEci = positionAndVelocity.position + var positionGd = self.satellite_js.eciToGeodetic(positionEci, gmst) + var longitude = positionGd.longitude + var latitude = positionGd.latitude + + postMessage([norad,TLE[0],[degress(latitude),degress(longitude)],groundStations]) + + +}, 500); + +function getStations(){ +var xhttp = new XMLHttpRequest(); + xhttp.onreadystatechange = function() { + if (this.readyState == 4 && this.status == 200) { + groundStations = JSON.parse(this.responseText); + } + }; + xhttp.open("GET", "/stations_from_sat/"+norad, true); + xhttp.send(); +} + +function degress (radians) { + return radians * 180 / Math.PI; +}; \ No newline at end of file diff --git a/static/satellite.js b/static/satellite.js new file mode 100644 index 0000000..e294cab --- /dev/null +++ b/static/satellite.js @@ -0,0 +1 @@ +!function(o,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t(o.satellite_js={})}(this,function(o){"use strict";var Ho=Math.PI,Yo=2*Ho,m=Ho/180,t=180/Ho,s=398600.5,Ao=6378.137,Bo=60/Math.sqrt(Ao*Ao*Ao/s),p=1/Bo,Co=.00108262998905,e=-253215306e-14,Uo=-161098761e-14,Do=e/Co,Jo=2/3,a=Object.freeze({pi:Ho,twoPi:Yo,deg2rad:m,rad2deg:t,minutesPerDay:1440,mu:s,earthRadius:Ao,xke:Bo,tumin:p,j2:Co,j3:e,j4:Uo,j3oj2:Do,x2o3:Jo});function l(o,t){for(var s=[31,o%4==0?29:28,31,30,31,30,31,31,30,31,30,31],e=Math.floor(t),a=1,n=0;n+s[a-1]Ho&&(so - +test = null var light_sat = L.icon({ iconUrl: 'static/satellite-marker-light.png', iconSize: [40, 40], @@ -71,24 +71,71 @@ var active_station = L.icon({ id: 'mapbox.streets', accessToken: 'pk.eyJ1IjoiY2hpYmlsbCIsImEiOiJjamxsNHBuZG4wdG1uM3FwYTN5c2ZubmxrIn0.ghkx6AngBzUiZQWBAWKziQ' }).addTo(mymap); +var t = L.terminator(); +t.addTo(mymap); +setInterval(function(){updateTerminator(t)}, 500); +function updateTerminator(t) { + var t2 = L.terminator(); + t.setLatLngs(t2.getLatLngs()); + t.redraw(); +} +Stations = {} +Workers = {} +Lines = {} +Sats = {} -Stations = [] - +dataS = null function UpdateMap(e) { - var satPos = e[0] - var links = e[1] + var norad = e.data[0] + var name = e.data[1] + var satPos = e.data[2] + if (norad in Sats){ + + }else{ + Sats[norad] = L.marker(satPos,{icon: dark_sat,zIndexOffset:1000}).addTo(mymap); + Sats[norad].bindPopup("Name: "+name+"
Norad: "+norad+""); + Lines[norad] = {} + e.data[3].forEach(function(x){ + Lines[norad][x] = new L.Polyline([[Stations[x]._latlng.lat,Stations[x]._latlng.lng],[satPos[0],satPos[1]]], {color: '#'+norad.toString(16).repeat(2).substr(0,6),weight: 3,opacity: 1,smoothFactor: 1}); + Lines[norad][x].addTo(mymap) + }); + } + Sats[norad]._latlng = {"lat":satPos[0],"lng":satPos[1]} + Sats[norad].update() + Object.keys(Lines[norad]).forEach(function(x){ + if (x in e){ + Lines[norad][x]._latlngs[1]= {"lat":satPos[0],"lng":satPos[1]} + Lines[norad][x].update() + }else{ + Lines[norad][x].removeFrom(mymap) + delete Lines[norad][x] + } + }) + + + } $.get("/active_stations", function(data, status){ data = JSON.parse(data) - Object.keys(data).forEach(function(x){ - marker = L.marker(x[1],{icon: station,zIndexOffset:-1000}).addTo(mymap); - marker.bindPopup("Name: "+x[2]+"") - + dataS = data + data.forEach(function(x){ + + marker = L.marker(x["lat_lng"],{icon: station,zIndexOffset:-1000}).addTo(mymap); + marker.bindPopup("Name: "+x['name']+"") + Stations[x["id"]] = marker }); }); + $.get("/occuring_sats", function(data, status){ + data = JSON.parse(data) + Object.keys(data).forEach(function(x){ + worker = new Worker('/static/Worker.js'); + worker.onmessage = UpdateMap + worker.postMessage([x,data[x]]); + }); + }); //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"]);