From e758f9adcd1ccec8e2adf491892c207f7196189e Mon Sep 17 00:00:00 2001 From: Frantisek Lachman Date: Thu, 7 Sep 2023 13:03:13 +0200 Subject: [PATCH] Add usage trend charts for project count This adds two new charts to show usage of jobs for number of unique projects. Signed-off-by: Frantisek Lachman --- frontend/src/app/Usage/UsageInterval.tsx | 12 ++++++++++++ packit_dashboard/api/routes.py | 10 ++++++++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/frontend/src/app/Usage/UsageInterval.tsx b/frontend/src/app/Usage/UsageInterval.tsx index f7944a5a..58f14acf 100644 --- a/frontend/src/app/Usage/UsageInterval.tsx +++ b/frontend/src/app/Usage/UsageInterval.tsx @@ -160,11 +160,23 @@ const UsageInterval: React.FC = (props) => { data.jobs, "Number of processed jobs", )} + {getLineChart( + Object.keys(data.jobs_project_count).filter( + (obj) => obj !== "sync_release_runs", + ), + data.jobs_project_count, + "Number of projects with processed jobs of this type", + )} {getLineChart( ["sync_release_runs"], data.jobs, "Number of synced releases", )} + {getLineChart( + ["sync_release_runs"], + data.jobs_project_count, + "Number of projects with synced releases", + )} {getLineChart( ["active_projects"], data, diff --git a/packit_dashboard/api/routes.py b/packit_dashboard/api/routes.py index 584d6373..ca52754e 100644 --- a/packit_dashboard/api/routes.py +++ b/packit_dashboard/api/routes.py @@ -139,7 +139,7 @@ def usage_past_year(): # format the chart needs is a list of {"x": "datetimelegend", "y": value} -CHART_DATA_TYPE = list[dict[str, str]] +CHART_DATA_TYPE = list[dict[str, Union[str, int]]] @ttl_cache(maxsize=_CACHE_MAXSIZE, ttl=timedelta(hours=1).seconds) @@ -162,6 +162,7 @@ def _get_usage_interval_data( current_date -= delta result_jobs: dict[str, CHART_DATA_TYPE] = {} + result_jobs_project_count: dict[str, CHART_DATA_TYPE] = {} result_events: dict[str, CHART_DATA_TYPE] = {} result_active_projects: CHART_DATA_TYPE = [] @@ -171,12 +172,16 @@ def _get_usage_interval_data( legend = day.strftime("%H:%M" if (hours and not days) else "%Y-%m-%d") interval_result = _get_usage_data_from_packit_api( - usage_from=day_from, usage_to=day_to, top=0 + usage_from=day_from, usage_to=day_to, top=100000 ).json for job, data in interval_result["jobs"].items(): result_jobs.setdefault(job, []) result_jobs[job].append({"x": legend, "y": data["job_runs"]}) + result_jobs_project_count.setdefault(job, []) + result_jobs_project_count[job].append( + {"x": legend, "y": len(data["top_projects_by_job_runs"])} + ) for event, data in interval_result["events"].items(): result_events.setdefault(event, []) @@ -188,6 +193,7 @@ def _get_usage_interval_data( return { "jobs": result_jobs, + "jobs_project_count": result_jobs_project_count, "events": result_events, "from": days_legend[0].isoformat(), "to": days_legend[-1].isoformat(),