Commit 4816cef4f64959d2d95fd094fd1b2389bd09879c

Authored by Goutte
1 parent c69afa1c

Refactor some more.

@@ -271,8 +271,6 @@ def get_orbiter_csv(source): @@ -271,8 +271,6 @@ def get_orbiter_csv(source):
271 except: 271 except:
272 abort(400, "Invalid stopped_at parameter : '%s'." % stopped_at) 272 abort(400, "Invalid stopped_at parameter : '%s'." % stopped_at)
273 273
274 -  
275 - source_config = get_source_config(orbiter)  
276 # todo: iterate on models when there are many 274 # todo: iterate on models when there are many
277 try: 275 try:
278 model_slug = source_config['models'][0]['slug'] 276 model_slug = source_config['models'][0]['slug']
web/static/js/swapp.js
@@ -75,6 +75,38 @@ @@ -75,6 +75,38 @@
75 }); 75 });
76 return promise; 76 return promise;
77 }; 77 };
  78 + SpaceWeather.prototype.createTimeSeries = function(data){
  79 + var timeSeries;
  80 + timeSeries = [];
  81 + this.configuration['parameters'].forEach(function(parameter){
  82 + var container, id, title;
  83 + container = this.configuration['time_series_container'];
  84 + id = parameter['id'];
  85 + title = parameter['title'];
  86 + if (!(id in data)) {
  87 + console.error("No data for id '" + id + "'.", data);
  88 + }
  89 + return timeSeries.push(new TimeSeries(id, title, data[id], container));
  90 + });
  91 + return timeSeries.forEach(function(ts){
  92 + ts.options['onMouseOver'] = function(){
  93 + return timeSeries.forEach(function(ts2){
  94 + return ts2.showCursor();
  95 + });
  96 + };
  97 + ts.options['onMouseOut'] = function(){
  98 + return timeSeries.forEach(function(ts2){
  99 + return ts2.hideCursor();
  100 + });
  101 + };
  102 + return ts.options['onMouseMove'] = function(t){
  103 + timeSeries.forEach(function(ts2){
  104 + return ts2.moveCursor(t);
  105 + });
  106 + return typeof orbits != 'undefined' && orbits !== null ? orbits.moveToDate(t) : void 8;
  107 + };
  108 + });
  109 + };
78 return SpaceWeather; 110 return SpaceWeather;
79 }()); 111 }());
80 Source = (function(){ 112 Source = (function(){
web/static/js/swapp.ls
@@ -57,6 +57,25 @@ export class SpaceWeather @@ -57,6 +57,25 @@ export class SpaceWeather
57 ) 57 )
58 promise 58 promise
59 59
  60 + createTimeSeries: (data) ->
  61 + timeSeries = []
  62 + @configuration['parameters'].forEach((parameter) ->
  63 + container = @configuration['time_series_container']
  64 + id = parameter['id'] ; title = parameter['title']
  65 + if id not of data then console.error("No data for id '#{id}'.", data)
  66 + timeSeries.push(new TimeSeries(id, title, data[id], container))
  67 + )
  68 + timeSeries.forEach((ts) ->
  69 + ts.options['onMouseOver'] = ->
  70 + timeSeries.forEach((ts2) -> ts2.showCursor())
  71 + ts.options['onMouseOut'] = ->
  72 + timeSeries.forEach((ts2) -> ts2.hideCursor())
  73 + ts.options['onMouseMove'] = (t) ->
  74 + timeSeries.forEach((ts2) -> ts2.moveCursor(t))
  75 + orbits?.moveToDate(t)
  76 + )
  77 +
  78 +
60 79
61 80
62 class Source 81 class Source
web/view/home.html.jinja2
@@ -213,53 +213,14 @@ jQuery().ready(function($){ @@ -213,53 +213,14 @@ jQuery().ready(function($){
213 213
214 var sw = new SpaceWeather(configuration); 214 var sw = new SpaceWeather(configuration);
215 sw.loadData('jupiter', '2016-01-01T00:00:00', '2023-01-01T00:00:00').then( 215 sw.loadData('jupiter', '2016-01-01T00:00:00', '2023-01-01T00:00:00').then(
216 - function (data) { console.log('OK', data); },  
217 - function (data) { console.log('Failed', data); } 216 + function (data) {
  217 + console.log('OK', data);
  218 + sw.createTimeSeries(data);
  219 + orbits = new Orbits(configuration.sources, data['hci'], configuration.orbits_container);
  220 + },
  221 + function (data) { console.error('Failed to load SW data.', data); }
218 ); 222 );
219 223
220 - d3.csv('{{ url_for('get_orbiter_csv', source='jupiter', started_at='2016-03-19T00:00:00', stopped_at='2022-01-01T00:00:00') }}', function(csv){  
221 - var timeFormat = d3.timeParse('%Y-%m-%dT%H:%M:%S%Z');  
222 - var data = {'hci': []};  
223 - configuration['parameters'].forEach(function(parameter){  
224 - data[parameter['id']] = [];  
225 - });  
226 - csv.forEach(function (d) {  
227 - var dtime = timeFormat(d['time']);  
228 - configuration['parameters'].forEach(function(parameter){  
229 - var id = parameter['id'];  
230 - data[id].push({x: dtime, y: parseFloat(d[id])});  
231 - });  
232 - if (d['xhci'] && d['yhci']) {  
233 - data['hci'].push({t: dtime, x: parseFloat(d['xhci']), y: parseFloat(d['yhci'])});  
234 - }  
235 - });  
236 -  
237 - var container = '#time_series';  
238 -  
239 - configuration['parameters'].forEach(function(parameter){  
240 - var id = parameter['id'];  
241 - var title = parameter['title'];  
242 - timeSeries.push(new TimeSeries(id, title, data[id], container));  
243 - });  
244 - // move outside (after promises)  
245 - timeSeries.forEach(function(ts){  
246 - ts.options['onMouseOver'] = function() {  
247 - timeSeries.forEach(function(ts2){ ts2.showCursor(); });  
248 - };  
249 - ts.options['onMouseOut'] = function() {  
250 - timeSeries.forEach(function(ts2){ ts2.hideCursor(); });  
251 - };  
252 - ts.options['onMouseMove'] = function(t) {  
253 - timeSeries.forEach(function(ts2){ ts2.moveCursor(t); });  
254 - if (orbits != null) orbits.moveToDate(t);  
255 - };  
256 - });  
257 -  
258 -  
259 - orbits = new Orbits(configuration.sources, data['hci'], configuration.orbits_container);  
260 -  
261 - });  
262 -  
263 var toggleTimeSeries = function(slug) { 224 var toggleTimeSeries = function(slug) {
264 $('#time_series .'+slug).toggleClass('hidden'); 225 $('#time_series .'+slug).toggleClass('hidden');
265 }; 226 };