[food] Fix error in calorie aggregation
This commit is contained in:
@ -396,11 +396,12 @@ def get_daily_calories_for_user_by_day(user_id: int, date: date| str) -> int:
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
qs = base_scrobble_qs(user_id).filter(day=date)
|
qs = base_scrobble_qs(user_id).filter(day=date)
|
||||||
except AttibuteError as e:
|
agg = qs.aggregate(total_calories=models.Sum("calories_int"))
|
||||||
|
except AttributeError as e:
|
||||||
logger.warning(f"Can't generate calorie total: {e}")
|
logger.warning(f"Can't generate calorie total: {e}")
|
||||||
agg = qs.aggregate(total_calories=models.Sum("calories_int"))
|
agg = {}
|
||||||
|
|
||||||
return agg["total_calories"] or 0
|
return agg.get("total_calories") or 0
|
||||||
|
|
||||||
def get_daily_calorie_dict_for_user(user_id: int) -> dict[date, int]:
|
def get_daily_calorie_dict_for_user(user_id: int) -> dict[date, int]:
|
||||||
"""Return {day: total_calories} for all days with scrobbles, in one query."""
|
"""Return {day: total_calories} for all days with scrobbles, in one query."""
|
||||||
|
|||||||
Reference in New Issue
Block a user