SDK representation of the database reference object
Does not contain all of the nutritional data, but has reference fields that can be used to fetch the full data
Mapping function to a PassioFoodDataInfo object from a list of JSON objects, where the response.results represents an array of JSON objects:
PassioFoodItem
Contains all of the nutritional information for a single database entry
Top-level object that contains one or more ingredients
Parsing from search routes
Typically used in the SDK when fetching from a reference PassioFoodDataInfoobject
Mapping function that creates a PassioFoodItem, using a ResponseFoodItem that represents a top level JSON object, and parsing functions for PassioIngredientandPassioFoodAmount:
Parsing from packaged product routes
Used in the SDK when fetching from a productCode, usually during barcode scanning
Mapping function that creates a PassioFoodItem, using a ResponseFoodItem that represents a top level JSON object, and parsing functions for PassioIngredientandPassioFoodAmount:
PassioIngredient
Contains nutritional and serving size data for a single food item
Mapping function that creates a PassioIngredient, using a ResponseIngredient that represents a top level JSON object, and parsing functions for PassioNutrients, PassioFoodAmount and PassioFoodMetadata:
PassioFoodAmount
SDK representation of serving portions, including serving quantities, units and their weights
If there are no portions in the JSON response, the SDK manually creates a 100 grams serving size
If the PassioFoodItem contains more then one ingredient, and there are no portions in the JSON response, the SDK will manually create a serving size called "Serving" , with it's weight being the summed up weight of all of the ingredients
The SDK offers conversion between units cup, teaspoon and tablespoon. If the JSON response contains only one or two of these units, the SDK will calculate the remaning ones and add them to the list of serving sizes
Mapping function that creates a PassioFoodAmount, using a ResponsePortions that represents a top level JSON object:
PassioNutrients
Data class that contains all of the macro and micro nutrients supported by the Passio Nutritional database
The SDK parses the values for Calories and VitaminA differently from other nutrients. Calories are parsed as UnitEnergy, and VitaminA has a Double value
The nutrientDefaults serves as a helper list that references the nutrient field, it's JSON "id" and JSON "shortName"
Mapping function that creates a PassioNutrients object, using a list of ResponseNutrient objects that represent a top level JSON array
PassioFoodMetadata
Contains miscellaneous data about the food ingredient like it's data source, product code, tags and ingredient description
Mapping function that creates a PassioFoodMetadata, using a ResponseIngredient that represents a top level JSON object:
PassioAdvisorFoodInfo
Represents a object returned by Passio's LLM services
Mapping function that creates a list of PassioAdvisorFoodInfo objects, using a json String as a top level JSON object:
PassioSpeechRecognitionModel
Represents a result from the speech recognition service
Mapping function that creates a list of PassioSpeechRecognitionModel objects, using a result String as a top level JSON array, also usign PassioFoodDataInfo and PassioAdvisorFoodInfomapping:
fun fromResponse(result: ResponseIngredient?): PassioFoodMetadata {
val metadata = PassioFoodMetadata()
if (result == null) {
return metadata
}
if (result.origin != null) {
val originsTemp = mutableListOf<PassioFoodOrigin>()
result.origin!!.forEach {
originsTemp.add(PassioFoodOrigin(it.id, it.source, result.licenseCopy))
}
metadata.foodOrigins = originsTemp
}
metadata.barcode = result.branded?.productCode
metadata.ingredientsDescription = result.branded?.ingredients
metadata.tags = result.tags
return metadata
}
private fun parseIngredients(json: String): List<PassioAdvisorFoodInfo> {
val jArray = JSONArray(json)
val list = mutableListOf<PassioAdvisorFoodInfo>()
for (i in 0 until jArray.length()) {
val it = ResponseAdvisorItem(jArray.getJSONObject(i).toString())
val foodDataInfo = PassioFoodDataInfo(
it.refCode,
it.shortName.ifEmpty { it.displayName },
it.brandName,
it.iconId,
it.score,
it.scoredName,
it.labelId,
it.type,
it.resultId,
true,
it.nutritionPreview.toDataModel(),
it.tags
)
val model = PassioAdvisorFoodInfo(
it.ingredientName,
it.portionSize,
it.weightGrams,
foodDataInfo,
null,
null,
PassioFoodResultType.FOOD_ITEM
)
list.add(model)
}
return list
val jArray = JSONArray(result)
val list = mutableListOf<PassioSpeechRecognitionModel>()
for (i in 0 until jArray.length()) {
val voiceItem = ResponseVoice(jArray.getJSONObject(i).toString())
voiceItem.items.forEach {
val foodDataInfo = PassioFoodDataInfo(
it.refCode,
it.shortName.ifEmpty { it.displayName },
it.brandName,
it.iconId,
it.score,
it.scoredName,
it.labelId,
it.type,
it.resultId,
true,
it.nutritionPreview.toDataModel(),
it.tags
)
val dataInfo = PassioAdvisorFoodInfo(
it.ingredientName,
it.portionSize,
it.weightGrams,
foodDataInfo,
null,
null,
PassioFoodResultType.FOOD_ITEM,
)
val model = PassioSpeechRecognitionModel(
voiceItem.action.toLogAction(),
voiceItem.mealTime.toMealTime(),
voiceItem.date,
dataInfo
)
list.add(model)
}
}
internal fun String.toLogAction(): PassioLogAction {
return when (this.lowercase()) {
"add" -> PassioLogAction.ADD
"remove" -> PassioLogAction.REMOVE
else -> PassioLogAction.NONE
}
}
internal fun String.toMealTime(): PassioMealTime? {
return when (this.lowercase()) {
"breakfast" -> PassioMealTime.BREAKFAST
"lunch" -> PassioMealTime.LUNCH
"dinner" -> PassioMealTime.DINNER
"snack" -> PassioMealTime.SNACK
else -> null
}
}