Skip to content

Bug in 7-day average calculation in nutrition plan #1212

@Thaniel94

Description

@Thaniel94

In the nutrition plan's "logged" section, there is a graph displaying "7 day average", "planned" and "today" fields, which are displayed as bars for protein, carbs, sugar, etc.

From what I can see, the 7 day average calculation on the react frontend is not working the way it should, and so giving much lower values than the true weekly average.
It seems the averaging value ("nrOfEntries" is much higher than it ought to be for some reason (as many as 50 in my tests) - not sure if it's meant to represent daily entries - the number in the week, or total number of food items in the week.

In any case, this leads to much lower values recorded here than anticipated.

The bad code is /src/components/Nutrition//models/nutritionPlan.ts, in the function: "getAverageNutritionalValuesFromDiaryEntries"
The fix seems to be trivial. Running the code locally on the master branch, it's just a case of adjusting the averaging logic so instead of dividing by the total number of food items, it just divided by the number of days in a week (i.e. 7) - presumably this may be what the number of elements in "nrOfEntries" is supposed to be ( perhaps it's supposed to aggregate the data for each day first), but just making it 7 gives the correct values.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions