diff --git a/tdee_calculator.py b/tdee_calculator.py index 167bd25..7001e14 100644 --- a/tdee_calculator.py +++ b/tdee_calculator.py @@ -1,154 +1,123 @@ -# -*- coding: utf-8 -*- -""" -每日热量需求估算器:BMR (Mifflin-St Jeor) -> TDEE -> 减脂目标 +import { useState } from 'react'; +import { Flame, Scale, Footprints, Activity } from 'lucide-react'; -输入:身高、体重、年龄、性别、每日步数 -输出:BMR、TDEE、减脂期每日摄入热量、三大营养素建议 +const stepBands = [ + { min: 0, max: 5000, factor: 1.2, label: '久坐(<5,000 步)' }, + { min: 5000, max: 7500, factor: 1.375, label: '轻度活动(5,000–7,499 步)' }, + { min: 7500, max: 10000, factor: 1.55, label: '中度活动(7,500–9,999 步)' }, + { min: 10000, max: 12500, factor: 1.65, label: '高度活动(10,000–12,499 步)' }, + { min: 12500, max: Infinity, factor: 1.8, label: '非常活跃(≥12,500 步)' }, +]; -用法: - 1. 修改下面 CONFIG 里的个人信息,然后直接运行;或 - 2. import 后调用 daily_calories(...) - -注意:未成年人(<18 岁)的 BMI 判定应使用年龄性别百分位标准 - (中国 WS/T 586-2018),而非成人 24/28 的切点。 -""" - -# ============ 在这里填入真实数据 ============ -CONFIG = { - "height_cm": 165, # 身高(厘米) - "weight_kg": 70, # 体重(公斤)—— 140 斤 - "age": 16, # 年龄 - "sex": "female", # "male" 或 "female" - "steps": 10000, # 每日平均步数 - "goal": "cut", # "maintain" 保持 / "cut" 减脂 / "gain" 增重 +function bandFor(steps) { + return stepBands.find(b => steps >= b.min && steps < b.max) || stepBands[stepBands.length - 1]; } -# ============================================== +function bmiCategory(bmi) { + if (bmi < 18.5) return { text: '偏瘦', color: 'text-amber-600' }; + if (bmi < 24) return { text: '正常', color: 'text-emerald-600' }; + if (bmi < 28) return { text: '超重', color: 'text-orange-600' }; + return { text: '肥胖', color: 'text-red-600' }; +} -def bmr_mifflin(weight_kg, height_cm, age, sex): - """基础代谢率 BMR,单位 kcal/天(Mifflin-St Jeor 公式)""" - if weight_kg <= 0 or height_cm <= 0: - raise ValueError("身高和体重必须大于 0") - if not 0 < age < 120: - raise ValueError("年龄看起来不太对") +export default function CalorieCalculator() { + const [sex, setSex] = useState('female'); + const [age, setAge] = useState(30); + const [height, setHeight] = useState(164); + const [weight, setWeight] = useState(51); + const [steps, setSteps] = useState(10000); - base = 10 * weight_kg + 6.25 * height_cm - 5 * age - if sex == "male": - return base + 5 - elif sex == "female": - return base - 161 - else: - raise ValueError("sex 只能是 'male' 或 'female'") + const hM = height / 100; + const bmi = hM > 0 ? weight / (hM * hM) : 0; + const cat = bmiCategory(bmi); + const bmr = sex === 'male' + ? 10 * weight + 6.25 * height - 5 * age + 5 + : 10 * weight + 6.25 * height - 5 * age - 161; -def pal_from_steps(steps): - """根据每日步数返回 (下限, 常用值, 上限) 三个 PAL 系数""" - if steps < 5000: - return 1.15, 1.2, 1.25 - elif steps < 7500: - return 1.3, 1.375, 1.45 - elif steps < 10000: - return 1.45, 1.5, 1.55 - elif steps < 12500: - return 1.5, 1.55, 1.6 - else: - return 1.6, 1.725, 1.8 + const band = bandFor(steps); + const tdee = bmr * band.factor; + const round = n => Math.round(n); + const inputCls = 'w-full px-3 py-2 rounded-lg border border-slate-200 focus:outline-none focus:ring-2 focus:ring-sky-400'; -def daily_calories(weight_kg, height_cm, age, sex, steps=10000): - """返回 (BMR, PAL, TDEE下限, TDEE常用, TDEE上限)""" - bmr = bmr_mifflin(weight_kg, height_cm, age, sex) - low, mid, high = pal_from_steps(steps) - return bmr, mid, bmr * low, bmr * mid, bmr * high + return ( +
Mifflin-St Jeor 公式 + 步数活动系数
+* 结果仅供参考,个体肌肉量、代谢与食物热效应等会影响实际需求。
+