From d402511418a18858adec4750451aa7ebc2973e53 Mon Sep 17 00:00:00 2001 From: andrewlalis Date: Sun, 5 Nov 2023 10:29:00 -0500 Subject: [PATCH] Add --last-days arg, and fix user agent windowing. --- source/report/gen.d | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/source/report/gen.d b/source/report/gen.d index 304c262..3b789e3 100644 --- a/source/report/gen.d +++ b/source/report/gen.d @@ -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 + A convenience to show stats from the last N days. If provided, overrides + any --start or --end timestamps given. + -f | --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;