Fixed erroneous data

This commit is contained in:
Andrew Henry 2015-10-22 21:30:13 -07:00
parent 14722a6ef5
commit cdc2a407dc
2 changed files with 26 additions and 6 deletions

View File

@ -30,7 +30,7 @@ define(
float: "number",
integer: "number",
string: "string"
};
}
function RemsTelemetryModelProvider(adapter){
@ -54,7 +54,7 @@ define(
key: measurement.identifier,
ranges: [{
key: "value",
name: "Value",
name: measurement.units,
units: measurement.units,
format: format
}]

View File

@ -37,21 +37,41 @@ define(
function RemsTelemetryServerAdapter($q, $http, REMS_WS_URL){
var histories = {},
deferreds = {};
function statisticalRejection(values){
//First, calculate mean
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
*/
var lastGoodValue=0;
response.data.soles.forEach(function(solData){
for (var prop in solData){
histories[prop] = histories[prop] || [];
var value = isNaN(solData[prop]) ? lastGoodValue : (lastGoodValue = solData[prop]);
histories[prop].unshift({date: Date.parse(solData[TERRESTRIAL_DATE]), value: value});
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);