mirror of
https://github.com/mealie-recipes/mealie.git
synced 2025-12-10 20:35:14 -05:00
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:
40
mealie/services/group_services/group_service.py
Normal file
40
mealie/services/group_services/group_service.py
Normal 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)
|
||||
Reference in New Issue
Block a user