ivoxavier / kaltracker

Stores yours calories ingestion on ubuntu touch phone
GNU General Public License v3.0
2 stars 3 forks source link

Calories in kcal vs kJ #13

Open Blackoverflow opened 2 years ago

Blackoverflow commented 2 years ago

The recommended calories seem to be calculated in kcal but the calories given for a scanned foot item (Fritz-Kola EAN 4260107220015) seem to be in kJ.

How it is:

  1. No units are displayed for calorie values.
  2. Calorie values in different units are subtracted by the kalTracker.

What I wish for:

  1. It would be nice to have the unit of values displayed.
  2. All calculations should be done with values in the same unit (maybe kcal, because that feels to be the commonly used unit).
ivoxavier commented 2 years ago

Hi Blackoverflow, thank you for your feedback. I will improve this in future releases

c0d3xd3v commented 2 months ago

I think it is realy a bug, some items add kcal some kj. I have investigated the openfood api and we can filter out the kcal numbers to compute right. I think it musst be here :

qml/components/IsProductFoundDialog.qml

{
            var _json = openFoodFactJSON.model.get(0);
            if (typeof _json !== "undefined" && typeof _json.product_name !== "undefined" ) {
                logical_fields.ingestion.product_name = _json.product_name
                logical_fields.ingestion.nutriscore = (typeof _json.nutriscore_grade == "undefined") ? "a" :  _json.nutriscore_grade
                logical_fields.ingestion.cal = (typeof _json.nutriments.energy_value == "undefined") ? 0 : _json.nutriments.energy_value
                logical_fields.ingestion.fat = (typeof _json.nutriments.fat_100g == "undefined") ? 0.0 : _json.nutriments.fat_100g
                logical_fields.ingestion.protein = (typeof _json.nutriments.proteins_100g == "undefined") ? 0.0 : _json.nutriments.proteins_100g
                logical_fields.ingestion.carbo = (typeof _json.nutriments.carbohydrates_100g == "undefined") ? 0.0 : _json.nutriments.carbohydrates_100g
                logical_fields.ingestion.nova_groups = (typeof _json.nova_groups == "undefined") ? "0" : _json.nova_groups
                next_button.enabled = true
                loading_circle.running = false
                loading_circle.visible = false
            }else{
                loading_circle.running = false
                loading_circle.visible = false
                enter_manually.visible = true
                is_code_empty = true
            }
        }
    }

the _json.nutriments.energy_value to not contain kcal consistently so we can use energy-kcal , energy-kcal_100g that holds the needed kcal value. but i do not know right now how to extract it from _json.nutriments.