Passio Nutrition-AI
  • Nutrition-AI SDK Overview
  • Guides
    • Nutrition AI SDK
      • SDK Key and minimum requirements
      • Installation
      • Configure the SDK
      • Use Cases
        • Food recognition
        • Nutrition data
        • Barcode scanning
        • Nutrition Facts scanning
        • Search, Food Icons, RefCode
        • Speech recognition
        • Nutrition Advisor
        • Suggestions and Meal Plans
        • User created foods and reports
    • iOS SDK Docs
      • Before getting started
      • Getting the ml models to the device
      • Run the demos first
      • Adding Passio SDK into your project
      • Initialize and configure the SDK
      • Start/Stop food detection
      • Food Recognition Delegate
      • Migration from SDK 1.4.X to 2.x
      • SDK API
      • Quick Start Guide
        • Installation
        • Configure the SDK (UIKit)
        • Recognise food using image
        • Food Details
    • Android SDK Docs
      • Getting started
        • Include the library
        • Camera
        • SDK Initialization and Configuration
        • Food detection session
        • Visual, Barcode and Packaged Food detection
        • Nutritional Database
        • Sandbox app
      • Troubleshooting on Android
      • Migration from SDK version 1.4.x to 2.x
      • Quick Start Guide
        • Importing the Android SDK to a project
        • Configure SDK and handle the result
        • RecognizeImageRemote
        • Food Details
    • React Native SDK Docs
      • Getting Started
        • Installation
        • SDK Initialization and Configuration
      • API Reference
        • configure & requestCameraAuthorization
        • recognizeImageRemote
        • searchForFood & searchForFoodSemantic
        • startFoodDetection
          • FoodDetectionEvent
        • fetchFoodItemForProductCode
        • fetchFoodItemForRefCode
        • fetchFoodItemForDataInfo
        • startNutritionFactsDetection
        • fetchFoodItemForPassioID
        • recognizeSpeechRemote
        • Fetch Nutrients
        • onDowloadingPassioModelCallBacks
        • detectFoodFromImageURI
        • addToPersonalization
        • updateLanguage
        • fetchHiddenIngredients
        • fetchVisualAlternatives
        • fetchPossibleIngredients
      • Properties
        • PassioFoodItem
        • PassioFoodDataInfo
        • PassioFoodAmount
        • PassioIngredient
        • PassioNutrients
        • UnitMass
        • ServingUnit
        • ServingSize
        • PassioSearchResult
        • NutritionFacts
        • PassioNutritionPreview
        • PassioSpeechRecognitionModel
        • PassioLogAction
        • PassioAdvisorFoodInfo
        • FoodCandidates
        • FoodDetectionEvent
        • NutritionDetectionEvent
        • DetectedCandidate
        • BarcodeCandidate
        • PackagedFoodCode
        • AmountEstimate
        • ImagesInfo
        • PassioStatus
        • FoodDetectionEvent
        • NutritionFacts
        • PassioMealPlan
        • PassioMealPlanItem
      • Nutriton Advisor
        • initConversation
        • sendMessage
        • sendImage
        • Guide
          • useNutritionAdvisor
        • Properties
          • PassioAdvisorResponse
          • PassioAdvisorMessageResultStatus
          • PassioAdvisorResultStatus
      • Quick Start Guide
        • Installation
        • Configure the SDK
        • RecognizeImageRemote
        • Food Detail
      • Guide
        • Integrate SDK Setup
        • Integrate Quick Scan
        • Integrate Food Search
        • Integrate Food Editor with Recipe
        • Integrate MealPlan
        • Integrate Suggestions
        • Integrate recognizeImageRemote
      • Components
        • DetectionCameraView
        • PassioIconView
      • Changelog
      • More
        • Display Macro Chart
          • MockFood
          • Utils PassioNutrient
        • Display Micro Progress
        • Getting nutrition value for a FoodItem
        • Getting nutrition value for a Recipe
        • Recalculate the nutrition value based on serving size options.
      • Migrations
        • Migrating from SDK 2.X to version 3.X
        • Structure Migrations From SDK 3.X to SDK 2.X
        • [Deprecated] Migrating from SDK 1.X to version 2.X
        • [Deprecated] Getting Started (v1)
          • Installation
          • SDK Initialization and Configuration
          • Start food detection
          • FoodDetectionEvent
          • Nutritional Database
      • Troubleshooting on RN
      • V2
        • Getting Started
          • Installation
          • SDK Initialization and Configuration
          • Start food detection
          • FoodDetectionEvent
        • RN SDK API
          • Properties
            • PersonalizedAlternative
            • FoodSearchResult
            • PassioNutrient
            • FoodDetectionEvent
            • DownloadModelCallBack
            • UPCProduct
            • ServingUnit
            • PassioStatus
            • PassioIDAttributes
            • PassioIDEntityType
            • PassioFoodItem
            • PassioRecipe
            • ServingSize
            • Measurement
            • UnitMass
            • NutritionFacts
        • Food Image
        • Search Food Item
        • Quick Scan
        • Multi Scan
        • MealPlan
        • Recipe
      • How do I Integrate a Passio SDK in EXPO?
    • Flutter SDK Docs
      • Getting Started
    • Before You Continue
    • Setup For Android
    • Initialize and configure the SDK
  • Fundamentals
    • Nutrition-AI Developer FAQ
      • Nutrition Data
      • Supported Phones
      • Security
      • Testing Volume Estimation
      • Testing Nutrition-AI SDK
      • Nutrition-AI Test Methodology
    • Nutrition API - Mobile SDK interoperability
      • JSON Response parsing
  • Versions
    • 3.2.4
      • SDK Key and minimum requirements
      • Installation
      • Configure the SDK
      • Use Cases
        • Food recognition
        • Nutrition data
        • Barcode scanning
        • Nutrition Facts scanning
        • Search, Food Icons, RefCode
        • Speech recognition
        • Nutrition Advisor
        • Suggestions and Meal Plans
        • User created foods and reports
    • 3.2.2
      • SDK Key and minimum requirements
      • Installation
      • Configure the SDK
      • Use Cases
        • Food recognition
        • Nutrition data
        • Barcode scanning
        • Nutrition Facts scanning
        • Search, Food Icons, RefCode
        • Speech recognition
        • Nutrition Advisor
        • Suggestions and Meal Plans
        • User created foods and reports
    • 3.2.0
      • SDK Key and minimum requirements
      • Installation
      • Configure the SDK
      • Use Cases
        • Food recognition
        • Nutrition data
        • Barcode scanning
        • Nutrition Facts scanning
        • Search, Food Icons, RefCode
        • Speech recognition
        • Nutrition Advisor
        • Suggestions and Meal Plans
    • 3.1.4
      • SDK Key and minimum requirements
      • Installation
      • Configure the SDK
      • Use Cases
        • Food recognition
        • Nutrition data
        • Barcode scanning
        • Search, Food Icons, RefCode
        • Speech recognition
        • Nutrition Advisor
        • Suggestions and Meal Plans
