Make "calories burned per day" more dependent on my current weight

... If the previous numbers were based on some kind of research... oops :P
This commit is contained in:
Knyffen 2026-04-23 16:33:34 +02:00
parent cfd92c982e
commit c86daeaa4b

View File

@ -11,10 +11,11 @@ use time::Date;
use time::*; use time::*;
const MEALS_PER_DAY: f32 = 2.3; const MEALS_PER_DAY: f32 = 2.3;
const MYSTERY_MEAL_MIN_CALORIES: f32 = 800.;
const SMOOTHING_DAYS: usize = 21; const SMOOTHING_DAYS: usize = 21;
const CALORIES_BURNED_PER_DAY: f32 = 2270.; const CALORIES_BURNED_PER_DAY: f32 = 2350.;
const CALORIES_BURNED_PER_DAY_BASE_WEIGHT: f32 = 83.; const CALORIES_BURNED_PER_DAY_BASE_WEIGHT: f32 = 83.;
const CALORIES_BURNED_LESS_PER_DAY_PER_KG: f32 = 12.5; const CALORIES_BURNED_LESS_PER_DAY_PER_KG: f32 = 27.;
fn time_date_to_chrono_naive_date(d: Date) -> chrono::NaiveDate { fn time_date_to_chrono_naive_date(d: Date) -> chrono::NaiveDate {
chrono::NaiveDate::from_ymd_opt(d.year(), d.month() as u32, d.day() as u32).unwrap() chrono::NaiveDate::from_ymd_opt(d.year(), d.month() as u32, d.day() as u32).unwrap()
@ -61,7 +62,8 @@ fn calculate_calories_per_day(
} }
}); });
mystery_meals.iter().enumerate().for_each(|(i, amount)| { mystery_meals.iter().enumerate().for_each(|(i, amount)| {
let calories = calorie_days[i] / MEALS_PER_DAY * *amount as f32; let calories = (calorie_days[i] / MEALS_PER_DAY * *amount as f32)
.max(MYSTERY_MEAL_MIN_CALORIES * *amount as f32);
let calories_smoothed = calories / SMOOTHING_DAYS as f32; let calories_smoothed = calories / SMOOTHING_DAYS as f32;
for item in &mut calorie_days[i..i + SMOOTHING_DAYS] { for item in &mut calorie_days[i..i + SMOOTHING_DAYS] {
@ -267,6 +269,15 @@ pub fn plot_weight_loss(
.reduce(|a, b| a.min(b)) .reduce(|a, b| a.min(b))
.unwrap(); .unwrap();
let min_deficit: f32 = deficit_days
.iter()
// the non-calories values is an offset to make the two plotted lines fit
.map(|w| *w / 7000. + (weight[0].weight + 1.))
.reduce(|a, b| a.min(b))
.unwrap();
let min_graph_y = min_weight.min(min_deficit);
let plotfun = Box::new(move |root: plotting::SVGPlotRoot| { let plotfun = Box::new(move |root: plotting::SVGPlotRoot| {
root.fill(&WHITE).unwrap(); root.fill(&WHITE).unwrap();
let mut chart = ChartBuilder::on(&root) let mut chart = ChartBuilder::on(&root)
@ -277,12 +288,12 @@ pub fn plot_weight_loss(
.right_y_label_area_size(50) .right_y_label_area_size(50)
.build_cartesian_2d( .build_cartesian_2d(
mindate_chrono..maxdate_chrono, mindate_chrono..maxdate_chrono,
(min_weight - 2.)..(max_weight + 2.), (min_graph_y - 2.)..(max_weight + 2.),
) )
.unwrap() .unwrap()
.set_secondary_coord( .set_secondary_coord(
mindate_chrono..maxdate_chrono, mindate_chrono..maxdate_chrono,
(min_weight - max_weight - 2.)..2., (min_graph_y - max_weight - 2.)..2.,
); );
chart chart
@ -301,7 +312,7 @@ pub fn plot_weight_loss(
chart chart
.draw_series(LineSeries::new( .draw_series(LineSeries::new(
vec![ vec![
(today_chrono, min_weight - 2.), (today_chrono, min_graph_y - 2.),
(today_chrono, max_weight + 2.), (today_chrono, max_weight + 2.),
], ],
BLACK.stroke_width(2), BLACK.stroke_width(2),