using filenames based on date

pull/2798/head
Gordon Williams 2023-06-05 09:30:42 +01:00
parent c1f2ca5b78
commit a81c367827
4 changed files with 17 additions and 26 deletions

View File

@ -29,4 +29,5 @@
0.23: Add graphing for HRM, fix some other graphs
Altitude graphing now uses barometer altitude if it exists
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: 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(){};
@ -353,7 +341,7 @@ function viewTrack(filename, info) {
infc[i]++;
}
} else if (style=="Altitude") {
title = /*LANG*/"Altitude (m)";
title = /*LANG*/"Altitude (m)";
var altIdx = info.fields.indexOf("Barometer Altitude");
if (altIdx<0) altIdx = info.fields.indexOf("Altitude");
while(l!==undefined) {

View File

@ -2,7 +2,7 @@
"id": "recorder",
"name": "Recorder",
"shortName": "Recorder",
"version": "0.24",
"version": "0.25",
"description": "Record GPS position, heart rate and more in the background, then download to your PC.",
"icon": "app.png",
"tags": "tool,outdoors,gps,widget",

View File

@ -244,7 +244,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=>{
@ -260,11 +260,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);
}