feat: add group statistics on profile page

* resolve file not found error and add constants

* add group stats and storage functionality

* generate new types

* add statistics and storage cap graphs

* fix: add loadFood query param #1103

* refactor to flex view
This commit is contained in:
Hayden
2022-03-27 15:12:18 -08:00
committed by GitHub
parent b57e42a3b3
commit 1e90dc2022
13 changed files with 326 additions and 32 deletions

View File

@@ -0,0 +1,40 @@
from pydantic import UUID4
from mealie.pkgs.stats import fs_stats
from mealie.repos.repository_factory import AllRepositories
from mealie.schema.group.group_statistics import GroupStatistics, GroupStorage
from mealie.services._base_service import BaseService
ALLOWED_SIZE = 500 * fs_stats.megabyte
class GroupService(BaseService):
def __init__(self, group_id: UUID4, repos: AllRepositories):
self.group_id = group_id
self.repos = repos
super().__init__()
def calculate_statistics(self, group_id: None | UUID4 = None) -> GroupStatistics:
"""
calculate_statistics calculates the statistics for the group and returns
a GroupStatistics object.
"""
target_id = group_id or self.group_id
return self.repos.groups.statistics(target_id)
def calculate_group_storage(self, group_id: None | UUID4 = None) -> GroupStorage:
"""
calculate_group_storage calculates the storage used by the group and returns
a GroupStorage object.
"""
target_id = group_id or self.group_id
all_ids = self.repos.recipes.all_ids(target_id)
used_size = sum(
fs_stats.get_dir_size(f"{self.directories.RECIPE_DATA_DIR}/{str(recipe_id)}") for recipe_id in all_ids
)
return GroupStorage.bytes(used_size, ALLOWED_SIZE)