mirror of https://github.com/espruino/BangleApps
sleepphasealarm: Fix json dates
Fix handle dates saved as object with millisecondspull/3277/head
parent
cdbe4aa3ee
commit
7503254033
|
@ -19,3 +19,4 @@
|
||||||
Add plot logged data to settings
|
Add plot logged data to settings
|
||||||
0.15: Convert Yes/No On/Off in settings to checkboxes
|
0.15: Convert Yes/No On/Off in settings to checkboxes
|
||||||
0.16: Fix Keep alarm enabled inverted settings
|
0.16: Fix Keep alarm enabled inverted settings
|
||||||
|
0.17: Fix handle dates saved as object with milliseconds
|
||||||
|
|
|
@ -136,7 +136,7 @@ function buzz() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function addLog(time, type) {
|
function addLog(time, type) {
|
||||||
logs.push({time: time, type: type});
|
logs.push({time: time.toISOString(), type: type});
|
||||||
if (logs.length > 1) { // Do not write if there is only one state
|
if (logs.length > 1) { // Do not write if there is only one state
|
||||||
require("Storage").writeJSON(CONFIGFILE, config);
|
require("Storage").writeJSON(CONFIGFILE, config);
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,7 +35,7 @@ function getData() {
|
||||||
logs.forEach((log, i) => {
|
logs.forEach((log, i) => {
|
||||||
const timeStr = log.filter(entry => entry.type === "alarm")[0]?.time;
|
const timeStr = log.filter(entry => entry.type === "alarm")[0]?.time;
|
||||||
if (timeStr) {
|
if (timeStr) {
|
||||||
const date = new Date(timeStr);
|
const date = new Date(typeof timeStr === 'string' ? timeStr : timeStr.ms);
|
||||||
let option = document.createElement("option");
|
let option = document.createElement("option");
|
||||||
option.text = date.toLocaleDateString();
|
option.text = date.toLocaleDateString();
|
||||||
option.value = i;
|
option.value = i;
|
||||||
|
@ -89,10 +89,10 @@ function getData() {
|
||||||
|
|
||||||
select.onchange = () => {
|
select.onchange = () => {
|
||||||
const log = logs[select.value];
|
const log = logs[select.value];
|
||||||
chart.data.labels = log.map(entry => new Date(entry.time));
|
chart.data.labels = log.map(entry => new Date(typeof entry.time === 'string' ? entry.time : entry.time.ms));
|
||||||
chart.data.datasets[0].data = log.map(entry => yTicks.indexOf(entry.type));
|
chart.data.datasets[0].data = log.map(entry => yTicks.indexOf(entry.type));
|
||||||
const timeStr = log.filter(entry => entry.type === "alarm")[0]?.time;
|
const timeStr = log.filter(entry => entry.type === "alarm")[0]?.time;
|
||||||
chart.data.datasets[0].label = new Date(timeStr).toLocaleDateString();
|
chart.data.datasets[0].label = new Date(typeof timeStr === 'string' ? timeStr : timeStr.ms).toLocaleDateString();
|
||||||
chart.update();
|
chart.update();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
"id": "sleepphasealarm",
|
"id": "sleepphasealarm",
|
||||||
"name": "SleepPhaseAlarm",
|
"name": "SleepPhaseAlarm",
|
||||||
"shortName": "SleepPhaseAlarm",
|
"shortName": "SleepPhaseAlarm",
|
||||||
"version": "0.16",
|
"version": "0.17",
|
||||||
"description": "Uses the accelerometer to estimate sleep and wake states with the principle of Estimation of Stationary Sleep-segments (ESS, see https://ubicomp.eti.uni-siegen.de/home/datasets/ichi14/index.html.en). This app will read the next alarm from the alarm application and will wake you up to 30 minutes early at the best guessed time when you are almost already awake.",
|
"description": "Uses the accelerometer to estimate sleep and wake states with the principle of Estimation of Stationary Sleep-segments (ESS, see https://ubicomp.eti.uni-siegen.de/home/datasets/ichi14/index.html.en). This app will read the next alarm from the alarm application and will wake you up to 30 minutes early at the best guessed time when you are almost already awake.",
|
||||||
"icon": "app.png",
|
"icon": "app.png",
|
||||||
"tags": "tool,alarm",
|
"tags": "tool,alarm",
|
||||||
|
|
|
@ -16,8 +16,8 @@
|
||||||
function draw(log) {
|
function draw(log) {
|
||||||
const step = 10*60*1000; // resolution 10min
|
const step = 10*60*1000; // resolution 10min
|
||||||
const yTicks = ["sleep", "awake", "alarm"];
|
const yTicks = ["sleep", "awake", "alarm"];
|
||||||
const starttime = new Date(log[0].time);
|
const starttime = dateFromJson(log[0].time);
|
||||||
const endtime = new Date(log[log.length-1].time);
|
const endtime = dateFromJson(log[log.length-1].time);
|
||||||
|
|
||||||
let logidx = 0;
|
let logidx = 0;
|
||||||
let curtime = starttime;
|
let curtime = starttime;
|
||||||
|
@ -29,7 +29,7 @@
|
||||||
if (logtime === undefined || curtime > logtime) {
|
if (logtime === undefined || curtime > logtime) {
|
||||||
curval = yTicks.indexOf(log[logidx].type);
|
curval = yTicks.indexOf(log[logidx].type);
|
||||||
logidx++;
|
logidx++;
|
||||||
logtime = new Date(log[logidx].time);
|
logtime = dateFromJson(log[logidx].time);
|
||||||
}
|
}
|
||||||
|
|
||||||
data[i++] = curval;
|
data[i++] = curval;
|
||||||
|
@ -70,8 +70,8 @@
|
||||||
|
|
||||||
const logs = config.logs.filter(log => log != null && log.filter(entry => entry.type === "alarm").length > 0);
|
const logs = config.logs.filter(log => log != null && log.filter(entry => entry.type === "alarm").length > 0);
|
||||||
logs.sort(function(a, b) { // sort by alarm date desc
|
logs.sort(function(a, b) { // sort by alarm date desc
|
||||||
const adate = new Date(a.filter(entry => entry.type === "alarm")[0].time);
|
const adate = dateFromJson(a.filter(entry => entry.type === "alarm")[0].time);
|
||||||
const bdate = new Date(b.filter(entry => entry.type === "alarm")[0].time);
|
const bdate = dateFromJson(b.filter(entry => entry.type === "alarm")[0].time);
|
||||||
return bdate - adate;
|
return bdate - adate;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -79,12 +79,16 @@
|
||||||
menu[""] = { title: /*LANG*/"Select day" };
|
menu[""] = { title: /*LANG*/"Select day" };
|
||||||
menu["< Back"] = () => settingsmenu();
|
menu["< Back"] = () => settingsmenu();
|
||||||
logs.forEach((log, i) => {
|
logs.forEach((log, i) => {
|
||||||
const date = new Date(log.filter(entry => entry.type === "alarm")[0].time);
|
const date = dateFromJson(log.filter(entry => entry.type === "alarm")[0].time);
|
||||||
menu[require("locale").date(date, 1)] = () => { E.showMenu(); draw(log); };
|
menu[require("locale").date(date, 1)] = () => { E.showMenu(); draw(log); };
|
||||||
});
|
});
|
||||||
E.showMenu(menu);
|
E.showMenu(menu);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function dateFromJson(o) {
|
||||||
|
return new Date(typeof o === 'string' ? o : o.ms);
|
||||||
|
}
|
||||||
|
|
||||||
function settingsmenu() {
|
function settingsmenu() {
|
||||||
// Show the menu
|
// Show the menu
|
||||||
E.showMenu({
|
E.showMenu({
|
||||||
|
|
Loading…
Reference in New Issue