Skip to content

Commit

Permalink
A few more fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
dbutenhof committed May 13, 2024
1 parent f563d2e commit 0233289
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions lib/pbench/cli/server/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,9 @@ def summarize_dates(base_query: Query, options: dict[str, Any]):
since = options.get("since")
until = options.get("until")

if since and until and since > until:
raise Exception("The --until value must be later than the --since value")

by_year = defaultdict(int)
by_month = defaultdict(int)
by_day = defaultdict(int)
Expand Down Expand Up @@ -421,10 +424,7 @@ def summarize_dates(base_query: Query, options: dict[str, Any]):
# the label (SQL "AS date") in our WHERE filter clauses. (In a direct query
# PostgreSQL doesn't allow filtering on renamed columns.)
subquery = base_query.subquery()
query = Database.db_session.query(subquery.c.date)
if since and until:
if since > until:
raise Exception("The --until value must be later than the --since value")
query = Database.db_session.query(subquery.c.date).order_by(subquery.c.date)

if since:
verifier.status(f"Filter since {since}")
Expand All @@ -433,18 +433,18 @@ def summarize_dates(base_query: Query, options: dict[str, Any]):
verifier.status(f"Filter until {until}")
filters.append(subquery.c.date <= until)
if filters:
query = query.filter(*filters).order_by(subquery.c.date)
query = query.filter(*filters)
rows = query.execution_options(stream_results=True).yield_per(SQL_CHUNK)

for row in rows:
if not first:
first = row[0]
last = row[0]
in_range += 1
date: datetime.datetime = row[0]
if not isinstance(date, datetime.datetime):
detailer.message(f"Got non-datetime row {row}")
continue
if not first:
first = date
last = date
in_range += 1
by_year[date.year] += 1
by_month[date.month] += 1
by_day[date.day] += 1
Expand Down

0 comments on commit 0233289

Please sign in to comment.