feat: Update Gitea issues index and enhance data layer metrics
Deploy Development / deploy (push) Successful in 1m3s
Build Test / pytest-backend (push) Successful in 9s
Build Test / lint-backend (push) Successful in 0s
Build Test / build-frontend (push) Successful in 16s

- Updated the Gitea issues index to reflect the latest state as of 2026-04-11, adding issue #76 to the list.
- Refined data handling in `activity_metrics.py`, `body_metrics.py`, `nutrition_metrics.py`, and `scores.py` to ensure consistent float conversions for calculations, improving accuracy in metric evaluations.
- Enhanced the calculation logic for various metrics to handle potential None values more robustly, ensuring smoother data processing and improved reliability across the application.

These changes improve the clarity of the Gitea issues documentation and enhance the overall accuracy and reliability of health and fitness metrics.
This commit is contained in:
Lars committed 2026-04-11 22:14:45 +02:00
1 parent 4868e44882
commit d7cefdd9e9
7 files changed
+121 -50

No files matched your search

+32 -19
View File
@@ -445,12 +445,16 @@ def calculate_weight_7d_median(profile_id: str) -> Optional[float]:
ORDER BY date DESC
""", (profile_id,))
weights = [row['weight'] for row in cur.fetchall()]
weights = [
safe_float(row['weight'])
for row in cur.fetchall()
if row['weight'] is not None
]
if len(weights) < 4: # Need at least 4 measurements
return None
return round(statistics.median(weights), 1)
return round(float(statistics.median(weights)), 1)
def calculate_weight_28d_slope(profile_id: str) -> Optional[float]:
@@ -478,7 +482,11 @@ def _calculate_weight_slope(profile_id: str, days: int) -> Optional[float]:
ORDER BY date
""", (profile_id, days))
data = [(row['date'], row['weight']) for row in cur.fetchall()]
data = [
(row['date'], safe_float(row['weight']))
for row in cur.fetchall()
if row['weight'] is not None
]
# Need minimum data points based on period
min_points = max(18, int(days * 0.6)) # 60% coverage
@@ -488,21 +496,21 @@ def _calculate_weight_slope(profile_id: str, days: int) -> Optional[float]:
# Convert dates to days since start
start_date = data[0][0]
x_values = [(date - start_date).days for date, _ in data]
y_values = [weight for _, weight in data]
y_values = [w for _, w in data]
# Linear regression
# Linear regression (alles float: PostgreSQL numeric → Decimal in Python)
n = len(data)
x_mean = sum(x_values) / n
y_mean = sum(y_values) / n
x_mean = float(sum(x_values)) / n
y_mean = float(sum(y_values)) / n
numerator = sum((x - x_mean) * (y - y_mean) for x, y in zip(x_values, y_values))
denominator = sum((x - x_mean) ** 2 for x in x_values)
numerator = sum(float(x - x_mean) * float(y - y_mean) for x, y in zip(x_values, y_values))
denominator = float(sum((x - x_mean) ** 2 for x in x_values))
if denominator == 0:
return None
slope = numerator / denominator
return round(slope, 4) # kg/day
return round(float(slope), 4) # kg/day
def calculate_goal_projection_date(profile_id: str, goal_id: str) -> Optional[str]:
@@ -594,19 +602,24 @@ def _calculate_body_composition_change(profile_id: str, metric: str, days: int)
recent = data[0]
oldest = data[-1]
# Calculate FM and LBM
recent_fm = recent['weight'] * (recent['bf_pct'] / 100)
recent_lbm = recent['weight'] - recent_fm
# Calculate FM and LBM (DB numeric → Decimal; für Regression/Scores nur float)
rw = float(safe_float(recent['weight']) or 0)
ob = float(safe_float(recent['bf_pct']) or 0)
ow = float(safe_float(oldest['weight']) or 0)
obf = float(safe_float(oldest['bf_pct']) or 0)
oldest_fm = oldest['weight'] * (oldest['bf_pct'] / 100)
oldest_lbm = oldest['weight'] - oldest_fm
recent_fm = rw * (ob / 100)
recent_lbm = rw - recent_fm
oldest_fm = ow * (obf / 100)
oldest_lbm = ow - oldest_fm
if metric == 'fm':
change = recent_fm - oldest_fm
else:
change = recent_lbm - oldest_lbm
return round(change, 2)
return round(float(change), 2)
# ── Circumference Calculations ──────────────────────────────────────────────
@@ -731,9 +744,9 @@ def calculate_body_progress_score(profile_id: str, focus_weights: Optional[Dict]
from data_layer.scores import get_user_focus_weights
focus_weights = get_user_focus_weights(profile_id)
weight_loss = focus_weights.get('weight_loss', 0)
muscle_gain = focus_weights.get('muscle_gain', 0)
body_recomp = focus_weights.get('body_recomposition', 0)
weight_loss = float(focus_weights.get('weight_loss', 0) or 0)
muscle_gain = float(focus_weights.get('muscle_gain', 0) or 0)
body_recomp = float(focus_weights.get('body_recomposition', 0) or 0)
total_body_weight = weight_loss + muscle_gain + body_recomp