Skip to content

Commit

Permalink
Add tab with the total usage numbers
Browse files Browse the repository at this point in the history
Trends are not so relevant here and too demanding on resources.

Signed-off-by: Frantisek Lachman <[email protected]>
  • Loading branch information
lachmanfrantisek committed Oct 6, 2023
1 parent b69290b commit d09c792
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
3 changes: 3 additions & 0 deletions frontend/src/app/Usage/Usage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ const Usage = () => {
<UsageList what="past-year" />
<UsageInterval days={7} hours={0} count={52} />
</Tab>
<Tab eventKey={4} title="Total">
<UsageList what="total" />
</Tab>
</Tabs>
</CardBody>
</Card>
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/app/Usage/UsageList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const fetchDataByGranularity = (granularity: UsageListProps["what"]) =>
fetch(`/api/usage/${granularity}`).then((response) => response.json());

interface UsageListProps {
what: "past-day" | "past-week" | "past-month" | "past-year";
what: "past-day" | "past-week" | "past-month" | "past-year" | "total";
}

const UsageList: React.FC<UsageListProps> = (props) => {
Expand Down
8 changes: 8 additions & 0 deletions packit_dashboard/api/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,14 @@ def usage_past_year():
return _get_usage_data_from_packit_api(usage_from=past_year_date)


@api.route("/api/usage/total")
@ttl_cache(maxsize=_CACHE_MAXSIZE, ttl=timedelta(days=1).seconds)
def usage_total():
now = datetime.now()
past_date = now.replace(year=now.year - 100).strftime("%Y-%m-%d")
return _get_usage_data_from_packit_api(usage_from=past_date)


# format the chart needs is a list of {"x": "datetimelegend", "y": value}
CHART_DATA_TYPE = list[dict[str, Union[str, int]]]

Expand Down

0 comments on commit d09c792

Please sign in to comment.