This discussion is archived
5 Replies Latest reply: Nov 9, 2012 9:24 AM by Dmitriy Kolasnikov RSS

Nutrition Panel - Carbohydrate by Difference

Sinfo_Cesare Newbie
Currently Being Moderated
Our customer use to calculate Carbohydrate quantity present in a finish good “by Difference”: Carbohydrate by Difference is calculated using the below equation:
Carbohydrate by difference = 100 – (Protein + Fat + Fibre + Moisture + Ash).

How could we replicate this kind of equation to represent the quantity for a specific component in Nutrition Panel?

Thanks,
Regards,
Cesare
  • 1. Re: Nutrition Panel - Carbohydrate by Difference
    Ron M Pro
    Currently Being Moderated
    Using calculated extended attributes, you can create your own class to do this, and call that class in your Extended Attribute calculation script. In Extensibility Pack 2.5, we have a class that does something very similar, called OtherCarbohydratesCalculator.

    You can find it in ReferenceImplementations\CalculationExtensions\SourceCode\CalculationExtensions\ExtendedAttributes

    The Agile_Product_Lifecycle_Management_for_Process_Extended_Attribute_Calculation_Guide.pdf (also available in the Extensibility Pack) will walk you through extended attribute calculation.
  • 2. Re: Nutrition Panel - Carbohydrate by Difference
    StefanoMeleSinfo Newbie
    Currently Being Moderated
    Hi Ron,
    thank you for your quick answer.

    Just to check if I've well understand: if we manage "carbohydrate by different" as an extended attribute, the only way to show this value to the user is to insert that attribute in an extended data tab.
    Does this mean that user must switch between 2 tab to read all the nutrition informations?

    I.e. in the "nutrition tab" user can see values of fat, fibres, sugar and so content in a finis good, but to read value of carbohydrate in the same item, he has to change tab.

    Our request is to calculate the carbohydrate value throught a specific formuala, but to represent this value togheter with other nutriton values within nutrition panel.

    It seems to us that the system use a similar logic to calculate KJ (KiloJoule) value.

    Thank you,
    Regards,
    Stefano&Cesare
  • 3. Re: Nutrition Panel - Carbohydrate by Difference
    Ron M Pro
    Currently Being Moderated
    Good point.
    One thing you can try instead then is to do it through a Validator. On a Save event, you could fire a validator that calculates the carbohydrates by difference and populates the nutrient value on the specification. You'd have to test various scenarios, but that seems like an approach that could work.
  • 4. Re: Nutrition Panel - Carbohydrate by Difference
    Ron M Pro
    Currently Being Moderated
    After further investigation, it looks like there is a way to do this more easily. We do have the ability to handle nutrient calculations to a certain degree, but it may not be well documented. I'll find out more and get back to you soon.
  • 5. Re: Nutrition Panel - Carbohydrate by Difference
    Dmitriy Kolasnikov Explorer
    Currently Being Moderated
    Hello, Cesare;

    You can create methods that calculate a nutrient value based on related nutrient values, but you will need to create and manage them under CustomerSettings/CustomerNutrientItems/NutrientItemConfig node in Config\Custom\CustomerSettings.config file.
    <ul>
    <li>Define a nutrient which will contain calculation where the id attribute matches the GSMID of a nutrient.</li>
    <ol>
    <li>You can create multiple formulas for each nutrient by specifying multiple formula nodes.</li>
    <li>Each formula has a unique id used for merging.</li>
    </ol>
    <li>Define an algebra attribute for each node.</li>
    <ol>
    <li>It has a dual purpose in that it is used to actually calculate the nutrient value and to display the formula to the user.</li>
    <li>It uses the same jscript engine that is used for calculated EAs to calculate the value.</li>
    <li>If it sees something in the form of {<some value>} it will look up a nutrient value with GSMID matching <some value>.</li>
    <li>The calculations are always performed in the base UOMs,.</li>
    <ol>
    <li>Thus, [17000 * ]{lblProtein} + [37000 * ]{lblTotalFat} + [17000 * ]{lblCarbohydrates}" Represents a common formula of 4 * Protein + 9 * Fat + 4 * carbs
    Here is how I’ve arrived with 17000 to represent a factor of 4 in a calorie calculation formula:
    KG is a base UOM for mass category. Since we track protein in grams, the system will convert the value into kilograms when it uses it within the formula.
    To account for this I multiplied the coefficient by 1000.
    The base UOM for energy is kJ in our system, while our formula needs to be in kcal. The conversion factor between these 2 UOMs is 0.238845897 in our system.
    Thus, I’ll need to adjust every coefficient by this factor. 4 * 1000 / 0.238845897 ~= 17000</li>
    </ol>
    </ol>
    <li>Now, for a UI display purpose of the formula.</li>
    <ol>
    <li>When you select a method, we display a calculation method using the same formula.</li>
    <li>Everything inside the square brackets is hidden from the user.</li>
    <li>It will look up the translation value for everything containing {}. </li>
    <li>It will use a CalculationMethod name attribute to lookup the translation of a formula display name.</li>
    </ol>
    </ul>

    Dmitriy
    Here is an example based on the above criteria:

    {code}
    { <NutrientItemConfig configChildKey="id" >
    <NutrientItem configChildKey="id" id="lblEnergykJ" active="true" translationCache="CalculatableNutrientService/FormulationMethods" >
    <Formula configChildKey="name" id="lblConvert" algebra="[1.0 * ]{lblCalories}" active="true" translationCache="CalculatableNutrientService/CtlNutritionalAnalysis1,CalculatableNutrientService/FormulationMethods" >
    <CalculationMethod configAttributeOverrideModifier="CanExtend" name="lblConvertFromkCal" active="true" default="false" />
    </Formula>
    <Formula configChildKey="name" id="lblDefaultEnergykJ" algebra="[17000 * ]{lblProtein} + [37000 * ]{lblTotalFat} + [17000 * ]{lblCarbohydrates}" active="true" translationCache="CalculatableNutrientService/CtlNutritionalAnalysis1,CalculatableNutrientService/FormulationMethods" >
    <CalculationMethod configAttributeOverrideModifier="CanExtend" name="lblDefault" active="true" default="true" />
    </Formula>
    <Formula configChildKey="name" id="lblFSANZEnergykJ" algebra="[17000 * ]{lblProtein} + [37000 * ]{lblTotalFat} + [17000 * ]{lblCarbohydrateAvailable} + [8000 * ]{lblDietaryFiber}" active="true" translationCache="CalculatableNutrientService/CtlNutritionalAnalysis1,CalculatableNutrientService/FormulationMethods" >
    <CalculationMethod configAttributeOverrideModifier="CanExtend" name="lblFSANZ" active="true" default="false" />
    </Formula>
    </NutrientItem>

    <NutrientItem configChildKey="id" id="lblCalories" active="true" translationCache="CalculatableNutrientService/FormulationMethods" >
    <Formula configChildKey="name" id="lblConvert" algebra="{lblEnergykJ}[ / 1.0 ]" active="true" translationCache="CalculatableNutrientService/CtlNutritionalAnalysis1,CalculatableNutrientService/FormulationMethods" >
    <CalculationMethod configAttributeOverrideModifier="CanExtend" name="lblConvertFromkJ" active="true" default="false" />
    </Formula>
    <Formula configChildKey="name" id="lblDefaultEnergykCal" algebra="[4.1868 * 4063 * ]{lblProtein} + [4.1868 * 8843 * ]{lblTotalFat} + [4.1868 * 4063 * ]{lblCarbohydrates}" active="true" translationCache="CalculatableNutrientService/CtlNutritionalAnalysis1,CalculatableNutrientService/FormulationMethods" >
    <CalculationMethod configAttributeOverrideModifier="CanExtend" name="lblDefault" active="true" default="true" />
    </Formula>
    <Formula configChildKey="name" id="lblFSANZEnergykCal" algebra="[4.1868 * 4063 * ]{lblProtein} + [4.1868 * 8843 * ]{lblTotalFat} + [4.1868 * 4063 * ]{lblCarbohydrateAvailable} + [4.1868 * 1912 * ]{lblDietaryFiber}" active="true" translationCache="CalculatableNutrientService/CtlNutritionalAnalysis1,CalculatableNutrientService/FormulationMethods" >
    <CalculationMethod configAttributeOverrideModifier="CanExtend" name="lblFSANZ" active="true" default="false" />
    </Formula>
    </NutrientItem>

    </NutrientItemConfig>}
    {code}

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points