Add --last-days arg, and fix user agent windowing.

This commit is contained in:
Andrew Lalis 2023-11-05 10:29:00 -05:00
parent 5e0b60e9fd
commit d402511418
1 changed files with 13 additions and 1 deletions

View File

@ -6,6 +6,7 @@ import std.datetime;
import std.algorithm;
import std.array;
import std.file;
import std.conv : to;
import d2sqlite3;
import data;
import std.json;
@ -54,6 +55,10 @@ are accepted:
date and time. Timestamps are always interpretted as UTC timezone. Defaults
to the current time.
--last-days <days>
A convenience to show stats from the last N days. If provided, overrides
any --start or --end timestamps given.
-f <format> | --format <format>
Specify the desired output format for the report(s) generated by this
command. The following formats are available: text, json, csv.
@ -104,6 +109,10 @@ ReportPeriod parseReportPeriod(string[] args) {
} else if (args[i] == "--end" && !endParsed) {
end = tryParseTime(args[i + 1]);
endParsed = true;
} else if (args[i] == "--last-days") {
end = Clock.currTime(UTC());
start = end - days(args[i + 1].to!uint);
return ReportPeriod(start, end);
}
}
}
@ -198,9 +207,12 @@ SQL",
ResultRange userAgentsResult = db.execute(q"SQL
SELECT user_agent, COUNT(user_agent) AS c
FROM session
WHERE start_timestamp >= ? AND end_timestamp <= ?
GROUP BY user_agent
ORDER BY c DESC
SQL");
SQL",
TS_START, TS_END
);
foreach (Row row; userAgentsResult) {
string userAgent = row["user_agent"].as!string;
ulong count = row["c"].as!ulong;