Rotate log files once a week
parent
8d89334c4d
commit
9851328c69
|
|
@ -1136,7 +1136,7 @@
|
||||||
"name": "Battery Chart",
|
"name": "Battery Chart",
|
||||||
"shortName":"BatChart",
|
"shortName":"BatChart",
|
||||||
"icon": "app.png",
|
"icon": "app.png",
|
||||||
"version":"0.02",
|
"version":"0.03",
|
||||||
"description": "A widget and an app for recording and visualizing battery percentage over time.",
|
"description": "A widget and an app for recording and visualizing battery percentage over time.",
|
||||||
"tags": "app,widget,battery,time,record,chart,tool",
|
"tags": "app,widget,battery,time,record,chart,tool",
|
||||||
"storage": [
|
"storage": [
|
||||||
|
|
|
||||||
|
|
@ -1,2 +1,3 @@
|
||||||
0.01: New app and widget
|
0.01: New app and widget
|
||||||
0.02: Widget stores data to file (1 dataset/min)
|
0.02: Widget stores data to file (1 dataset/10min)
|
||||||
|
0.03: Rotate log files once a week.
|
||||||
|
|
|
||||||
|
|
@ -1 +1 @@
|
||||||
require("heatshrink").decompress(atob("mEwxH+AH4A/AH4AS64AIF/4pZABYuuGDIv/F/4v/F9+Gw0rAQIASF7YxTF7cxwAvtrdVF9qQTF/4vMYCQvcYCQvcSCQvdqpgQF7oEBYJ4veAoNbF9uGmMrrgvsw2AGILFKF8IACrYxJF8gxDSowvmBwWAF9oPGF9NbmIvtCAovqMAgvqCIgvrrdVF9oSDF9iPuF7crACxf/F++wFqmG2AvXGCouZAH4A/AGY"))
|
require("heatshrink").decompress(atob("mEwxH+AH4A/AH4AS64AIF/4pZABYuuGDIv/F/4v/F9+Gw0rAQIASF7YxTF7cxwAvtrdVF9qQTF/4vMYCQvcYCQvcSCQvdqpgQF7oEBYJ4veAoNbF9uGmMrrgvsw2AGILFKF8IACrYxJF8gxDSowvmBwWAF9oPGF9NbmIvtCAovqMAgvqCIgvrrdVF9oSDF9iPuF7crACxf/F++wFqmG2AvXGCouZAH4A/AGY"))
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,8 @@
|
||||||
bluetooth: 4,
|
bluetooth: 4,
|
||||||
gps: 8,
|
gps: 8,
|
||||||
hrm: 16
|
hrm: 16
|
||||||
}
|
};
|
||||||
|
|
||||||
var settings = {};
|
var settings = {};
|
||||||
var batChartFile; // file for battery percentage recording
|
var batChartFile; // file for battery percentage recording
|
||||||
const recordingInterval10Min = 60 * 10 * 1000;
|
const recordingInterval10Min = 60 * 10 * 1000;
|
||||||
|
|
@ -20,26 +21,6 @@
|
||||||
g.drawString("BC", this.x, this.y);
|
g.drawString("BC", this.x, this.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Called by the heart app to reload settings and decide what's
|
|
||||||
function reload() {
|
|
||||||
WIDGETS["batchart"].width = 24;
|
|
||||||
|
|
||||||
// Check if the data file exists, if not try to create it.
|
|
||||||
var batChartFileCheck = require("Storage").open("batchart.dat", "r");
|
|
||||||
if (!batChartFileCheck)
|
|
||||||
if (!require("Storage").write("batchart.dat", ""))
|
|
||||||
//Only continue if the file was created
|
|
||||||
return;
|
|
||||||
|
|
||||||
recordingInterval = setInterval(() => {
|
|
||||||
var batChartFileAppend = require("Storage").open("batchart.dat", "a");
|
|
||||||
if (batChartFileAppend) {
|
|
||||||
console.log([getTime().toFixed(0), E.getBattery(), E.getTemperature(), getEnabledConsumersValue()].join(","));
|
|
||||||
batChartFileAppend.write([getTime().toFixed(0),E.getBattery].join(",")+"\n");
|
|
||||||
}
|
|
||||||
}, recordingInterval1Min)
|
|
||||||
}
|
|
||||||
|
|
||||||
function getEnabledConsumersValue() {
|
function getEnabledConsumersValue() {
|
||||||
var enabledConsumers = switchableConsumers.none;
|
var enabledConsumers = switchableConsumers.none;
|
||||||
|
|
||||||
|
|
@ -54,10 +35,40 @@
|
||||||
// enabledConsumers = enabledConsumers | switchableConsumers.gps;
|
// enabledConsumers = enabledConsumers | switchableConsumers.gps;
|
||||||
// if (Bangle.isHrmOn())
|
// if (Bangle.isHrmOn())
|
||||||
// enabledConsumers = enabledConsumers | switchableConsumers.hrm;
|
// enabledConsumers = enabledConsumers | switchableConsumers.hrm;
|
||||||
|
|
||||||
return enabledConsumers;
|
return enabledConsumers;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function logBatteryData() {
|
||||||
|
const previousWriteLogName = "bcprvday";
|
||||||
|
const previousWriteDay = require("Storage").read(previousWriteLogName);
|
||||||
|
const currentWriteDay = new Date().getDay();
|
||||||
|
|
||||||
|
const logFileName = "bclog" + currentWriteDay;
|
||||||
|
|
||||||
|
// Change log target on day change
|
||||||
|
if (previousWriteDay != currentWriteDay) {
|
||||||
|
//Remove a log file containing data from a week ago
|
||||||
|
require("Storage").erase(logFileName);
|
||||||
|
require("Storage").write(previousWriteLogName, currentWriteDay);
|
||||||
|
}
|
||||||
|
|
||||||
|
var bcLogFileA = require("Storage").open(logFileName, "a");
|
||||||
|
if (bcLogFileA) {
|
||||||
|
console.log([getTime().toFixed(0), E.getBattery(), E.getTemperature(), getEnabledConsumersValue()].join(","));
|
||||||
|
bcLogFileA.write([[getTime().toFixed(0), E.getBattery(), E.getTemperature(), getEnabledConsumersValue()].join(",")].join(",")+"\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Called by the heart app to reload settings and decide what's
|
||||||
|
function reload() {
|
||||||
|
WIDGETS["batchart"].width = 24;
|
||||||
|
|
||||||
|
recordingInterval = setInterval(logBatteryData, recordingInterval10Min);
|
||||||
|
|
||||||
|
logBatteryData();
|
||||||
|
}
|
||||||
|
|
||||||
// add the widget
|
// add the widget
|
||||||
WIDGETS["batchart"]={area:"tl",width:24,draw:draw,reload:function() {
|
WIDGETS["batchart"]={area:"tl",width:24,draw:draw,reload:function() {
|
||||||
reload();
|
reload();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue