ActivePedom 0.03
parent
5d3264e51e
commit
9d67877294
|
|
@ -1,8 +1,31 @@
|
||||||
(() => {
|
(() => {
|
||||||
|
|
||||||
|
//Graph module, as long as modules are not added by the app loader
|
||||||
|
Modules.addCached("graph",function(){exports.drawAxes=function(b,c,a){function h(a){return e+m*(a-t)/x}function l(a){return f+g-g*(a-n)/u}var k=a.padx||0,d=a.pady||0,t=-k,w=c.length+k-1,n=(void 0!==a.miny?a.miny:a.miny=c.reduce(function(a,b){return Math.min(a,b)},c[0]))-d;c=(void 0!==a.maxy?a.maxy:a.maxy=c.reduce(function(a,b){return Math.max(a,b)},c[0]))+d;a.gridy&&(d=a.gridy,n=d*Math.floor(n/d),c=d*Math.ceil(c/d));var e=a.x||0,f=a.y||0,m=a.width||b.getWidth()-(e+1),g=a.height||b.getHeight()-(f+1);a.axes&&(null!==a.ylabel&&
|
||||||
|
(e+=6,m-=6),null!==a.xlabel&&(g-=6));a.title&&(f+=6,g-=6);a.axes&&(b.drawLine(e,f,e,f+g),b.drawLine(e,f+g,e+m,f+g));a.title&&(b.setFontAlign(0,-1),b.drawString(a.title,e+m/2,f-6));var x=w-t,u=c-n;u||(u=1);if(a.gridx){b.setFontAlign(0,-1,0);var v=a.gridx;for(d=Math.ceil((t+k)/v)*v;d<=w-k;d+=v){var r=h(d),p=a.xlabel?a.xlabel(d):d;b.setPixel(r,f+g-1);var q=b.stringWidth(p)/2;null!==a.xlabel&&r>q&&b.getWidth()>r+q&&b.drawString(p,r,f+g+2)}}if(a.gridy)for(b.setFontAlign(0,0,1),d=n;d<=c;d+=a.gridy)k=l(d),
|
||||||
|
p=a.ylabel?a.ylabel(d):d,b.setPixel(e+1,k),q=b.stringWidth(p)/2,null!==a.ylabel&&k>q&&b.getHeight()>k+q&&b.drawString(p,e-5,k+1);b.setFontAlign(-1,-1,0);return{x:e,y:f,w:m,h:g,getx:h,gety:l}};exports.drawLine=function(b,c,a){a=a||{};a=exports.drawAxes(b,c,a);var h=!0,l;for(l in c)h?b.moveTo(a.getx(l),a.gety(c[l])):b.lineTo(a.getx(l),a.gety(c[l])),h=!1;return a};exports.drawBar=function(b,c,a){a=a||{};a.padx=1;a=exports.drawAxes(b,c,a);for(var h in c)b.fillRect(a.getx(h-.5)+1,a.gety(c[h]),a.getx(h+
|
||||||
|
.5)-1,a.gety(0));return a}});
|
||||||
|
|
||||||
const storage = require("Storage");
|
const storage = require("Storage");
|
||||||
|
const SETTINGS_FILE = 'activepedom.settings.json';
|
||||||
var history = 86400000; // 28800000=8h 43200000=12h //86400000=24h
|
var history = 86400000; // 28800000=8h 43200000=12h //86400000=24h
|
||||||
|
|
||||||
|
//return setting
|
||||||
|
function setting(key) {
|
||||||
|
//define default settings
|
||||||
|
const DEFAULTS = {
|
||||||
|
'cMaxTime' : 1100,
|
||||||
|
'cMinTime' : 240,
|
||||||
|
'stepThreshold' : 30,
|
||||||
|
'intervalResetActive' : 30000,
|
||||||
|
'stepSensitivity' : 80,
|
||||||
|
'stepGoal' : 10000,
|
||||||
|
'stepLength' : 75,
|
||||||
|
};
|
||||||
|
if (!settings) { loadSettings(); }
|
||||||
|
return (key in settings) ? settings[key] : DEFAULTS[key];
|
||||||
|
}
|
||||||
|
|
||||||
//Convert ms to time
|
//Convert ms to time
|
||||||
function getTime(t) {
|
function getTime(t) {
|
||||||
date = new Date(t);
|
date = new Date(t);
|
||||||
|
|
@ -58,8 +81,8 @@ function drawGraph() {
|
||||||
filename = filename = "activepedom-" + now.getFullYear() + month + now.getDate() + ".data";
|
filename = filename = "activepedom-" + now.getFullYear() + month + now.getDate() + ".data";
|
||||||
var csvFile = storage.open(filename, "r");
|
var csvFile = storage.open(filename, "r");
|
||||||
times = getArrayFromCSV(csvFile, 0);
|
times = getArrayFromCSV(csvFile, 0);
|
||||||
first = getDate(times[0]) + " " + getTime(times[0]);
|
first = getDate(times[0]) + " " + getTime(times[0]); //first entry in datafile
|
||||||
last = getDate (times[times.length-1]) + " " + getTime(times[times.length-1]);
|
last = getDate (times[times.length-1]) + " " + getTime(times[times.length-1]); //last entry in datafile
|
||||||
//free memory
|
//free memory
|
||||||
csvFile = undefined;
|
csvFile = undefined;
|
||||||
times = undefined;
|
times = undefined;
|
||||||
|
|
@ -67,21 +90,24 @@ function drawGraph() {
|
||||||
//steps
|
//steps
|
||||||
var csvFile = storage.open(filename, "r");
|
var csvFile = storage.open(filename, "r");
|
||||||
steps = getArrayFromCSV(csvFile, 1);
|
steps = getArrayFromCSV(csvFile, 1);
|
||||||
|
first = first + " " + steps[0] + "/" + setting('stepGoal');
|
||||||
|
last = last + " " + steps[steps.length-1] + "/" + setting('stepGoal');
|
||||||
|
|
||||||
//define y-axis grid labels
|
//define y-axis grid labels
|
||||||
stepsLastEntry = steps[steps.length-1];
|
stepsLastEntry = steps[steps.length-1];
|
||||||
if (stepsLastEntry < 1000) gridyValue = 100;
|
if (stepsLastEntry < 1000) gridyValue = 100;
|
||||||
if (stepsLastEntry >= 1000 && stepsLastEntry < 10000) gridyValue = 500;
|
if (stepsLastEntry >= 1000 && stepsLastEntry < 10000) gridyValue = 1000;
|
||||||
if (stepsLastEntry > 10000) gridyValue = 5000;
|
if (stepsLastEntry > 10000) gridyValue = 5000;
|
||||||
|
|
||||||
//draw
|
//draw
|
||||||
drawMenu();
|
drawMenu();
|
||||||
g.drawString("First: " + first, 40, 30);
|
g.drawString("First: " + first, 10, 30);
|
||||||
g.drawString(" Last: " + last, 40, 40);
|
g.drawString(" Last: " + last, 10, 40);
|
||||||
require("graph").drawLine(g, steps, {
|
require("graph").drawLine(g, steps, {
|
||||||
//title: "Steps Counted",
|
//title: "Steps Counted",
|
||||||
axes : true,
|
axes : true,
|
||||||
gridy : gridyValue,
|
gridy : gridyValue,
|
||||||
y : 50, //offset on screen
|
y : 60, //offset on screen
|
||||||
x : 5, //offset on screen
|
x : 5, //offset on screen
|
||||||
});
|
});
|
||||||
//free memory from big variables
|
//free memory from big variables
|
||||||
|
|
@ -128,6 +154,12 @@ setWatch(function() { //BTN4
|
||||||
setWatch(function() { //BTN5
|
setWatch(function() { //BTN5
|
||||||
}, BTN5, {edge:"rising", debounce:50, repeat:true});
|
}, BTN5, {edge:"rising", debounce:50, repeat:true});
|
||||||
|
|
||||||
|
//load settings
|
||||||
|
let settings;
|
||||||
|
function loadSettings() {
|
||||||
|
settings = storage.readJSON(SETTINGS_FILE, 1) || {};
|
||||||
|
}
|
||||||
|
|
||||||
drawMenu();
|
drawMenu();
|
||||||
|
|
||||||
})();
|
})();
|
||||||
|
|
@ -35,16 +35,24 @@
|
||||||
now = new Date();
|
now = new Date();
|
||||||
month = now.getMonth() + 1;
|
month = now.getMonth() + 1;
|
||||||
if (month < 10) month = "0" + month;
|
if (month < 10) month = "0" + month;
|
||||||
filename = filename = "activepedom-" + now.getFullYear() + month + now.getDate() + ".data";
|
filename = filename = "activepedom" + now.getFullYear() + month + now.getDate() + ".data";
|
||||||
dataFile = s.open(filename,"a");
|
dataFile = s.open(filename,"a");
|
||||||
if (dataFile) dataFile.write([
|
if (dataFile) {
|
||||||
now.getTime(),
|
if (dataFile.getLength() == 0) {
|
||||||
stepsCounted,
|
stepsToWrite = 0;
|
||||||
active,
|
}
|
||||||
stepsTooShort,
|
else {
|
||||||
stepsTooLong,
|
stepsToWrite = stepsCounted;
|
||||||
stepsOutsideTime,
|
}
|
||||||
].join(",")+"\n");
|
dataFile.write([
|
||||||
|
now.getTime(),
|
||||||
|
stepsToWrite,
|
||||||
|
active,
|
||||||
|
stepsTooShort,
|
||||||
|
stepsTooLong,
|
||||||
|
stepsOutsideTime,
|
||||||
|
].join(",")+"\n");
|
||||||
|
}
|
||||||
dataFile = undefined;
|
dataFile = undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue