Skip to content

Commit

Permalink
cmd_acc: added time interval cli option for acc report
Browse files Browse the repository at this point in the history
  • Loading branch information
miconda committed Oct 14, 2024
1 parent 2678277 commit f04c6b1
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions kamcli/commands/cmd_acc.py
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ def acc_rates_generate(ctx, rate_group):


@cli.command(
"acc-report",
"report",
short_help="Show various accounting reports",
)
@click.option(
Expand All @@ -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="<name>")
@pass_context
def acc_report(ctx, oformat, ostyle, limit, name):
def acc_report(ctx, oformat, ostyle, limit, interval, name):
"""Show various accounting reports
\b
Expand All @@ -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)

0 comments on commit f04c6b1

Please sign in to comment.