From f04c6b1fbb4a07cd9b0de5c078393aa860b0e210 Mon Sep 17 00:00:00 2001 From: Daniel-Constantin Mierla Date: Sun, 13 Oct 2024 18:19:54 +0200 Subject: [PATCH] cmd_acc: added time interval cli option for acc report --- kamcli/commands/cmd_acc.py | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/kamcli/commands/cmd_acc.py b/kamcli/commands/cmd_acc.py index 5a61aed..ae2b7ca 100644 --- a/kamcli/commands/cmd_acc.py +++ b/kamcli/commands/cmd_acc.py @@ -483,7 +483,7 @@ def acc_rates_generate(ctx, rate_group): @cli.command( - "acc-report", + "report", short_help="Show various accounting reports", ) @click.option( @@ -509,9 +509,17 @@ def acc_rates_generate(ctx, rate_group): default=20, help="The limit of listed records (default: 20)", ) +@click.option( + "interval", + "--interval", + "-i", + type=int, + default=24, + help="The time interval in hours (default: 24)", +) @click.argument("name", metavar="") @pass_context -def acc_report(ctx, oformat, ostyle, limit, name): +def acc_report(ctx, oformat, ostyle, limit, interval, name): """Show various accounting reports \b @@ -520,8 +528,14 @@ def acc_report(ctx, oformat, ostyle, limit, name): """ e = create_engine(ctx.gconfig.get("db", "rwurl")) ctx.vlog("Showing accounting report: " + name) - query = "SELECT `src_user`, count(*) AS `count` FROM acc GROUP BY `src_user` ORDER BY count DESC" + query = "SELECT `src_user`, count(*) AS `count` FROM acc" + query = query + " WHERE DATE_SUB(NOW(), INTERVAL {0} HOUR) <= time".format( + interval + ) + query = query + " GROUP BY `src_user` ORDER BY count DESC" + if limit > 0: query = query + " LIMIT {0}".format(limit) + res = e.execute(query) ioutils_dbres_print(ctx, oformat, ostyle, res)