Powered by GitBook
On this page
  • PassioFoodItem
  • PassioFoodAmount
  • PassioIngredient
  • Fetching nutrients
  • Single food item vs recipe
  • UI Example
Export as PDF
  1. Versions
  2. 3.2.4
  3. Use Cases

Nutrition data

The main object containing the nutritional information is called PassioFoodItem. This object is fetched from Passio's backend using one of several fetchFoodItemFor... functions.

PassioFoodItem

The PassioFoodItem is a top level object that can represent a single food like a banana, or a complex recipe like caesar salad.

public struct PassioFoodItem: Codable {
    public let id: String
    public let name: String
    public let details: String
    public let iconId: String
    public let licenseCopy: String
    public let amount: PassioNutritionAISDK.PassioFoodAmount
    public let ingredients: [PassioNutritionAISDK.PassioIngredient]
    public let refCode: String?
}
data class PassioFoodItem(
    val id: String,
    val refCode: String,
    val name: String,
    val details: String,
    val iconId: String,
    val amount: PassioFoodAmount,
    val ingredients: List<PassioIngredient>,
)
export interface PassioFoodItem {
  refCode?: RefCode
  name: string
  details?: strin
  iconId: PassioID | string
  amount: PassioFoodAmount
  ingredients?: PassioIngredient[]
  weight: UnitMass
  isOpenFood?: boolean
  openFoodLicense?: string
  id: string
}
class PassioFoodItem {
  final PassioFoodAmount amount;
  final String details;
  final String iconId;
  final String id;
  final List<PassioIngredient> ingredients;
  final String name;
  final String refCode;
  final PassioID? scannedId;
 }
  • The name attribute is used to display the name of the food, while the details contains additional information like the brand of the food or the name of the food which was used to populate the nutritional data

  • iconId is used with the SDK function fetchIconFor to fetch a small image of the food

  • refCode is a parameter that can be used later on to retrieve the full food item again

  • amount details the available serving size as well as the currently selected serving quantity and unit, used when calculating nutrients

There are three functions that can be used to fetch nutrient information for the PassioFoodItem:

