Add line with calories burned per day
This commit is contained in:
parent
1b0686d16f
commit
b856ed01cd
@ -12,6 +12,7 @@ use time::*;
|
|||||||
|
|
||||||
const MEALS_PER_DAY: f32 = 2.3;
|
const MEALS_PER_DAY: f32 = 2.3;
|
||||||
const SMOOTHING_DAYS: usize = 21;
|
const SMOOTHING_DAYS: usize = 21;
|
||||||
|
const CALORIES_BURNED_PER_DAY: f32 = 2270.;
|
||||||
|
|
||||||
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()
|
||||||
@ -125,6 +126,18 @@ pub fn plot_calories_per_day(
|
|||||||
.label("today")
|
.label("today")
|
||||||
.legend(|(x, y)| PathElement::new(vec![(x, y), (x + 20, y)], BLACK));
|
.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
|
chart
|
||||||
.draw_series(LineSeries::new(
|
.draw_series(LineSeries::new(
|
||||||
calorie_days.iter().enumerate().map(|(i, cal)| {
|
calorie_days.iter().enumerate().map(|(i, cal)| {
|
||||||
@ -162,7 +175,6 @@ pub fn plot_weight_loss(
|
|||||||
running: Vec<my_structs::Running>,
|
running: Vec<my_structs::Running>,
|
||||||
) -> plotting::SVGPlotFun {
|
) -> plotting::SVGPlotFun {
|
||||||
let (mindate, calorie_days) = calculate_calories_per_day(nutrition_map, purchases);
|
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
|
// Based on the Caloie Burned by Distance Calculator
|
||||||
// https://www.calculator.net/calories-burned-calculator.html
|
// https://www.calculator.net/calories-burned-calculator.html
|
||||||
@ -194,7 +206,7 @@ pub fn plot_weight_loss(
|
|||||||
.iter()
|
.iter()
|
||||||
.enumerate()
|
.enumerate()
|
||||||
.scan(0., |deficit, (i, &calories)| {
|
.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)
|
Some(*deficit)
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
Loading…
Reference in New Issue
Block a user