myprofile: Add birthday setting

pull/3120/head
Erik Andresen 2023-12-12 19:30:46 +01:00
parent 799c0b4e89
commit 16cc803b86
2 changed files with 105 additions and 40 deletions

View File

@ -4,12 +4,14 @@ Configure your personal profile. All settings are optional and are only stored o
## Available settings ## Available settings
| Setting | Description | Displayed in | Stored in | Default value | How to measure | | Setting | Description | Displayed in | Stored in | Default value | How to measure |
| ------------- | ------------------------------- | ------------------- | --------- | ------------- | ----------------------------------------------------------------- | | ------------- | ------------------------------- | ------------------- | ------------ | ------------- | ----------------------------------------------------------------- |
| HR max | maximum heart rate | BPM | BPM | 60 | Use maximum value when exercising.<br/> If unsure set to 220-age. | | Birthday | Used to calculate age | year, month, day | 'YYYY-MM-DD' | 01.01.1970 | - |
| HR min | minimum heart rate | BPM | BPM | 200 | Measure your heart rate after waking up | | HR max | maximum heart rate | BPM | BPM | 60 | Use maximum value when exercising.<br/> If unsure set to 220-age. |
| Stride length | distance traveled with one step | local length unit | meter | 0 (=not set) | Walk 10 steps and divide the travelled distance by 10 | | HR min | minimum heart rate | BPM | BPM | 200 | Measure your heart rate after waking up |
| Stride length | distance traveled with one step | local length unit | meter | 0 (=not set) | Walk 10 steps and divide the travelled distance by 10 |
## Developer notes ## Developer notes
Feel free to add additional settings - Feel free to add additional settings.
- For values without reasonable defaults never assume that a value is set. Always check the value before using it.

View File

@ -5,47 +5,110 @@
minHrm: 60, minHrm: 60,
maxHrm: 200, maxHrm: 200,
strideLength: 0, // 0 = not set strideLength: 0, // 0 = not set
birthday: '1970-01-01',
}, require('Storage').readJSON(FILE, true) || {}); }, require('Storage').readJSON(FILE, true) || {});
function writeProfile() { function writeProfile() {
require('Storage').writeJSON(FILE, myprofile); require('Storage').writeJSON(FILE, myprofile);
} }
// Show the menu const ageMenu = () => {
E.showMenu({ const date = new Date(myprofile.birthday);
"" : { "title" : /*LANG*/"My Profile" },
"< Back" : () => back(), E.showMenu({
"" : { "title" : /*LANG*/"Birthday" },
/*LANG*/'HR max': { "< Back" : () => {
format: v => /*LANG*/`${v} BPM`, if (date != new Date(myprofile.birthday)) {
value: myprofile.maxHrm, if (date > new Date()) {
min: 30, max: 220, E.showPrompt(/*LANG*/"Birthday must not be in future!", {
onchange: v => { buttons : {"Ok":true},
myprofile.maxHrm = v; }).then(() => ageMenu());
writeProfile(); } else {
} // Birthday changed
}, const age = (new Date()).getFullYear() - date.getFullYear();
const newMaxHRM = 220-age;
/*LANG*/'HR min': { E.showPrompt(/*LANG*/`Set HR max to ${newMaxHRM} calculated from age?`).then(function(v) {
format: v => /*LANG*/`${v} BPM`, myprofile.birthday = date.getFullYear() + "-" + (date.getMonth() + 1).toString().padStart(2, '0') + "-" + date.getDate().toString().padStart(2, '0');
value: myprofile.minHrm, if (v) {
min: 30, max: 220, myprofile.maxHrm = newMaxHRM;
onchange: v => { writeProfile();
myprofile.minHrm = v; }
writeProfile(); mainMenu();
} });
}, }
} else {
/*LANG*/"Stride length": { mainMenu();
value: myprofile.strideLength, }
min:0.00,
step:0.01,
format: v => v ? require("locale").distance(v, 2) : '-',
onchange: v => {
myprofile.strideLength=v;
writeProfile();
}, },
},
}); /*LANG*/"Day": {
value: date ? date.getDate() : null,
min: 1,
max: 31,
wrap: true,
onchange: v => {
date.setDate(v);
}
},
/*LANG*/"Month": {
value: date ? date.getMonth() + 1 : null,
format: v => require("date_utils").month(v),
onchange: v => {
date.setMonth((v+11)%12);
}
},
/*LANG*/"Year": {
value: date ? date.getFullYear() : null,
min: 1900,
max: (new Date()).getFullYear(),
onchange: v => {
date.setFullYear(v);
}
},
});
};
const mainMenu = () => {
E.showMenu({
"" : { "title" : /*LANG*/"My Profile" },
"< Back" : () => back(),
/*LANG*/"Birthday" : () => ageMenu(),
/*LANG*/'HR max': {
format: v => /*LANG*/`${v} BPM`,
value: myprofile.maxHrm,
min: 30, max: 220,
onchange: v => {
myprofile.maxHrm = v;
writeProfile();
}
},
/*LANG*/'HR min': {
format: v => /*LANG*/`${v} BPM`,
value: myprofile.minHrm,
min: 30, max: 220,
onchange: v => {
myprofile.minHrm = v;
writeProfile();
}
},
/*LANG*/"Stride length": {
value: myprofile.strideLength,
min:0.00,
step:0.01,
format: v => v ? require("locale").distance(v, 2) : '-',
onchange: v => {
myprofile.strideLength=v;
writeProfile();
},
},
});
};
mainMenu();
}) })