mirror of https://github.com/espruino/BangleApps
[sleeplog] Improve README, remove convertOldLog
parent
361efb6c25
commit
30abb6706b
|
@ -7,4 +7,4 @@
|
|||
0.10: Complete rework off this app!
|
||||
0.10beta: Add interface.html to view saved log data, add "View log" function for debugging log, send data for gadgetbridge, change caching for global getStats
|
||||
0.11: Prevent module not found error
|
||||
0.12: Execute functions in `sleeplog.onChange` object on a status change
|
||||
0.12: Improve README, option to add functions triggered by status changes or time periods, remove old log (<0.10) conversion
|
|
@ -24,10 +24,20 @@ Logfiles are not removed on un-/reinstall to prevent data loss.
|
|||
|
||||
|
||||
---
|
||||
### App Usage
|
||||
### Main App Usage
|
||||
---
|
||||
|
||||
#### On the main app screen:
|
||||
#### View:
|
||||
| Status | Color | Height |
|
||||
|-------------|:------:|----------:|
|
||||
| unknown | black | 0% |
|
||||
| not worn | red | 40% |
|
||||
| awake | green | 60% |
|
||||
| light sleep | cyan | 80% |
|
||||
| deep sleep | blue | 100% |
|
||||
| consecutive | violet | as status |
|
||||
|
||||
#### Controls:
|
||||
- __swipe left & right__
|
||||
to change the displayed day
|
||||
- __touch the "title"__ (e.g. `Night to Fri 20/05/2022`)
|
||||
|
@ -40,7 +50,11 @@ Logfiles are not removed on un-/reinstall to prevent data loss.
|
|||
- __use back button widget__ (upper left corner)
|
||||
exit the app
|
||||
|
||||
#### Inside the settings:
|
||||
|
||||
---
|
||||
### Settings Usage
|
||||
---
|
||||
|
||||
- __Thresholds__ submenu
|
||||
Changes take effect from now on, not retrospective!
|
||||
- __Max Awake__ | maximal awake duration
|
||||
|
@ -198,7 +212,7 @@ The passed data object has the following properties:
|
|||
Please leave requests and bug reports by raising an issue at [github.com/storm64/BangleApps](https://github.com/storm64/BangleApps) (or send me a [mail](mailto:banglejs@storm64.de)).
|
||||
|
||||
#### Creator
|
||||
Storm64 ([Mail](mailto:banglejs@storm64.de), [github](https://github.com/storm64))
|
||||
Storm64 ([mail](mailto:banglejs@storm64.de), [github](https://github.com/storm64))
|
||||
|
||||
#### Contributors
|
||||
myxor ([github](https://github.com/myxor))
|
||||
|
|
|
@ -149,14 +149,6 @@ exports = {
|
|||
|
||||
// define move log function, move StorageFile content into files seperated by fortnights
|
||||
moveLog: function(force) {
|
||||
/** convert old logfile (< v0.10) if present **/
|
||||
if (require("Storage").list("sleeplog.log", {
|
||||
sf: false
|
||||
}).length) {
|
||||
convertOldLog();
|
||||
}
|
||||
/** may be removed in later versions **/
|
||||
|
||||
// first day of this fortnight period
|
||||
var thisFirstDay = this.fnToMs(this.msToFn(Date.now()));
|
||||
|
||||
|
@ -384,82 +376,5 @@ exports = {
|
|||
"unknown,not worn,awake,light sleep,deep sleep".split(",")[entry[1]].padEnd(12) +
|
||||
"for" + (duration + "min").padStart(8));
|
||||
});
|
||||
},
|
||||
|
||||
/** convert old (< v0.10) to new logfile data **/
|
||||
convertOldLog: function() {
|
||||
// read old logfile
|
||||
var oldLog = require("Storage").read("sleeplog.log") || "";
|
||||
// decode data if needed
|
||||
if (!oldLog.startsWith("[")) oldLog = atob(oldLog);
|
||||
// delete old logfile and return if it is empty or corrupted
|
||||
if (!oldLog.startsWith("[[") || !oldLog.endsWith("]]")) {
|
||||
require("Storage").erase("sleeplog.log");
|
||||
return;
|
||||
}
|
||||
|
||||
// transform into StorageFile and clear oldLog to have more free ram accessable
|
||||
require("Storage").open("sleeplog_old.log", "w").write(JSON.parse(oldLog).reverse().join("\n"));
|
||||
oldLog = undefined;
|
||||
|
||||
// calculate fortnight from now
|
||||
var fnOfNow = this.msToFn(Date.now());
|
||||
|
||||
// open StorageFile with old log data
|
||||
var file = require("Storage").open("sleeplog_old.log", "r");
|
||||
// define active fortnight and file cache
|
||||
var activeFn = true;
|
||||
var fileCache = [];
|
||||
// loop through StorageFile entries
|
||||
while (activeFn) {
|
||||
// define fortnight for this entry
|
||||
var thisFn = false;
|
||||
// cache new line
|
||||
var line = file.readLine();
|
||||
// check if line is filled
|
||||
if (line) {
|
||||
// parse line
|
||||
line = line.substr(0, 15).split(",").map(e => parseInt(e));
|
||||
// calculate fortnight for this entry
|
||||
thisFn = this.msToFn(line[0]);
|
||||
// convert timestamp into 10min steps
|
||||
line[0] = line[0] / 6E5 | 0;
|
||||
// set consecutive to unknown
|
||||
line.push(0);
|
||||
}
|
||||
// check if active fortnight and file cache is set, fortnight has changed and
|
||||
// active fortnight is not fortnight from now
|
||||
if (activeFn && fileCache.length && activeFn !== thisFn && activeFn !== fnOfNow) {
|
||||
// write file cache into new file according to fortnight
|
||||
require("Storage").writeJSON("sleeplog_" + activeFn + ".log", fileCache);
|
||||
// clear file cache
|
||||
fileCache = [];
|
||||
}
|
||||
// add line to file cache if it is filled
|
||||
if (line) fileCache.push(line);
|
||||
// set active fortnight
|
||||
activeFn = thisFn;
|
||||
}
|
||||
// check if entries are leftover
|
||||
if (fileCache.length) {
|
||||
// format fileCache entries into a string
|
||||
fileCache = fileCache.map(e => e.join(",")).join("\n");
|
||||
// read complete new log StorageFile as string
|
||||
file = require("Storage").open("sleeplog.log", "r");
|
||||
var newLogString = file.read(file.getLength());
|
||||
// add entries at the beginning of the new log string
|
||||
newLogString = fileCache + "\n" + newLogString;
|
||||
// rewrite new log StorageFile
|
||||
require("Storage").open("sleeplog.log", "w").write(newLogString);
|
||||
}
|
||||
|
||||
// free ram
|
||||
file = undefined;
|
||||
fileCache = undefined;
|
||||
|
||||
// clean up old files
|
||||
require("Storage").erase("sleeplog.log");
|
||||
require("Storage").open("sleeplog_old.log", "w").erase();
|
||||
}
|
||||
/** may be removed in later versions **/
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue