From a7fcae14b142631e102e3a5908c577cb640630e3 Mon Sep 17 00:00:00 2001 From: Edward Betts Date: Thu, 21 Dec 2023 19:54:13 +0000 Subject: [PATCH] Show actual bug state changes --- build.py | 29 +++++++++++------------------ template.html | 6 +----- 2 files changed, 12 insertions(+), 23 deletions(-) diff --git a/build.py b/build.py index cff086d..e6236fd 100755 --- a/build.py +++ b/build.py @@ -64,19 +64,18 @@ def get_all_bugs() -> list[Bug]: return all_bugs -def parse_date(date_str: str | None) -> date | None: +def parse_date(date_str: str | None) -> datetime | None: """Parse a date string with timezone information.""" if date_str is None: return None fmt = "%Y-%m-%dT%H:%M:%SZ" if date_str.endswith("Z") else "%Y-%m-%dT%H:%M:%S%z" - return datetime.strptime(date_str, fmt).astimezone(pytz.utc).date() + return datetime.strptime(date_str, fmt).astimezone(pytz.utc) def count_open_bugs(bug_reports: list[Bug]) -> list[tuple[str, int]]: """Count the number of open bugs for each date based on a list of bug reports.""" - open_dates: Counter[date] = Counter() - close_dates: Counter[date] = Counter() + dates: list[tuple[datetime, int]] = [] # Process each bug report seen: set[int] = set() @@ -86,25 +85,19 @@ def count_open_bugs(bug_reports: list[Bug]) -> list[tuple[str, int]]: seen.add(report["id"]) open_date = parse_date(report["created_at"]) assert open_date - open_dates[open_date] += 1 + dates.append((open_date, 1)) close_date = parse_date(report["closed_at"]) if close_date: - close_dates[close_date] += 1 + dates.append((close_date, -1)) - # Create a date range from the earliest open date to the latest close date - start_date = min(open_dates.keys()) - end_date = max(close_dates.keys(), default=start_date) - delta = end_date - start_date - - # Count open bugs for each date - open_bug_count = 0 + dates.sort() + bug_count = 0 open_bugs_over_time = [] - for i in range(delta.days + 1): - current_date = start_date + timedelta(days=i) - open_bug_count += open_dates.get(current_date, 0) - open_bug_count -= close_dates.get(current_date, 0) - open_bugs_over_time.append((current_date.isoformat(), open_bug_count)) + for dt, delta in dates: + bug_count += delta + iso_date = dt.isoformat() + open_bugs_over_time.append((iso_date, bug_count)) return open_bugs_over_time diff --git a/template.html b/template.html index f605b0d..d83f15d 100644 --- a/template.html +++ b/template.html @@ -35,11 +35,7 @@ document.addEventListener('DOMContentLoaded', function () { scales: { x: { type: 'time', - time: { - parser: 'yyyy-MM-dd', - unit: 'month', - // displayFormats: {'month': 'MMM yyyy'} - } + time: {unit: 'month'} }, y: { ticks: {