diff --git a/borgweb/borg/urls.py b/borgweb/borg/urls.py index d4a2980..60d3752 100644 --- a/borgweb/borg/urls.py +++ b/borgweb/borg/urls.py @@ -8,6 +8,7 @@ urlpatterns = [ path('repo_daily.json', cache_page(3600)(views.repo_daily_json), name='daily repo json'), path('repo_monthly.json', cache_page(3600 * 12)(views.repo_monthly_json), name='monthly repo json'), path('repo_list.json', cache_page(60)(views.repo_list_json), name='repo list'), + path('repo//size.json', cache_page(60)(views.repo_size_json), name='repo size time series'), path('repo/.json', cache_page(60)(views.repo_json), name='repo json'), path('repo/', cache_page(60)(views.repo), name='repo'), path('post/repo', views.post_repo, name='post repo'), diff --git a/borgweb/borg/views/__init__.py b/borgweb/borg/views/__init__.py index fb30390..82ea75f 100644 --- a/borgweb/borg/views/__init__.py +++ b/borgweb/borg/views/__init__.py @@ -1,3 +1,3 @@ from .views import index, repo, axes from .post import post_repo, post_archive, post_error, post_location -from .json import repo_daily_json, repo_monthly_json, repo_list_json, repo_json +from .json import repo_daily_json, repo_monthly_json, repo_list_json, repo_json, repo_size_json diff --git a/borgweb/borg/views/json.py b/borgweb/borg/views/json.py index a053c07..8d5ec70 100644 --- a/borgweb/borg/views/json.py +++ b/borgweb/borg/views/json.py @@ -17,6 +17,26 @@ def repo_json(request, repo_label): return JsonResponse(repo_dict) +def repo_size_json(request, repo_label, months_ago: int = 12): + repo = get_object_or_404(Repo, label__label=repo_label) + + date_labels = [date.strftime("%b %Y") for date in last_day_previous_months(months_ago)] + + max_unit = get_units([repo]) + + repo_dict = {"id": repo.id, + "label": repo.label.label, + "size": repo.size_on_months(max_unit, months_ago)} + + response_dict = { + "dates": date_labels, + "repo": repo_dict, + "units": max_unit + } + + return JsonResponse(response_dict) + + def repo_list_json(request): return JsonResponse({'labels': [repo.label.label for repo in Repo.objects.all()]}) @@ -70,4 +90,3 @@ def get_units(repo_list): max_repo_size = max(repo.latest_archive().cache.unique_csize for repo in repo_list) _, max_unit = data.convert_bytes(max_repo_size) return max_unit -