mirror of
https://github.com/nasa/openmct.git
synced 2025-06-16 14:18:16 +00:00
Updating code to conform to code style
This commit is contained in:
@ -23,6 +23,12 @@
|
|||||||
|
|
||||||
define(
|
define(
|
||||||
[],
|
[],
|
||||||
|
/**
|
||||||
|
* A data dictionary describes the telemetry available from a data
|
||||||
|
* source and its data types. The data dictionary will be parsed by a custom
|
||||||
|
* server provider for this data source (in this case
|
||||||
|
* {@link RemsTelemetryServerAdapter}).
|
||||||
|
*/
|
||||||
function () {
|
function () {
|
||||||
return {
|
return {
|
||||||
"name": "Mars Science Laboratory",
|
"name": "Mars Science Laboratory",
|
@ -22,74 +22,76 @@
|
|||||||
/*global define*/
|
/*global define*/
|
||||||
|
|
||||||
define(
|
define(
|
||||||
["./RemsDataDictionary"],
|
["./MSLDataDictionary"],
|
||||||
function (RemsDataDictionary) {
|
function (MSLDataDictionary) {
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var TERRESTRIAL_DATE = "terrestrial_date",
|
var TERRESTRIAL_DATE = "terrestrial_date";
|
||||||
NO_DATA = "--";
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* For now just returns a hard-coded data dictionary, but in future
|
* Fetches historical data from the REMS instrument on the Curiosity
|
||||||
* could be adapted to provide data from remote source.
|
* Rover. Exposes two services to client code, one
|
||||||
|
* @param $q
|
||||||
|
* @param $http
|
||||||
|
* @param REMS_WS_URL
|
||||||
|
* @returns {{dictionary: exports, history: Function}}
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
function RemsTelemetryServerAdapter($q, $http, REMS_WS_URL){
|
function RemsTelemetryServerAdapter($q, $http, REMS_WS_URL) {
|
||||||
var histories = {},
|
this.histories = {},
|
||||||
deferreds = {};
|
this.deferreds = {};
|
||||||
|
this.REMS_WS_URL = REMS_WS_URL;
|
||||||
function statisticalRejection(values){
|
this.$q = $q;
|
||||||
//First, calculate mean
|
this.$http = $http;
|
||||||
var mean = values.reduce(function(accumulator, value){
|
|
||||||
return accumulator += parseInt(value.value);
|
|
||||||
}, 0) / values.length;
|
|
||||||
var variance = values.reduce(function(accumulator, value){
|
|
||||||
return accumulator+= Math.pow(parseInt(value.value) - mean, 2);
|
|
||||||
}, 0) / values.length;
|
|
||||||
var stddev = Math.sqrt(variance);
|
|
||||||
return values.filter(function(value){
|
|
||||||
return mean - stddev < parseInt(value.value) && parseInt(value.value) < mean + stddev;
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
function requestHistory (id) {
|
|
||||||
$http.get(REMS_WS_URL).then(
|
|
||||||
function(response){
|
|
||||||
histories = {};
|
|
||||||
/**
|
|
||||||
* 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){
|
|
||||||
histories[prop] = histories[prop] || [];
|
|
||||||
if (!isNaN(solData[prop])) {
|
|
||||||
//var value = isNaN(solData[prop]) ? lastGoodValue : (lastGoodValue = solData[prop]);
|
|
||||||
histories[prop].unshift({
|
|
||||||
date: Date.parse(solData[TERRESTRIAL_DATE]),
|
|
||||||
value: solData[prop]
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
//deferreds[id].resolve({id: id, values: statisticalRejection(histories[id])});
|
|
||||||
deferreds[id].resolve({id: id, values: histories[id]});
|
|
||||||
}, function (error){
|
|
||||||
deferreds[id].reject(error);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
return {
|
|
||||||
dictionary: RemsDataDictionary,
|
|
||||||
history: function(id) {
|
|
||||||
deferreds[id] = deferreds[id] || $q.defer();
|
|
||||||
if (histories[id]) {
|
|
||||||
deferreds[id].resolve({id: id, values: histories[id]});
|
|
||||||
} else {
|
|
||||||
histories = {};
|
|
||||||
requestHistory(id);
|
|
||||||
}
|
|
||||||
return deferreds[id].promise;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
RemsTelemetryServerAdapter.prototype.requestHistory = function(id) {
|
||||||
|
var self = this;
|
||||||
|
|
||||||
|
return this.$http.get(this.REMS_WS_URL).then(function(response){
|
||||||
|
self.histories = {};
|
||||||
|
/**
|
||||||
|
* 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){
|
||||||
|
self.histories[prop] = self.histories[prop] || [];
|
||||||
|
if (!isNaN(solData[prop])) {
|
||||||
|
self.histories[prop].unshift({
|
||||||
|
date: Date.parse(solData[TERRESTRIAL_DATE]),
|
||||||
|
value: solData[prop]
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
self.deferreds[id].resolve({id: id, values: self.histories[id]});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @type {exports}
|
||||||
|
*/
|
||||||
|
RemsTelemetryServerAdapter.prototype.dictionary = MSLDataDictionary;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param id
|
||||||
|
* @returns {p.promise|{then, fail, end}|performPromise|deferred.promise|{}|*}
|
||||||
|
*/
|
||||||
|
RemsTelemetryServerAdapter.prototype.history = function(id) {
|
||||||
|
this.deferreds[id] = this.deferreds[id] || this.$q.defer();
|
||||||
|
if (this.histories[id]) {
|
||||||
|
this.deferreds[id].resolve({id: id, values: this.histories[id]});
|
||||||
|
} else {
|
||||||
|
this.histories = {};
|
||||||
|
this.requestHistory(id);
|
||||||
|
}
|
||||||
|
return this.deferreds[id].promise;
|
||||||
|
};
|
||||||
|
|
||||||
return RemsTelemetryServerAdapter;
|
return RemsTelemetryServerAdapter;
|
||||||
});
|
});
|
Reference in New Issue
Block a user