Skip to content

Commit

Permalink
Add scripts to extract food data from usda databases
Browse files Browse the repository at this point in the history
  • Loading branch information
Cody Weaver authored and Cody Weaver committed Jan 5, 2024
1 parent 2ba9ea1 commit bd41ea1
Show file tree
Hide file tree
Showing 8 changed files with 7,664 additions and 8 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# Unproccessed USDA database files
brandedFood.json
foundationFoods.json

# Gradle files
.gradle/
build/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class EditRecipeViewModel @Inject constructor(
/**
* ui state model for EditRecipeScreen
*/
private var _recipeState: MutableState<Recipe> = mutableStateOf(Recipe(userId = userId, recipeId = recipeId))
private var _recipeState: MutableState<Recipe> = mutableStateOf(Recipe(userId = userId, id = recipeId))
/**
* public accessor for ui state model
*/
Expand Down Expand Up @@ -91,7 +91,7 @@ class EditRecipeViewModel @Inject constructor(
* Updates ui state model
*/
fun updateRecipeState(recipe: Recipe) {
_recipeState.value = recipe.copy(recipeId = recipeId)
_recipeState.value = recipe.copy(id = recipeId)
}

/**
Expand Down
28 changes: 25 additions & 3 deletions app/src/main/java/com/android/pocketalchemy/model/Ingredient.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,29 @@
package com.android.pocketalchemy.model
import com.google.firebase.firestore.DocumentId
import com.google.firebase.firestore.IgnoreExtraProperties
import androidx.annotation.Keep

/* PLACEHOLDER */
/**
* Ingredient Model class
*/
@Keep
@IgnoreExtraProperties
data class Ingredient(
val name: String = "",
val ingredientId: Int = 0
@DocumentId val id: String? = null,
val name: String? = null,
val category: String? = null,
val calories: MeasuredInt? = null,
val protein: MeasuredInt? = null,
val fat: MeasuredInt? = null,
val carbs: MeasuredInt? = null,
val sodium: MeasuredInt? = null,
val fiber: MeasuredInt? = null,,
val sugars: MeasuredInt? = null,
val portions: list<MeasuredInt>? = null,
val fdcId: String? = null
)

/**
* TODO: extract possible units from ingredients and make enum
*/
data class MeasuredInt(val value: Int, val unit: String)
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import com.google.firebase.firestore.IgnoreExtraProperties
@IgnoreExtraProperties
@Keep
data class Recipe(
@DocumentId val recipeId: String? = null,
@DocumentId val id: String? = null,
val userId: String? = null,
val title: String? = null,
val subtitle: String? = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ fun RecipeListCard(

Card(
onClick = {
onNavigateToEditRecipe(recipe.recipeId)
onNavigateToEditRecipe(recipe.id)
},
enabled = true,
elevation = CardDefaults.cardElevation(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class RecipeRepository @Inject constructor(
* @param recipe Recipe object to insert into collection
*/
fun insertRecipe(recipe: Recipe) {
recipe.recipeId?.let { id ->
recipe.id?.let { id ->
firestore.collection(RECIPE_COLLECTION).document(id)
.set(recipe)
.addOnSuccessListener {
Expand Down
Loading

0 comments on commit bd41ea1

Please sign in to comment.