Skip to content
Kyle Falconer edited this page Aug 27, 2017 · 7 revisions

A Sugar is defined in JSON as follows:

{
  "id": "CLOVER_HONEY",
  "combined_sugars_total_pct": 0.794,
  "density__kg_per_m3": 1.423
}
  • id must be unique and also paired to the string resource name associated with this Sugar, for translation purposes. (see below)
  • combined_sugars_total_pct is the total amount of sugar percent by volume or by mass (see below)
  • density__kg_per_m3, optional, is the density of the sugar, as mass per unit volume: f9 (see below)

id

When defining the id:

  1. Pick an id that describes the Sugar. As a naming convention, the id should be in all capitals, underscores are used to separate words, and two underscores are used to separate the type and kind.

    Examples:

    • "clover honey" -> HONEY__CLOVER
    • "red currant" -> CURRANT__RED
    • "maple sap" -> MAPLE_SAP
  2. Ensure the id chosen is unique among the other Sugar definitions. This value is used as the primary key in the database table.

  3. Add an entry in the string resources file at Must-Watch-Android/app/src/main/res/values/strings.xml, using the Sugar's id value as the name attribute, and the XML node's value as the human-readable string:

    <string name="CLOVER_HONEY">clover honey</string>
  4. Run the unit tests to ensure the database loads the new sugar definition correctly.

combined_sugars_total_pct

To find the total sugar percentage of an ingredient, combined_sugars_total_pct, we need to find the mass concentration, f1 using this formula:

f2

Recall that volume is in liters, mass is in kilograms.

For more information, refer to the Wikipedia article on mass concentration.

Example 1: percent sugar content in liquids f7

Using Welch's Grape Juice as an example, the nutrition label shows that sugars from carbohydrates are 36g per 240ml serving. We need to convert these units into liters and kilograms, then put it into the formula:

f3

f4

Example 2: percent sugar content in masses f8

Take Gunter's Pure Clover Honey. The serving size is 1 Tbsp (21g), and the sugars are listed as 16g. Using 21g in the denominator, and converting both values to kg:

f5

f6

density__kg_per_m3

Density can be measured using a hydrometer, or if you're lazy, then try to find it online.

This value is used to convert from volume to mass for sugars that are viscous, like honey, that are commonly measured in both volume and mass units. If this value is not provided, it is assumed that this sugar is measured in mass units.

Clone this wiki locally