1
0
Fork 0

Front-end mostly working. Some small bugs.

merge-requests/1/head
wgaylord 2018-12-19 15:25:38 -06:00
parent 739fd839e7
commit 87ceb972da
4 changed files with 109 additions and 32 deletions

View File

@ -11,6 +11,7 @@ app = Flask(__name__)
Passes = [] Passes = []
Occuring_sats = {}
Stations = [] Stations = []
TLEs = {} TLEs = {}
@ -101,9 +102,16 @@ def GetGroundStations():
@scheduler.scheduled_job('interval',minutes=3) @scheduler.scheduled_job('interval',minutes=3)
def updatePasses(): def updatePasses():
global Passes global Passes
global Occuring_sats
print "Updating Passes" print "Updating Passes"
Passes = getActive() 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) @scheduler.scheduled_job('interval',hours=1)
def updateStations(): def updateStations():
global Stations global Stations
@ -121,7 +129,7 @@ def updateTLE():
satnogs_db_norad_ids = satnogs_db_norad_ids - temporary_norad_ids satnogs_db_norad_ids = satnogs_db_norad_ids - temporary_norad_ids
# Fetch TLEs for the satellites of interest # Fetch TLEs for the satellites of interest
print satnogs_db_norad_ids
tles = fetch_tles(satnogs_db_norad_ids) tles = fetch_tles(satnogs_db_norad_ids)
TLEs = {} TLEs = {}
for norad_id, (source, tle) in tles.items(): for norad_id, (source, tle) in tles.items():
@ -139,7 +147,7 @@ def map_view():
def api_active_stations(): def api_active_stations():
sations = [] sations = []
for x in Stations: 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) return json.dumps(sations)
@app.route('/stations_from_sat/<string:norad>') @app.route('/stations_from_sat/<string:norad>')
@ -153,14 +161,7 @@ def api_occuring_observations(norad):
@app.route('/occuring_sats') @app.route('/occuring_sats')
def api_occuring_sats(): def api_occuring_sats():
tle = {} return json.dumps(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])]
tle[x.norad] = TLEs[x.norad]
return json.dumps(tle)

View File

@ -1,16 +1,44 @@
importScripts("https://bundle.run/satellite.js@3.0.0") self.importScripts("satellite.js");
norad = 0 norad = ""
passes = [] groundStations = []
TLE = [] TLE = []
onmessage = function(e) { onmessage = function(e) {
if(e[0] == 1){ norad = e.data[0]
norad = e[1] TLE = e.data[1]
TLE = e[2] getStations()
passes = e[3] }
}
var workerResult = 'Result: ' + (e.data[0] * e.data[1]); setInterval(function(){
console.log('Posting message back to main script'); getStations()
postMessage(workerResult); }, 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;
};

File diff suppressed because one or more lines are too long

View File

@ -31,7 +31,7 @@
<script> <script>
test = null
var light_sat = L.icon({ var light_sat = L.icon({
iconUrl: 'static/satellite-marker-light.png', iconUrl: 'static/satellite-marker-light.png',
iconSize: [40, 40], iconSize: [40, 40],
@ -71,24 +71,71 @@ var active_station = L.icon({
id: 'mapbox.streets', id: 'mapbox.streets',
accessToken: 'pk.eyJ1IjoiY2hpYmlsbCIsImEiOiJjamxsNHBuZG4wdG1uM3FwYTN5c2ZubmxrIn0.ghkx6AngBzUiZQWBAWKziQ' accessToken: 'pk.eyJ1IjoiY2hpYmlsbCIsImEiOiJjamxsNHBuZG4wdG1uM3FwYTN5c2ZubmxrIn0.ghkx6AngBzUiZQWBAWKziQ'
}).addTo(mymap); }).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) { function UpdateMap(e) {
var satPos = e[0] var norad = e.data[0]
var links = e[1] 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("<b>Name: "+name+"</b><br><b>Norad: "+norad+"</b>");
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){ $.get("/active_stations", function(data, status){
data = JSON.parse(data) data = JSON.parse(data)
Object.keys(data).forEach(function(x){ dataS = data
marker = L.marker(x[1],{icon: station,zIndexOffset:-1000}).addTo(mymap); data.forEach(function(x){
marker.bindPopup("<b>Name: "+x[2]+"</b>")
marker = L.marker(x["lat_lng"],{icon: station,zIndexOffset:-1000}).addTo(mymap);
marker.bindPopup("<b>Name: "+x['name']+"</b>")
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 = 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"]); //marker.bindPopup("<b>Name: "+data[key]["name"]+"</b><br><b>Norad: "+key+"</b><br><b>Eclipsed?: "+data[key]["eclipsed"]);