Remove extreme fluctuation check, because of accuracy decline
parent
c97d8179df
commit
d28d762304
|
|
@ -1,15 +1,15 @@
|
||||||
{
|
{
|
||||||
var dataFile = "smartbattdata.json";
|
var dataFile = "smartbattdata.json";
|
||||||
var interval;
|
var interval;
|
||||||
var storage=require("Storage");
|
var storage = require("Storage");
|
||||||
|
|
||||||
|
|
||||||
var logFile = "smartbattlog.json";
|
var logFile = "smartbattlog.json";
|
||||||
|
|
||||||
function getSettings(){
|
function getSettings() {
|
||||||
return Object.assign({
|
return Object.assign({
|
||||||
//Record Interval stored in ms
|
//Record Interval stored in ms
|
||||||
doLogging:false
|
doLogging: false
|
||||||
}, require('Storage').readJSON("smartbatt.settings.json", true) || {});
|
}, require('Storage').readJSON("smartbatt.settings.json", true) || {});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -18,11 +18,11 @@
|
||||||
//get human-readable time
|
//get human-readable time
|
||||||
let d = new Date();
|
let d = new Date();
|
||||||
entry.time = d.getFullYear() + "-" +
|
entry.time = d.getFullYear() + "-" +
|
||||||
("0"+(d.getMonth()+1)).slice(-2) + "-" +
|
("0" + (d.getMonth() + 1)).slice(-2) + "-" +
|
||||||
("0"+d.getDate()).slice(-2) + " " +
|
("0" + d.getDate()).slice(-2) + " " +
|
||||||
("0"+d.getHours()).slice(-2) + ":" +
|
("0" + d.getHours()).slice(-2) + ":" +
|
||||||
("0"+d.getMinutes()).slice(-2) + ":" +
|
("0" + d.getMinutes()).slice(-2) + ":" +
|
||||||
("0"+d.getSeconds()).slice(-2);
|
("0" + d.getSeconds()).slice(-2);
|
||||||
|
|
||||||
log.push(entry);
|
log.push(entry);
|
||||||
if (log.length > 100) log = log.slice(-100);
|
if (log.length > 100) log = log.slice(-100);
|
||||||
|
|
@ -44,11 +44,11 @@
|
||||||
|
|
||||||
if (battChange <= 0) {
|
if (battChange <= 0) {
|
||||||
reason = "Skipped: battery fluctuated or no change";
|
reason = "Skipped: battery fluctuated or no change";
|
||||||
if(Math.abs(battChange)<5){
|
if (Math.abs(battChange) < 5) {
|
||||||
//less than 6% difference, average percents
|
//less than 6% difference, average percents
|
||||||
var newBatt=(batt+data.battLastRecorded)/2;
|
var newBatt = (batt + data.battLastRecorded) / 2;
|
||||||
data.battLastRecorded = newBatt;
|
data.battLastRecorded = newBatt;
|
||||||
}else{
|
} else {
|
||||||
//probably charged, ignore average
|
//probably charged, ignore average
|
||||||
data.battLastRecorded = batt;
|
data.battLastRecorded = batt;
|
||||||
}
|
}
|
||||||
|
|
@ -60,53 +60,29 @@
|
||||||
data.battLastRecorded = batt;
|
data.battLastRecorded = batt;
|
||||||
storage.writeJSON(dataFile, data);
|
storage.writeJSON(dataFile, data);
|
||||||
} else {
|
} else {
|
||||||
|
let weightCoefficient = 1;
|
||||||
let currentDrainage = battChange / deltaHours;
|
let currentDrainage = battChange / deltaHours;
|
||||||
let drainageChange=data.avgBattDrainage-currentDrainage;
|
let drainageChange = data.avgBattDrainage - currentDrainage;
|
||||||
//check if drainage rate has fluctuated quite a bit
|
|
||||||
//If fluctuation event is 0, first time fluctuating like this, cycles > 10 so as not to interfere with initial data collection.
|
|
||||||
if(Math.abs(drainageChange)>currentDrainage*0.7&&data.fluctuationEvent==0&&data.totalCycles>=10){
|
|
||||||
//has fluctuated, first time doing so
|
|
||||||
reason="Skipped: Extreme fluctuation";
|
|
||||||
//set fluctuationevent so it knows what was the first time.
|
|
||||||
data.fluctuationEvent=data.totalCycles+1;
|
|
||||||
data.battLastRecorded=batt;
|
|
||||||
storage.writeJSON(dataFile, data);
|
|
||||||
|
|
||||||
if(getSettings().doLogging){
|
|
||||||
// Always log the sample
|
|
||||||
logBatterySample({
|
|
||||||
battNow: batt,
|
|
||||||
battLast: data.battLastRecorded,
|
|
||||||
battChange: battChange,
|
|
||||||
deltaHours: deltaHours,
|
|
||||||
avgDrainage: data.avgBattDrainage,
|
|
||||||
reason: reason
|
|
||||||
});
|
|
||||||
return;
|
|
||||||
}else{
|
|
||||||
data.fluctuationEvent=0;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
let newAvg = weightedAverage(data.avgBattDrainage, data.totalHours, currentDrainage, deltaHours * weightCoefficient);
|
||||||
|
data.avgBattDrainage = newAvg;
|
||||||
let newAvg = weightedAverage(data.avgBattDrainage, data.totalHours, currentDrainage, deltaHours);
|
|
||||||
data.avgBattDrainage=newAvg;
|
|
||||||
data.timeLastRecorded = now;
|
data.timeLastRecorded = now;
|
||||||
data.totalCycles += 1;
|
data.totalCycles += 1;
|
||||||
data.totalHours+=deltaHours;
|
data.totalHours += deltaHours;
|
||||||
data.battLastRecorded = batt;
|
data.battLastRecorded = batt;
|
||||||
storage.writeJSON(dataFile, data);
|
storage.writeJSON(dataFile, data);
|
||||||
|
|
||||||
reason = "Drainage recorded: " + currentDrainage.toFixed(3) + "%/hr";
|
reason = "Drainage recorded: " + currentDrainage.toFixed(3) + "%/hr";
|
||||||
}
|
}
|
||||||
if(getSettings().doLogging){
|
if (getSettings().doLogging) {
|
||||||
// Always log the sample
|
// Always log the sample
|
||||||
logBatterySample({
|
logBatterySample({
|
||||||
battNow: batt,
|
battNow: batt,
|
||||||
battLast: data.battLastRecorded,
|
battLast: data.battLastRecorded,
|
||||||
battChange: battChange,
|
battChange: battChange,
|
||||||
deltaHours: deltaHours,
|
deltaHours: deltaHours,
|
||||||
|
timeLastRecorded: data.timeLastRecorded,
|
||||||
avgDrainage: data.avgBattDrainage,
|
avgDrainage: data.avgBattDrainage,
|
||||||
reason: reason
|
reason: reason
|
||||||
});
|
});
|
||||||
|
|
@ -125,8 +101,7 @@
|
||||||
battLastRecorded: E.getBattery(),
|
battLastRecorded: E.getBattery(),
|
||||||
timeLastRecorded: Date.now(),
|
timeLastRecorded: Date.now(),
|
||||||
totalCycles: 0,
|
totalCycles: 0,
|
||||||
totalHours:0,
|
totalHours: 0,
|
||||||
fluctuationEvent:0
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -143,7 +118,7 @@
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function deleteData(){
|
function deleteData() {
|
||||||
storage.erase(dataFile);
|
storage.erase(dataFile);
|
||||||
storage.erase(logFile);
|
storage.erase(logFile);
|
||||||
}
|
}
|
||||||
|
|
@ -151,11 +126,11 @@
|
||||||
exports.record = recordBattery;
|
exports.record = recordBattery;
|
||||||
exports.deleteData = deleteData;
|
exports.deleteData = deleteData;
|
||||||
exports.get = estimateBatteryLife;
|
exports.get = estimateBatteryLife;
|
||||||
exports.changeInterval = function(newInterval) {
|
exports.changeInterval = function (newInterval) {
|
||||||
clearInterval(interval);
|
clearInterval(interval);
|
||||||
interval=setInterval(recordBattery, newInterval);
|
interval = setInterval(recordBattery, newInterval);
|
||||||
};
|
};
|
||||||
// Start recording every 5 minutes
|
// Start recording every 5 minutes
|
||||||
interval=setInterval(recordBattery, 600000);
|
interval = setInterval(recordBattery, 600000);
|
||||||
recordBattery(); // Log immediately
|
recordBattery(); // Log immediately
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue