フルリモートエンジニアがデータドリブンに35kg痩せた話
総摂取カロリー の項目で使用したコードです。
H = 172 # Height (cm)
A = 24 # Age (years)
C = 0.4235 # Gender coefficient (male)
PAL = 1.75 # Physical Activity Level (moderate)
DAYS = 30 # Number of days (1 month)
START_WEIGHT = 98.0 # Starting weight (kg)
WEIGHT_LOSS_PER_DAY = 3.0 / 30 # Daily weight loss (kg)
FAT_BURN_RATIO = 0.6 # 60% of energy comes from fat
FAT_KCAL_PER_GRAM = 7.2 # 1g of fat burns 7.2 kcal
def calc_bmr(weight):
# Calculate Basal Metabolic Rate (BMR) in kcal
return (0.0481 * weight + 0.0234 * H - 0.0138 * A - C) * (1000 / 4.186)
print(f"{'Day':>3} {'Weight (kg)':>12} {'BMR (kcal)':>12} {'摂取カロリー(kcal)':>22} {'脂肪燃焼量(g)':>15}")
print("-" * 80)
for day in range(1, DAYS + 1):
weight = START_WEIGHT - WEIGHT_LOSS_PER_DAY * (day - 1)
bmr = calc_bmr(weight)
total_energy = bmr * PAL
fat_burn_g = (total_energy * FAT_BURN_RATIO) / FAT_KCAL_PER_GRAM
print(f"{day:3d} {weight:12.2f} {bmr:12.1f} {total_energy:22.1f} {fat_burn_g:15.1f}")Day Weight (kg) BMR (kcal) 摂取カロリー(kcal) 脂肪燃焼量(g)
--------------------------------------------------------------------------------
1 98.00 1907.3 3337.8 278.1
2 97.90 1906.1 3335.7 278.0
3 97.80 1905.0 3333.7 277.8
4 97.70 1903.8 3331.7 277.6
5 97.60 1902.7 3329.7 277.5
6 97.50 1901.5 3327.7 277.3
7 97.40 1900.4 3325.7 277.1
8 97.30 1899.2 3323.7 277.0
9 97.20 1898.1 3321.7 276.8
10 97.10 1896.9 3319.7 276.6
11 97.00 1895.8 3317.6 276.5
12 96.90 1894.6 3315.6 276.3
13 96.80 1893.5 3313.6 276.1
14 96.70 1892.3 3311.6 276.0
15 96.60 1891.2 3309.6 275.8
16 96.50 1890.1 3307.6 275.6
17 96.40 1888.9 3305.6 275.5
18 96.30 1887.8 3303.6 275.3
19 96.20 1886.6 3301.6 275.1
20 96.10 1885.5 3299.5 275.0
21 96.00 1884.3 3297.5 274.8
22 95.90 1883.2 3295.5 274.6
23 95.80 1882.0 3293.5 274.5
24 95.70 1880.9 3291.5 274.3
25 95.60 1879.7 3289.5 274.1
26 95.50 1878.6 3287.5 274.0
27 95.40 1877.4 3285.5 273.8
28 95.30 1876.3 3283.5 273.6
29 95.20 1875.1 3281.4 273.5
30 95.10 1874.0 3279.4 273.31日だけ頑張る努力よりも長く続けられる工夫を見出す重要性 の項目で使用したコードです。
初期体重が98kg、脂肪燃焼分だけ体重が毎回減少、消費されるカロリーの60%が脂肪として消費されると仮定。
import plotly.graph_objects as go
# 設定
start_weight = 98.0
days = 365
duration_h = 1.0
def calc_kcal(met, time_h, weight):
return met * weight * time_h * 1.05
def calc_fat_loss(kcal):
return (kcal * 0.6) / 7.2 # g
# ランニング(週2回: 火・金)
run2_total_fat_list = []
run2_weight = start_weight
run2_total_fat_g = 0.0
# ランニング(週3回: 月・水・金)
run3_total_fat_list = []
run3_weight = start_weight
run3_total_fat_g = 0.0
# ウォーキング(毎日)
walk_total_fat_list = []
walk_weight = start_weight
walk_total_fat_g = 0.0
for day in range(1, days + 1):
# ランニング週2: 火(2), 金(5)
if day % 7 in [2, 5]:
kcal = calc_kcal(9.8, duration_h, run2_weight)
fat = calc_fat_loss(kcal)
run2_total_fat_g += fat
run2_weight -= fat / 1000
run2_total_fat_list.append(run2_total_fat_g)
# ランニング週3: 月(1), 水(3), 金(5)
if day % 7 in [1, 3, 5]:
kcal = calc_kcal(9.8, duration_h, run3_weight)
fat = calc_fat_loss(kcal)
run3_total_fat_g += fat
run3_weight -= fat / 1000
run3_total_fat_list.append(run3_total_fat_g)
# ウォーキング毎日
kcal = calc_kcal(3.8, duration_h, walk_weight)
fat = calc_fat_loss(kcal)
walk_total_fat_g += fat
walk_weight -= fat / 1000
walk_total_fat_list.append(walk_total_fat_g)
# 作図(脂肪燃焼量の推移)
fig = go.Figure()
fig.add_trace(go.Scatter(x=list(range(1, days + 1)), y=run2_total_fat_list, mode='lines', name='ランニング脂肪量(週2)'))
fig.add_trace(go.Scatter(x=list(range(1, days + 1)), y=run3_total_fat_list, mode='lines', name='ランニング脂肪量(週3)'))
fig.add_trace(go.Scatter(x=list(range(1, days + 1)), y=walk_total_fat_list, mode='lines', name='ウォーキング脂肪量(毎日)'))
fig.update_layout(
title="年間の脂肪燃焼量の推移(ランニング週2・週3 vs ウォーキング毎日)",
xaxis_title="日数",
yaxis_title="累積脂肪燃焼量(g)",
template="plotly_white"
)
fig.show()