PassioNutritionAI.shared.fetchFoodItemFor(passioID: "VEG0025") { (foodItem) in
        
  if let foodItem {
  
      // Getting nutrients for the referent 100 grams
      let nutrientsRef = foodItem.nutrientsReference()
            
      // Getting nutrients for a specific weight
      let nutrients250g = foodItem.nutrients(weight: Measurement<UnitMass>(value: 250.0, unit: .grams))
      
      // Getting nutrients using the amount->selectedQuantity and
      // amount->selectedUnit
      let nutrientsServing = foodItem.nutrientsSelectedSize()
            
      // Weight of the ingredients
      let weight = foodItem.weight()
  }
}
PassioSDK.instance.("VEG0025") { foodItem ->
    // Getting nutrients for the referent 100 grams
    val nutrientsRef = foodItem!!.nutrientsReference()
    // Getting nutrients for a specific weight
    val nutrients250g = foodItem.nutrients(UnitMass(Grams, 250.0))
    // Getting nutrients using the amount->selectedQuantity and
    // amount->selectedUnit
    val nutrientsServing = foodItem.nutrientsSelectedSize()
    // Weight of the ingredients
val weight = foodItem.weight()
}
   const passioFoodItem = await PassioSDK.fetchFoodItemForPassioID("VEG0025")
  
   // Getting nutrients for the referent 100 grams
   const nutrients =  PassioSDK.getNutrientsReferenceOfPassioFoodItem(passioFoodItem)
   
   // Getting nutrients for a specific weight
   const nutrients =  PassioSDK.getNutrientsOfPassioFoodItem(passioFoodItem,{unit:'g',value:250})
  
   // Getting nutrients using the amount->selectedQuantity and
   // amount->selectedUnit
   const nutrients =  PassioSDK.getNutrientsSelectedSizeOfPassioFoodItem(passioFoodItem)
 
   // Weight of the ingredients
   const val weight = passioFoodItem.weight()

    final foodItem = await NutritionAI.instance.fetchFoodItemForPassioID('VEG0025');
    // Getting nutrients for the referent 100 grams
    final nutrientsRef = foodItem!.nutrientsReference();
    // Getting nutrients for a specific weight
    final nutrients250g =
        foodItem.nutrients(UnitMass(250.0, UnitMassType.grams));
    // Getting nutrients using the amount->selectedQuantity and
    // amount->selectedUnit
    final nutrientsServing = foodItem.nutrientsSelectedSize();
    // Weight of the ingredients
    final weight = foodItem.weight();

The weight function is used to fetch the sum mass of all of the ingredients.

PassioFoodAmount

