From c86daeaa4b8d1ec34405c587a6eaa9139cea8f9e Mon Sep 17 00:00:00 2001 From: Knyffen Date: Thu, 23 Apr 2026 16:33:34 +0200 Subject: [PATCH] Make "calories burned per day" more dependent on my current weight ... If the previous numbers were based on some kind of research... oops :P --- server/src/math/calculations.rs | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/server/src/math/calculations.rs b/server/src/math/calculations.rs index 494d655..d16d241 100644 --- a/server/src/math/calculations.rs +++ b/server/src/math/calculations.rs @@ -11,10 +11,11 @@ use time::Date; use time::*; const MEALS_PER_DAY: f32 = 2.3; +const MYSTERY_MEAL_MIN_CALORIES: f32 = 800.; 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_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 { 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)| { - 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; 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)) .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| { root.fill(&WHITE).unwrap(); let mut chart = ChartBuilder::on(&root) @@ -277,12 +288,12 @@ pub fn plot_weight_loss( .right_y_label_area_size(50) .build_cartesian_2d( mindate_chrono..maxdate_chrono, - (min_weight - 2.)..(max_weight + 2.), + (min_graph_y - 2.)..(max_weight + 2.), ) .unwrap() .set_secondary_coord( mindate_chrono..maxdate_chrono, - (min_weight - max_weight - 2.)..2., + (min_graph_y - max_weight - 2.)..2., ); chart @@ -301,7 +312,7 @@ pub fn plot_weight_loss( chart .draw_series(LineSeries::new( vec![ - (today_chrono, min_weight - 2.), + (today_chrono, min_graph_y - 2.), (today_chrono, max_weight + 2.), ], BLACK.stroke_width(2),