Recorder - 0.26: Now record filename based on date

pull/2798/head
Gordon Williams 2023-06-06 11:04:26 +01:00
commit 2645cbe3f3
4 changed files with 20 additions and 26 deletions

View File

@ -31,3 +31,4 @@
plotTrack in widget allows track to be drawn in the background (doesn't block execution)
0.24: Can now specify `setRecording(true, {force:...` to not show a menu
0.25: Widget now has `isRecording()` for retrieving recording status.
0.26: Now record filename based on date

View File

@ -33,10 +33,8 @@ function updateSettings() {
function getTrackNumber(filename) {
var trackNum = 0;
var matches = filename.match(/^recorder\.log(.*)\.csv$/);
if (matches) {
trackNum = parseInt(matches[1]||0);
}
return trackNum;
if (matches) return matches[1];
return 0;
}
function showMainMenu() {
@ -62,23 +60,13 @@ function showMainMenu() {
WIDGETS["recorder"].setRecording(v).then(function() {
//print("Record start Complete");
loadSettings();
print("Recording: "+settings.recording);
//print("Recording: "+settings.recording);
showMainMenu();
});
}, 1);
}
},
/*LANG*/'File #': {
value: getTrackNumber(settings.file),
min: 0,
max: 99,
step: 1,
onchange: v => {
settings.recording = false; // stop recording if we change anything
settings.file = "recorder.log"+v+".csv";
updateSettings();
}
},
/*LANG*/'File' : {value:getTrackNumber(settings.file)},
/*LANG*/'View Tracks': ()=>{viewTracks();},
/*LANG*/'Time Period': {
value: settings.period||10,
@ -110,7 +98,7 @@ function viewTracks() {
var found = false;
require("Storage").list(/^recorder\.log.*\.csv$/,{sf:true}).forEach(filename=>{
found = true;
menu[/*LANG*/"Track "+getTrackNumber(filename)] = ()=>viewTrack(filename,false);
menu[/*LANG*/getTrackNumber(filename)] = ()=>viewTrack(filename,false);
});
if (!found)
menu[/*LANG*/"No Tracks found"] = function(){};

View File

@ -2,7 +2,7 @@
"id": "recorder",
"name": "Recorder",
"shortName": "Recorder",
"version": "0.25",
"version": "0.26",
"description": "Record GPS position, heart rate and more in the background, then download to your PC.",
"icon": "app.png",
"tags": "tool,outdoors,gps,widget",
@ -15,5 +15,8 @@
{"name":"recorder.wid.js","url":"widget.js"},
{"name":"recorder.settings.js","url":"settings.js"}
],
"data": [{"name":"recorder.json","url":"app-settings.json"},{"wildcard":"recorder.log?.csv","storageFile":true}]
"data": [
{"name":"recorder.json","url":"app-settings.json"},
{"wildcard":"recorder.log?.csv","storageFile":true}
]
}

View File

@ -246,7 +246,7 @@
if (!options.force) { // if not forced, ask the question
g.reset(); // work around bug in 2v17 and earlier where bg color wasn't reset
return E.showPrompt(
/*LANG*/"Overwrite\nLog " + settings.file.match(/\d+/)[0] + "?",
/*LANG*/"Overwrite\nLog " + settings.file.match(/^recorder\.log(.*)\.csv$/)[1] + "?",
{ title:/*LANG*/"Recorder",
buttons:{/*LANG*/"Yes":"overwrite",/*LANG*/"No":"cancel",/*LANG*/"New":"new",/*LANG*/"Append":"append"}
}).then(selection=>{
@ -262,11 +262,13 @@
// wipe the file
require("Storage").open(settings.file,"r").erase();
} else if (options.force=="new") {
// new file - find the max log file number and add one
var maxNumber=0;
require("Storage").list(/recorder.log.*/).forEach( fn => maxNumber = Math.max(maxNumber, fn.match(/\d+/)[0]) );
var newFileName = "recorder.log" + (maxNumber + 1) + ".csv";
// FIXME: use date?
// new file - use the current date
var date=(new Date()).toISOString().substr(0,10).replace(/-/g,""), trackNo=10;
var newFileName;
do { // while a file exists, add one to the letter after the date
newFileName = "recorder.log" + date + trackNo.toString(36) + ".csv";
trackNo++;
} while (require("Storage").list(newFileName).length);
settings.file = newFileName;
} else throw new Error("Unknown options.force, "+options.force);
}