|
@@ -143,19 +143,19 @@ int gymTrackerStatus(Arena *arena, list<string> args) { |
|
|
GymLogDbParsed *db = parseDb(arena, os_readEntireFile(arena, DB_FILE_LOCATION)); |
|
|
GymLogDbParsed *db = parseDb(arena, os_readEntireFile(arena, DB_FILE_LOCATION)); |
|
|
|
|
|
|
|
|
Timestamp startTs = {0}; |
|
|
Timestamp startTs = {0}; |
|
|
int numDays = 1; |
|
|
|
|
|
|
|
|
ParsePositiveIntResult numDays = {1, false}; |
|
|
bool showAll = args.length == 1 && strEql(args.data[0], "--all"_s); |
|
|
bool showAll = args.length == 1 && strEql(args.data[0], "--all"_s); |
|
|
if (!showAll) { |
|
|
if (!showAll) { |
|
|
if (args.length == 2 && (strEql(args.data[0], "--days"_s) || strEql(args.data[0], "-d"_s))) { |
|
|
if (args.length == 2 && (strEql(args.data[0], "--days"_s) || strEql(args.data[0], "-d"_s))) { |
|
|
size_t l; |
|
|
size_t l; |
|
|
numDays = parsePositiveInt(args.data[1], &l); |
|
|
numDays = parsePositiveInt(args.data[1], &l); |
|
|
} |
|
|
} |
|
|
if (numDays == -1) { |
|
|
|
|
|
|
|
|
if (!numDays.valid) { |
|
|
puts("Bad argument for --days (-d) parameter."); |
|
|
puts("Bad argument for --days (-d) parameter."); |
|
|
statusCode = 1; |
|
|
statusCode = 1; |
|
|
} else { |
|
|
} else { |
|
|
uint64 todayUnix = getSystemUnixTime(); |
|
|
uint64 todayUnix = getSystemUnixTime(); |
|
|
UnixTimestamp startUnix = todayUnix - numDays * 24 * 60 * 60; |
|
|
|
|
|
|
|
|
UnixTimestamp startUnix = todayUnix - numDays.result * 24 * 60 * 60; |
|
|
startTs = timestampFromUnixTime(&startUnix); |
|
|
startTs = timestampFromUnixTime(&startUnix); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
@@ -267,14 +267,14 @@ int gymTrackerDeleteEntries(Arena *arena, list<string> args) { |
|
|
statusCode = 1; |
|
|
statusCode = 1; |
|
|
} else { |
|
|
} else { |
|
|
size_t position = 0; |
|
|
size_t position = 0; |
|
|
int numToDelete = parsePositiveInt(args.data[0], &position); |
|
|
|
|
|
if (numToDelete != -1) { |
|
|
|
|
|
|
|
|
ParsePositiveIntResult numToDeleteParsed = parsePositiveInt(args.data[0], &position); |
|
|
|
|
|
if (numToDeleteParsed.valid) { |
|
|
list<GymLogEntry> logEntries = loadEntryLog(arena, LOG_FILE_LOCATION); |
|
|
list<GymLogEntry> logEntries = loadEntryLog(arena, LOG_FILE_LOCATION); |
|
|
if (numToDelete > logEntries.length) { |
|
|
|
|
|
log("%i is more than the current number of log entries (%i). Aborting.", numToDelete, logEntries.length); |
|
|
|
|
|
|
|
|
if (numToDeleteParsed.result > logEntries.length) { |
|
|
|
|
|
log("%i is more than the current number of log entries (%i). Aborting.", numToDeleteParsed, logEntries.length); |
|
|
statusCode = 1; |
|
|
statusCode = 1; |
|
|
} else { |
|
|
} else { |
|
|
os_writeEntireFile(arena, LOG_FILE_LOCATION, (byte *)logEntries.data, (logEntries.length - numToDelete) * sizeof(GymLogEntry)); |
|
|
|
|
|
|
|
|
os_writeEntireFile(arena, LOG_FILE_LOCATION, (byte *)logEntries.data, (logEntries.length - numToDeleteParsed.result) * sizeof(GymLogEntry)); |
|
|
} |
|
|
} |
|
|
} else { |
|
|
} else { |
|
|
log("Invalid number to delete.\n"); |
|
|
log("Invalid number to delete.\n"); |
|
@@ -321,17 +321,18 @@ int gymTrackerDo(Arena *arena, list<string> args) { |
|
|
if (statusCode == 0) { |
|
|
if (statusCode == 0) { |
|
|
exercise.id = existingEntry->id; |
|
|
exercise.id = existingEntry->id; |
|
|
size_t parsedCount = 0; |
|
|
size_t parsedCount = 0; |
|
|
real32 kg = parsePositiveReal32(args.data[1], &parsedCount); |
|
|
|
|
|
uint8 reps = parsePositiveInt(args.data[2], &parsedCount); |
|
|
|
|
|
if (parsedCount == 0 || kg == NAN || reps == 0 || kg == 0) { |
|
|
|
|
|
|
|
|
ParsePositiveReal32Result kg = parsePositiveReal32(args.data[1], &parsedCount); |
|
|
|
|
|
ParsePositiveIntResult reps = parsePositiveInt(args.data[2], &parsedCount); |
|
|
|
|
|
if (!kg.valid || !reps.valid) { |
|
|
|
|
|
log("%zu, %f, %\n", parsedCount, kg, reps); |
|
|
log("Invalid reps or weight input.\n"); |
|
|
log("Invalid reps or weight input.\n"); |
|
|
statusCode = 1; |
|
|
statusCode = 1; |
|
|
} else { |
|
|
} else { |
|
|
GymLogEntry entry = { |
|
|
GymLogEntry entry = { |
|
|
getSystemUnixTime(), |
|
|
getSystemUnixTime(), |
|
|
exercise.id, |
|
|
exercise.id, |
|
|
reps, |
|
|
|
|
|
kg, |
|
|
|
|
|
|
|
|
reps.result, |
|
|
|
|
|
kg.result, |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
os_fileAppend(arena, LOG_FILE_LOCATION, (byte *)&entry, sizeof(entry)); |
|
|
os_fileAppend(arena, LOG_FILE_LOCATION, (byte *)&entry, sizeof(entry)); |
|
|