This class holds the information about possible serving sizes and serving units, as well as the currently selected unit and quantity. Example of values for food item "apples"

  • serving units: small (2-3/4" dia), medium, large (3-1/4" dia), cup, oz, gram, ...

  • serving sizes: 1 small (2-3/4" dia), 2 cups, 100 grams, ...

  • selected quantity: 1

  • selected unit: medium

Serving units holds the list of all of the units that the system has the correct weight for. Serving sizes holds the list of predefines matches of a quantity and a serving unit. The selected quantity and unit are used to calculate nutrients on the PassioFoodItem level. While these values can be changed, the initial values are set by the SDK as a default portion.

PassioIngredient

Every PassioFoodItem has a list of ingredients. A food ingredient holds the nutritional information along with the portion size of each ingredient.

public struct PassioIngredient: Codable {
    public let id: String
    public let name: String
    public let iconId: String
    public let amount: PassioFoodAmount
    public let referenceNutrients: PassioNutrients
    public let metadata: PassioFoodMetadata
    public let refCode: String?
}
data class PassioIngredient(
    val id: String,
    val refCode: String,
    val name: String,
    val iconId: String,
    val amount: PassioFoodAmount,
    val referenceNutrients: PassioNutrients,
    val metadata: PassioFoodMetadata,
)
export interface PassioIngredient {
  name: string
  id: PassioID
  iconId: PassioID | string
  weight?: UnitMass
  referenceNutrients?: PassioNutrients
  nutrients?: PassioNutrients
  metadata?: PassioFoodMetadata
  amount?: PassioFoodAmount
}
class PassioIngredient {
  final PassioFoodAmount amount;
  final String iconId;
  final String id;
  final PassioFoodMetadata metadata;
  final String name;
  final String refCode;
  final PassioNutrients referenceNutrients;
}

Similarly to PassioFoodItem, the ingredient also has a name, iconId, refCode, and amount.

But, the most important part of the ingredient class is the PassioNutrients and it's methods. The referenceNutrients attribute holds the referent (in most cases 100 grams) macronutrients and micronutrients, and are used to calculate the resulting nutrient values when changing serving sizes of the whole PassioFoodItem.

Also, an ingredient has PassioMetadata field, storing the information on the origin of the nutritional data, barcode value, possible ingredients (if the PassioFoodItem is a packaged food), and a list of tags.

Fetching nutrients

PassioNutritionAI.shared.fetchFoodItemFor(passioID: "VEG0025") { (foodItem) in
  if let foodItem {
     let nutrients = foodItem.nutrientsReference()
     // Calories for 100 grams, values is in kCal
     let calories = nutrients.calories()?.value
     // Carbs for 100 grams, value is in grams
     let carbs = nutrients.carbs()?.value
     // Potassium for 100 grams, value is in milligrams
     let potassiumMilli = nutrients.potassium()?.value
     // Potassium for 100 grams, value is in grams
     let potassiumGrams = nutrients.potassium()?.gramsValue
  }
}
PassioSDK.instance.fetchFoodItemForPassioID("VEG0025") { foodItem ->
    val nutrients = foodItem!!.nutrientsReference()
    // Calories for 100 grams, values is in kCal
    val calories = nutrients.calories()?.value
    // Carbs for 100 grams, value is in grams
    val carbs = nutrients.carbs()?.value
    // Potassium for 100 grams, value is in milligrams
    val potassiumMilli = nutrients.potassium()?.value
    // Potassium for 100 grams, value is in grams
    val potassiumGrams = nutrients.potassium()?.gramsValue()
}
const passioFoodItem = await PassioSDKBridge.fetchFoodItemForPassioID("VEG0025")

   const nutrients =  PassioSDK.getNutrientsReferenceOfPassioFoodItem(passioFoodItem)
    // Calories for 100 grams, values is in kCal
     let calories = passioNutrients.calories?.value
     // Carbs for 100 grams, value is in grams
     let carbs = passioNutrients.carbs?.value
     // Potassium for 100 grams, value is in milligrams
     let potassiumMilli = passioNutrients.potassium?.value
    final foodItem = await NutritionAI.instance.fetchFoodItemForPassioID('VEG0025');
    final nutrients = foodItem!.nutrientsReference();
    // Calories for 100 grams, values is in kCal
    final calories = nutrients.calories?.value;
    // Carbs for 100 grams, value is in grams
    final carbs = nutrients.carbs?.value;
    // Potassium for 100 grams, value is in milligrams
    final potassiumMilli = nutrients.potassium?.value;
    // Potassium for 100 grams, value is in grams
    final potassiumGrams = nutrients.potassium?.gramsValue();

Single food item vs recipe

The PassioFoodItem class encompasses both single food items like an avocado as well as items with multiple ingredients such as homemade caprese salad. The difference between these two items is how is the PassioFoodAmount calculated from the top-level PassioFoodItem.

Homemade caprese salad:

  • weight(): 176.5 grams

  • amount->selectedQuantity = 1

  • amount->selectedUnit = "serving"

  • ingredients: 1. fresh sliced cheese, 84 grams, amount->selectedQuantity = 3, amount-> selectedUnit = "oz" 2. balsamic vinegar, 16 grams, amount->selectedQuantity = 1, amount-> selectedUnit = "tbsp" 3. fresh basil, 3 grams, amount->selectedQuantity = 6, amount-> selectedUnit = "leaves" 4. tomatoes, 60 grams, amount->selectedQuantity = 3, amount-> selectedUnit = "medium slice" 5. olive oil, 13.5 grams, amount->selectedQuantity = 1, amount-> selectedUnit = "tbsp"

Invoking the function foodItem.nutrientsServingSize() will fetch the nutrients for the whole recipe, calculated by the weight of the serving size "1 serving".

Avocado:

  • weight(): 201 grams

  • amount->selectedQuantity = 1

  • amount->selectedUnit = "avocado"

  • ingredients: 1. avodaco, raw, 201 grmas, amount->selectedQuantity = 1, amount->selectedUnit = "avocado"

A single food item will always have only one ingredient. Also, the amount object of the PassioFoodItem will be the same as the amount of the first ingredient. The ingredient is the item in the database used for nutritional data. For example, If the SDK recognises "milk" during the visual detection process, the default food item for "milk" is "milk, whole, 3.25% milkfat, without added vitamin a and vitamin d".

UI Example

  1. Fetch the PassioFoodItem

  2. Use the nutrientsSelectedSize->calories, carbs, protein and fat to show the marcos

  3. Use the amount class to create the serving size view

  4. Give the user the option to log the food

PreviousFood recognitionNextBarcode scanning

Last updated 8 months ago

Use the name, details and to create the food header view

iconId