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;