Add line with calories burned per day

This commit is contained in:
Knyffen 2024-11-21 07:47:46 +01:00
parent 1b0686d16f
commit b856ed01cd

View File

@ -12,6 +12,7 @@ use time::*;
const MEALS_PER_DAY: f32 = 2.3;
const SMOOTHING_DAYS: usize = 21;
const CALORIES_BURNED_PER_DAY: f32 = 2270.;
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()
@ -125,6 +126,18 @@ pub fn plot_calories_per_day(
.label("today")
.legend(|(x, y)| PathElement::new(vec![(x, y), (x + 20, y)], BLACK));
chart
.draw_series(LineSeries::new(
vec![
(mindate_chrono, CALORIES_BURNED_PER_DAY),
(maxdate_chrono, CALORIES_BURNED_PER_DAY),
],
BLACK.stroke_width(2),
))
.unwrap()
.label("calories burned per day")
.legend(|(x, y)| PathElement::new(vec![(x, y), (x + 20, y)], BLACK));
chart
.draw_series(LineSeries::new(
calorie_days.iter().enumerate().map(|(i, cal)| {
@ -162,7 +175,6 @@ pub fn plot_weight_loss(
running: Vec<my_structs::Running>,
) -> plotting::SVGPlotFun {
let (mindate, calorie_days) = calculate_calories_per_day(nutrition_map, purchases);
let calories_burned_per_day: f32 = 2270.;
// Based on the Caloie Burned by Distance Calculator
// https://www.calculator.net/calories-burned-calculator.html
@ -194,7 +206,7 @@ pub fn plot_weight_loss(
.iter()
.enumerate()
.scan(0., |deficit, (i, &calories)| {
*deficit += calories - calories_burned_per_day - running_days[i];
*deficit += calories - CALORIES_BURNED_PER_DAY - running_days[i];
Some(*deficit)
})
.collect();