diff --git a/example/msl/bundle.json b/example/msl/bundle.json index e627aef0b1..2a7f5141c7 100644 --- a/example/msl/bundle.json +++ b/example/msl/bundle.json @@ -19,7 +19,7 @@ "glyph": "T", "model": {"telemetry": {}}, "telemetry": { - "source": "msl.source", + "source": "rems.source", "domains": [ { "name": "Time", @@ -29,6 +29,12 @@ } } ], + "constants": [ + { + "key": "REMS_WS_URL", + "value": "http://cab.inta-csic.es/rems/wp-content/plugins/marsweather-widget/api.php" + } + ], "roots": [ { "id": "msl:curiosity", @@ -44,7 +50,7 @@ { "key":"rems.adapter", "implementation": "RemsTelemetryServerAdapter.js", - "depends": ["$q", "$http"] + "depends": ["$q", "$http", "REMS_WS_URL"] } ], "runs": [ diff --git a/example/msl/src/RemsDataDictionary.js b/example/msl/src/RemsDataDictionary.js index 55c8f90702..2890710599 100644 --- a/example/msl/src/RemsDataDictionary.js +++ b/example/msl/src/RemsDataDictionary.js @@ -39,7 +39,7 @@ define( "type": "float" }, { - "name": "Max. Air Temperatyre", + "name": "Max. Air Temperature", "identifier": "rems.max_temp", "units": "degrees", "type": "float" diff --git a/example/msl/src/RemsTelemetrySeries.js b/example/msl/src/RemsTelemetrySeries.js index 4a5986c5a9..dcfbbd2551 100644 --- a/example/msl/src/RemsTelemetrySeries.js +++ b/example/msl/src/RemsTelemetrySeries.js @@ -27,13 +27,13 @@ define( function RemsTelemetrySeries(data) { return { getPointCount: function(){ - return 100; + return data.length; }, getDomainValue: function(index) { - return index + 45 * 365 * 24 * 60 * 60 * 1000; + return data[index].date; }, getRangeValue: function(index){ - return index * 10; + return data[index].value; } } } diff --git a/example/msl/src/RemsTelemetryServerAdapter.js b/example/msl/src/RemsTelemetryServerAdapter.js index efd3db4790..ce5d17b7da 100644 --- a/example/msl/src/RemsTelemetryServerAdapter.js +++ b/example/msl/src/RemsTelemetryServerAdapter.js @@ -25,20 +25,43 @@ define( ["./RemsDataDictionary"], function (RemsDataDictionary) { "use strict"; - + + var TERRESTRIAL_DATE = "terrestrial_date", + NO_DATA = "--", + PREFIX = "rems."; + /** * For now just returns a hard-coded data dictionary, but in future * could be adapted to provide data from remote source. * @constructor */ - function RemsTelemetryServerAdapter($q, $http){ - var histories = {}; - + function RemsTelemetryServerAdapter($q, $http, REMS_WS_URL){ + var histories = {}, + deferred; + function requestHistory (id) { + $http.get(REMS_WS_URL).then( + function(response){ + /** + * All history is fetched in one go, cache it all to save round trips to the server on subsequent requests + */ + response.data.soles.forEach(function(solData){ + for (var prop in solData){ + var propName = PREFIX + prop; + histories[propName] = histories[propName] || []; + histories[propName].push({date: Date.parse(solData[TERRESTRIAL_DATE]), value: solData[prop]=== NO_DATA ? undefined : solData[prop]}); + } + }); + deferred.resolve(histories[id]); + }, function (error){ + deferred.reject(error); + }); + } return { dictionary: RemsDataDictionary, history: function(id) { - histories[id] = histories[id] || $q.defer(); - return histories[id].promise; + deferred = deferred || $q.defer(); + requestHistory(id); + return deferred.promise; } }; }