Recorder - 0.26: Now record filename based on date

master
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) 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.24: Can now specify `setRecording(true, {force:...` to not show a menu
0.25: Widget now has `isRecording()` for retrieving recording status. 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) { function getTrackNumber(filename) {
var trackNum = 0; var trackNum = 0;
var matches = filename.match(/^recorder\.log(.*)\.csv$/); var matches = filename.match(/^recorder\.log(.*)\.csv$/);
if (matches) { if (matches) return matches[1];
trackNum = parseInt(matches[1]||0); return 0;
}
return trackNum;
} }
function showMainMenu() { function showMainMenu() {
@ -62,23 +60,13 @@ function showMainMenu() {
WIDGETS["recorder"].setRecording(v).then(function() { WIDGETS["recorder"].setRecording(v).then(function() {
//print("Record start Complete"); //print("Record start Complete");
loadSettings(); loadSettings();
print("Recording: "+settings.recording); //print("Recording: "+settings.recording);
showMainMenu(); showMainMenu();
}); });
}, 1); }, 1);
} }
}, },
/*LANG*/'File #': { /*LANG*/'File' : {value:getTrackNumber(settings.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*/'View Tracks': ()=>{viewTracks();}, /*LANG*/'View Tracks': ()=>{viewTracks();},
/*LANG*/'Time Period': { /*LANG*/'Time Period': {
value: settings.period||10, value: settings.period||10,
@ -110,7 +98,7 @@ function viewTracks() {
var found = false; var found = false;
require("Storage").list(/^recorder\.log.*\.csv$/,{sf:true}).forEach(filename=>{ require("Storage").list(/^recorder\.log.*\.csv$/,{sf:true}).forEach(filename=>{
found = true; found = true;
menu[/*LANG*/"Track "+getTrackNumber(filename)] = ()=>viewTrack(filename,false); menu[/*LANG*/getTrackNumber(filename)] = ()=>viewTrack(filename,false);
}); });
if (!found) if (!found)
menu[/*LANG*/"No Tracks found"] = function(){}; menu[/*LANG*/"No Tracks found"] = function(){};
@ -353,7 +341,7 @@ function viewTrack(filename, info) {
infc[i]++; infc[i]++;
} }
} else if (style=="Altitude") { } else if (style=="Altitude") {
title = /*LANG*/"Altitude (m)"; title = /*LANG*/"Altitude (m)";
var altIdx = info.fields.indexOf("Barometer Altitude"); var altIdx = info.fields.indexOf("Barometer Altitude");
if (altIdx<0) altIdx = info.fields.indexOf("Altitude"); if (altIdx<0) altIdx = info.fields.indexOf("Altitude");
while(l!==undefined) { while(l!==undefined) {

View File

@ -2,7 +2,7 @@
"id": "recorder", "id": "recorder",
"name": "Recorder", "name": "Recorder",
"shortName": "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.", "description": "Record GPS position, heart rate and more in the background, then download to your PC.",
"icon": "app.png", "icon": "app.png",
"tags": "tool,outdoors,gps,widget", "tags": "tool,outdoors,gps,widget",
@ -15,5 +15,8 @@
{"name":"recorder.wid.js","url":"widget.js"}, {"name":"recorder.wid.js","url":"widget.js"},
{"name":"recorder.settings.js","url":"settings.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 if (!options.force) { // if not forced, ask the question
g.reset(); // work around bug in 2v17 and earlier where bg color wasn't reset g.reset(); // work around bug in 2v17 and earlier where bg color wasn't reset
return E.showPrompt( return E.showPrompt(
/*LANG*/"Overwrite\nLog " + settings.file.match(/\d+/)[0] + "?", /*LANG*/"Overwrite\nLog " + settings.file.match(/^recorder\.log(.*)\.csv$/)[1] + "?",
{ title:/*LANG*/"Recorder", { title:/*LANG*/"Recorder",
buttons:{/*LANG*/"Yes":"overwrite",/*LANG*/"No":"cancel",/*LANG*/"New":"new",/*LANG*/"Append":"append"} buttons:{/*LANG*/"Yes":"overwrite",/*LANG*/"No":"cancel",/*LANG*/"New":"new",/*LANG*/"Append":"append"}
}).then(selection=>{ }).then(selection=>{
@ -262,11 +262,13 @@
// wipe the file // wipe the file
require("Storage").open(settings.file,"r").erase(); require("Storage").open(settings.file,"r").erase();
} else if (options.force=="new") { } else if (options.force=="new") {
// new file - find the max log file number and add one // new file - use the current date
var maxNumber=0; var date=(new Date()).toISOString().substr(0,10).replace(/-/g,""), trackNo=10;
require("Storage").list(/recorder.log.*/).forEach( fn => maxNumber = Math.max(maxNumber, fn.match(/\d+/)[0]) ); var newFileName;
var newFileName = "recorder.log" + (maxNumber + 1) + ".csv"; do { // while a file exists, add one to the letter after the date
// FIXME: use date? newFileName = "recorder.log" + date + trackNo.toString(36) + ".csv";
trackNo++;
} while (require("Storage").list(newFileName).length);
settings.file = newFileName; settings.file = newFileName;
} else throw new Error("Unknown options.force, "+options.force); } else throw new Error("Unknown options.force, "+options.force);
} }