From 0538d6e60f82309ee1b07b07c1acb8aa64df749c Mon Sep 17 00:00:00 2001 From: Andrew Henry Date: Mon, 12 Oct 2015 19:54:03 -0700 Subject: [PATCH] Initial working version --- example/msl/src/RemsDataDictionary.js | 10 +++---- example/msl/src/RemsTelemetryProvider.js | 2 +- example/msl/src/RemsTelemetryServerAdapter.js | 27 +++++++++++-------- 3 files changed, 22 insertions(+), 17 deletions(-) diff --git a/example/msl/src/RemsDataDictionary.js b/example/msl/src/RemsDataDictionary.js index 2890710599..53e2f8e0cf 100644 --- a/example/msl/src/RemsDataDictionary.js +++ b/example/msl/src/RemsDataDictionary.js @@ -34,31 +34,31 @@ define( "measurements": [ { "name": "Min. Air Temperature", - "identifier": "rems.min_temp", + "identifier": "min_temp", "units": "degrees", "type": "float" }, { "name": "Max. Air Temperature", - "identifier": "rems.max_temp", + "identifier": "max_temp", "units": "degrees", "type": "float" }, { "name": "Atmospheric Pressure", - "identifier": "rems.pressure", + "identifier": "pressure", "units": "pascals", "type": "float" }, { "name": "Min. Ground Temperature", - "identifier": "rems.min_gts_temp", + "identifier": "min_gts_temp", "units": "degrees", "type": "float" }, { "name": "Max. Ground Temperature", - "identifier": "rems.max_gts_temp", + "identifier": "max_gts_temp", "units": "degrees", "type": "float" } diff --git a/example/msl/src/RemsTelemetryProvider.js b/example/msl/src/RemsTelemetryProvider.js index 3ae368ca33..7b27aef964 100644 --- a/example/msl/src/RemsTelemetryProvider.js +++ b/example/msl/src/RemsTelemetryProvider.js @@ -43,7 +43,7 @@ define ( function addToPackage(history) { packaged[SOURCE][history.id] = - new RemsTelemetrySeries(history.value); + new RemsTelemetrySeries(history.values); } function handleRequest(request) { diff --git a/example/msl/src/RemsTelemetryServerAdapter.js b/example/msl/src/RemsTelemetryServerAdapter.js index ce5d17b7da..257e0d37bd 100644 --- a/example/msl/src/RemsTelemetryServerAdapter.js +++ b/example/msl/src/RemsTelemetryServerAdapter.js @@ -27,8 +27,7 @@ define( "use strict"; var TERRESTRIAL_DATE = "terrestrial_date", - NO_DATA = "--", - PREFIX = "rems."; + NO_DATA = "--"; /** * For now just returns a hard-coded data dictionary, but in future @@ -37,31 +36,37 @@ define( */ function RemsTelemetryServerAdapter($q, $http, REMS_WS_URL){ var histories = {}, - deferred; + deferreds = {}; 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 */ + var lastGoodValue=0; 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]}); + histories[prop] = histories[prop] || []; + var value = isNaN(solData[prop]) ? lastGoodValue : (lastGoodValue = solData[prop]); + histories[prop].unshift({date: Date.parse(solData[TERRESTRIAL_DATE]), value: value}); } }); - deferred.resolve(histories[id]); + + deferreds[id].resolve({id: id, values: histories[id]}); }, function (error){ - deferred.reject(error); + deferreds[id].reject(error); }); } return { dictionary: RemsDataDictionary, history: function(id) { - deferred = deferred || $q.defer(); - requestHistory(id); - return deferred.promise; + deferreds[id] = deferreds[id] || $q.defer(); + if (histories[id]) { + deferreds[id].resolve({id: id, values: histories[id]}); + } else { + requestHistory(id); + } + return deferreds[id].promise; } }; }