davidhealey / waistline

Libre calorie counter app for Android. Built with Cordova.
570 stars 69 forks source link

[Bug] Quick add and foods with negative kcal doesn't cause a recomputation of nutriments set as a % of energy intake #596

Closed giovannivelludo closed 2 years ago

giovannivelludo commented 2 years ago

For example, let's say I have a calories goal of 2800 per day, and my fat goal is 30% of my energy intake, this results in a goal of 93 g of fat per day. After adding -368 kcals of exercise the fat goal is still 93 g, but it should be (2800 + 368) * 0.3 / 9 = 105.6 g

Steps to reproduce:

Setting negative macronutrient values in foods is not allowed, and even if it was it wouldn't be a good idea because your % goals might change over time.

EmilJunker commented 2 years ago

The thing is that adding negative calories in the diary does not change the calories goal. If your calories goal was 2800 before, then it is still 2800 after adding the -368 burned calories. Hence, the other goals which are set as percentage of energy don't change either. Why should they?

giovannivelludo commented 2 years ago

Because my calorie goal for the day has now become 3168 kcal. MyFitnessPal recomputes macronutrient goals after adding exercise calories.

davidhealey commented 2 years ago

The goal shouldn't change. Do you mean the amount consumed?

davidhealey commented 2 years ago

I just checked. It seems quick add (positive or negative) is not affecting the display/calculation of the consumed amount of % based nutriments.

giovannivelludo commented 2 years ago

What I mean is that if my calorie goal is 2800 kcal and I burn 368 kcal with exercise, my energy intake for the day will have to be 3168 kcal. Since my fat goal was set as 30% of my energy intake, it should be 105.6 g (I don't know how values are rounded in Waistline) instead of 93 g (= 2800 * 0.3 / 9).

EmilJunker commented 2 years ago

Indeed, this affects both positive and negative quick add entries. It's a consequence of the fact that the quick add feature is only for calories and not for macro nutrients.

And this does not just affect nutrients set as percentage of energy either. This also happens if you set absolute goals.

I don't really know what a solution for this problem could look like tbh.

giovannivelludo commented 2 years ago

I don't think absolute goals should change since they don't depend on energy intake

davidhealey commented 2 years ago

A workaround for now might be to add an exercise food item.

giovannivelludo commented 2 years ago

That's what I'm doing but it doesn't result in a recomputation of nutrients set as a %

davidhealey commented 2 years ago

That's what I'm doing but it doesn't result in a recomputation of nutrients set as a %

Confirmed

giovannivelludo commented 2 years ago

A solution could be to add foods with negative calories (as positive values) to the calorie goal for the day in which they're added. I don't know if it's doable.

EmilJunker commented 2 years ago

I don't think absolute goals should change since they don't depend on energy intake

It's not about the goal changing. But if you log +200 kcal via the quick add feature, it only increases the comsumed amount for energy by 200, but it does not increase the consumed amounts of fat, carbs, and proteins (even though it is obvious that the 200 kcal must have come from somewhere).

That's why the quick add feature is really only meant for people who just care about tracking calories and not macro nutrients.

That's what I'm doing but it doesn't result in a recomputation of nutrients set as a %

You need to specify the burned fat, carbs, and proteins as negative values in the item too. This is the workaround we were talking about.

davidhealey commented 2 years ago

This is the workaround we were talking about.

I missed that part too :)

I don't think that is an ideal situation though because it means the user has to do the calculation manually. But as a workaround it's not bad. I think it's important to remember that Waistline is a dietary calorie counter and not an exercise tracker, so anything that goes towards tracking exercise is a bonus.

giovannivelludo commented 2 years ago

@EmilJunker

I don't think absolute goals should change since they don't depend on energy intake

It's not about the goal changing. But if you log +200 kcal via the quick add feature, it only increases the comsumed amount for energy by 200, but it does not increase the consumed amounts of fat, carbs, and proteins (even though it is obvious that the 200 kcal must have come from somewhere).

I have a goal of at least 120 grams of protein per day and this is regardless of what my energy intake is. If I wanted my goal (in grams) to change depending on energy intake I would have set it as a percentage of energy intake, the feature is already there.

That's what I'm doing but it doesn't result in a recomputation of nutrients set as a %

You need to specify the burned fat, carbs, and proteins as negative values in the item too. This is the workaround we were talking about.

Negative values for macronutrients are not allowed, this would also require manually updating foods representing exercise every time somebodies % goals change.

EmilJunker commented 2 years ago

Negative values for macronutrients are not allowed, this would also require manually updating foods representing exercise every time somebodies % goals change.

You are right, I forgot this is not possible via the user interface. But you could export the database to a JSON file, change the values there, and then re-import. I know this is far from ideal but it would serve as a a temporary workaround.

As you suggested above, the long term solution would be to add negative energy values to the energy goal instead of subtracting them from the consumed amount. I think this should be doable. Maybe I can find some time to implement this on the weekend.

giovannivelludo commented 2 years ago

@EmilJunker I built the app using the code from the master branch and I can't create new foods, when I click the ✔ on the top right after inserting all the data nothing happens. I'm not sure if this is an issue on my end, if it was introduced in your PR or in one of the previous commits after release 3.4.2. It doesn't happen in version 3.4.2 even when built by myself.

EmilJunker commented 2 years ago

@giovannivelludo Yeah, I can confirm that it's not possible to create foods in the latest build. This issue must have been introduced by one of my previous commits. I'm glad that you noticed. I'll try to get this fixed quickly, shouldn't be too hard...

giovannivelludo commented 2 years ago

It came to my mind that if a user has set some goals as a % of energy intake and others as a fixed number, then it's wrong to compute the value in grams of the % goals as: (total kcals + exercise kcals) * % goal

Instead it should be: (total kcals + exercise kcals - kcals from fixed goals) * % goal

It's not important for me and I don't care if it gets fixed, but I though I'd share anyway.

EmilJunker commented 2 years ago

I think this depends on how exactly you set your goals. For example, if you have a fixed goal for protein, and want the remaining energy to be split evenly between carbs and fat, would you set your goals for carbs and fat to 50% each? Wouldn't this mean that your total energy intake is above your energy goal if you reach all three macro nutrient goals? I think you probably would rather set the goals to something like 40% each, and in this case the current calculation method would be alright.

giovannivelludo commented 2 years ago

Let's say I have a 50% goal for carbs and 50% for fats, a fixed goal of 70 grams of protein and a goal of 2500 kcals. With no exercise, using my second formula we get the following carbs goal in kcals: (2500 + 0 - (70 4)) 0.5 = 1110 kcal, which corresponds to 277.5 grams of carbs The fats goal in kcals is the same, corresponding to 123.333... grams of fat. If we sum calories from each macronutrient we get: 123.333... 9 + 277.5 4 + 70 * 4 = 2500 kcal

If exercise is added, each % goal is still computed correctly because exercise calories are simply added to the total before doing any other computation.

EmilJunker commented 2 years ago

I understand what you're saying, but my point was that most users would interpret "goal as percentage of energy intake" to mean that if you set your carbs goal to 50%, then 50% of your energy will come from carbs. There is no mention of first subtracting absolute goals or something like that. So if you set your carbs goal to 50%, then you shouldn't be surprised that the used reference value is for the calculation is 50% of your total energy (plus energy burned in exercises). In fact, this is exactly what I would expect as a user.