parent
e37b7c804a
commit
ef74b85ef9
|
|
@ -26,11 +26,12 @@ function menuStepCount() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function menuDistance() {
|
function menuDistance() {
|
||||||
|
const distMult = 1*require("locale").distance(settings.strideLength, 2); // hackish: this removes the distance suffix, e.g. 'm'
|
||||||
E.showMenu({
|
E.showMenu({
|
||||||
"": { title:/*LANG*/"Distance" },
|
"": { title:/*LANG*/"Distance" },
|
||||||
/*LANG*/"< Back": () => menuStepCount(),
|
/*LANG*/"< Back": () => menuStepCount(),
|
||||||
/*LANG*/"per hour": () => stepsPerHour(menuDistance, settings.strideLength),
|
/*LANG*/"per hour": () => stepsPerHour(menuDistance, distMult),
|
||||||
/*LANG*/"per day": () => stepsPerDay(menuDistance, settings.strideLength)
|
/*LANG*/"per day": () => stepsPerDay(menuDistance, distMult)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -57,6 +58,10 @@ function stepsPerHour(back, mult) {
|
||||||
current_selection = "stepsPerHour";
|
current_selection = "stepsPerHour";
|
||||||
var data = new Uint16Array(24);
|
var data = new Uint16Array(24);
|
||||||
require("health").readDay(new Date(), h=>data[h.hr]+=h.steps);
|
require("health").readDay(new Date(), h=>data[h.hr]+=h.steps);
|
||||||
|
if (mult !== undefined) {
|
||||||
|
// Calculate distance from steps
|
||||||
|
data.forEach((d, i) => data[i] = d*mult+0.5);
|
||||||
|
}
|
||||||
setButton(back, mult);
|
setButton(back, mult);
|
||||||
barChart(/*LANG*/"HOUR", data, mult);
|
barChart(/*LANG*/"HOUR", data, mult);
|
||||||
}
|
}
|
||||||
|
|
@ -66,6 +71,10 @@ function stepsPerDay(back, mult) {
|
||||||
current_selection = "stepsPerDay";
|
current_selection = "stepsPerDay";
|
||||||
var data = new Uint16Array(32);
|
var data = new Uint16Array(32);
|
||||||
require("health").readDailySummaries(new Date(), h=>data[h.day]+=h.steps);
|
require("health").readDailySummaries(new Date(), h=>data[h.day]+=h.steps);
|
||||||
|
if (mult !== undefined) {
|
||||||
|
// Calculate distance from steps
|
||||||
|
data.forEach((d, i) => data[i] = d*mult+0.5);
|
||||||
|
}
|
||||||
setButton(back, mult);
|
setButton(back, mult);
|
||||||
barChart(/*LANG*/"DAY", data, mult);
|
barChart(/*LANG*/"DAY", data, mult);
|
||||||
drawHorizontalLine(settings.stepGoal * (mult || 1));
|
drawHorizontalLine(settings.stepGoal * (mult || 1));
|
||||||
|
|
@ -80,7 +89,7 @@ function hrmPerHour() {
|
||||||
data[h.hr]+=h.bpm;
|
data[h.hr]+=h.bpm;
|
||||||
if (h.bpm) cnt[h.hr]++;
|
if (h.bpm) cnt[h.hr]++;
|
||||||
});
|
});
|
||||||
data.forEach((d,i)=>data[i] = d/cnt[i]);
|
data.forEach((d,i)=>data[i] = d/cnt[i]+0.5);
|
||||||
setButton(menuHRM);
|
setButton(menuHRM);
|
||||||
barChart(/*LANG*/"HOUR", data);
|
barChart(/*LANG*/"HOUR", data);
|
||||||
}
|
}
|
||||||
|
|
@ -94,7 +103,7 @@ function hrmPerDay() {
|
||||||
data[h.day]+=h.bpm;
|
data[h.day]+=h.bpm;
|
||||||
if (h.bpm) cnt[h.day]++;
|
if (h.bpm) cnt[h.day]++;
|
||||||
});
|
});
|
||||||
data.forEach((d,i)=>data[i] = d/cnt[i]);
|
data.forEach((d,i)=>data[i] = d/cnt[i]+0.5);
|
||||||
setButton(menuHRM);
|
setButton(menuHRM);
|
||||||
barChart(/*LANG*/"DAY", data);
|
barChart(/*LANG*/"DAY", data);
|
||||||
}
|
}
|
||||||
|
|
@ -108,7 +117,7 @@ function movementPerHour() {
|
||||||
data[h.hr]+=h.movement;
|
data[h.hr]+=h.movement;
|
||||||
cnt[h.hr]++;
|
cnt[h.hr]++;
|
||||||
});
|
});
|
||||||
data.forEach((d,i)=>data[i] = d/cnt[i]);
|
data.forEach((d,i)=>data[i] = d/cnt[i]+0.5);
|
||||||
setButton(menuMovement);
|
setButton(menuMovement);
|
||||||
barChart(/*LANG*/"HOUR", data);
|
barChart(/*LANG*/"HOUR", data);
|
||||||
}
|
}
|
||||||
|
|
@ -122,7 +131,7 @@ function movementPerDay() {
|
||||||
data[h.day]+=h.movement;
|
data[h.day]+=h.movement;
|
||||||
cnt[h.day]++;
|
cnt[h.day]++;
|
||||||
});
|
});
|
||||||
data.forEach((d,i)=>data[i] = d/cnt[i]);
|
data.forEach((d,i)=>data[i] = d/cnt[i]+0.5);
|
||||||
setButton(menuMovement);
|
setButton(menuMovement);
|
||||||
barChart(/*LANG*/"DAY", data);
|
barChart(/*LANG*/"DAY", data);
|
||||||
}
|
}
|
||||||
|
|
@ -155,11 +164,7 @@ function get_data_length(arr) {
|
||||||
return nlen;
|
return nlen;
|
||||||
}
|
}
|
||||||
|
|
||||||
function barChart(label, dt, mult) {
|
function barChart(label, dt) {
|
||||||
if (mult !== undefined) {
|
|
||||||
// Calculate distance from steps
|
|
||||||
dt.forEach((val, i) => dt[i] = val*mult);
|
|
||||||
}
|
|
||||||
data_len = get_data_length(dt);
|
data_len = get_data_length(dt);
|
||||||
chart_index = Math.max(data_len - 5, -5); // choose initial index that puts the last day on the end
|
chart_index = Math.max(data_len - 5, -5); // choose initial index that puts the last day on the end
|
||||||
chart_max_datum = max(dt); // find highest bar, for scaling
|
chart_max_datum = max(dt); // find highest bar, for scaling
|
||||||
|
|
|
||||||
|
|
@ -54,6 +54,7 @@
|
||||||
value : settings.strideLength || 0.0,
|
value : settings.strideLength || 0.0,
|
||||||
min:0.01,
|
min:0.01,
|
||||||
step:0.01,
|
step:0.01,
|
||||||
|
format: v => require("locale").distance(v, 2),
|
||||||
onchange : v => {
|
onchange : v => {
|
||||||
settings.strideLength=v;
|
settings.strideLength=v;
|
||||||
setSettings();
|
setSettings();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue