caltrack/calc/calc.go

54 lines
1.2 KiB
Go
Raw Permalink Normal View History

2026-02-23 18:21:23 +00:00
package calc
import "caltrack/types"
// BMR calculates Basal Metabolic Rate using Mifflin-St Jeor equation.
func BMR(cfg types.Config) float64 {
weight := cfg.CurrentWeightKg
height := float64(cfg.HeightCm)
age := float64(cfg.Age)
if cfg.Sex == "female" {
return 10*weight + 6.25*height - 5*age - 161
}
return 10*weight + 6.25*height - 5*age + 5
}
// ActivityMultiplier returns the multiplier for the given activity level.
func ActivityMultiplier(level string) float64 {
switch level {
case "sedentary":
return 1.2
case "light":
return 1.375
case "moderate":
return 1.55
case "active":
return 1.725
default:
return 1.55
}
}
// TDEE calculates Total Daily Energy Expenditure.
func TDEE(cfg types.Config) float64 {
return BMR(cfg) * ActivityMultiplier(cfg.ActivityLevel)
}
// DailyTarget calculates the daily calorie target accounting for desired deficit.
func DailyTarget(cfg types.Config) int {
tdee := TDEE(cfg)
// 1 kg of fat ≈ 7700 kcal
dailyDeficit := (cfg.WeeklyLossKg * 7700) / 7
target := tdee - dailyDeficit
if target < 1200 {
target = 1200
}
return int(target)
}
// Deficit returns the daily calorie deficit.
func Deficit(cfg types.Config) int {
return int(TDEE(cfg)) - DailyTarget(cfg)
}