Show actual bug state changes

This commit is contained in:
Edward Betts 2023-12-21 19:54:13 +00:00
parent 0aaa90c27a
commit a7fcae14b1
2 changed files with 12 additions and 23 deletions

View file

@ -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

View file

@ -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: {