Skip to content

Commit

Permalink
Add usage trend charts for project count
Browse files Browse the repository at this point in the history
This adds two new charts to show usage of jobs for number of unique projects.

Signed-off-by: Frantisek Lachman <[email protected]>
  • Loading branch information
lachmanfrantisek committed Sep 7, 2023
1 parent 0f1dc7c commit e758f9a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
12 changes: 12 additions & 0 deletions frontend/src/app/Usage/UsageInterval.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -160,11 +160,23 @@ const UsageInterval: React.FC<UsageIntervalProps> = (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,
Expand Down
10 changes: 8 additions & 2 deletions packit_dashboard/api/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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 = []

Expand All @@ -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, [])
Expand All @@ -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(),
Expand Down

0 comments on commit e758f9a

Please sign in to comment.