Răsfoiți Sursa

TG-29 TG-28: Add UX metadata mapping doc and fix seeding parser indentation

FerRo988 4 săptămâni în urmă
părinte
comite
4244f7e81d
2 a modificat fișierele cu 62 adăugiri și 29 ștergeri
  1. 36 0
      Metadata_Tags_UX_Mapping.md
  2. 26 29
      seed_food_db.py

+ 36 - 0
Metadata_Tags_UX_Mapping.md

@@ -0,0 +1,36 @@
+# UX Metadata Mapping for Database Searching
+
+**Task:** #29 mapped to User Story 04
+**Objective:** Map out metadata tags for optimal user searching that will integrate with our future fast search engine.
+
+## Core Search Tags
+The system utilizes two primary metadata identifiers isolated in the SQLite database to organize search layouts and autocomplete ranking dynamically without heavy computing:
+
+1. **`name` (The Primary UX Key)**
+   - **Type:** String (UTF-8)
+   - **Index:** `COLLATE NOCASE`
+   - **UX Purpose:** Serves as the fuzzy-matching target for the user's keystrokes. When a user types "Chic", the engine searches this exact metadata tag to autocomplete "Chicken Breast". 
+   - **Case-insensitivity:** Hardcoded at the database level so the UX never fails on capitalization mistakes.
+
+2. **`category` (The Secondary UX Key)**
+   - **Type:** String (Enum-like classification)
+   - **UX Purpose:** Used to visually group results for the user. For instance, search results can display a pill badge under the name saying "Sourced Ingredient" versus "User Saved Meal", allowing the user to instantly deduce where the data came from.
+
+## Nutrition Payload Tags
+When a user clicks a matched item in the UX, the following metric tags are instantly injected into the visual charts:
+- `calories` (kcal)
+- `protein_g` (grams)
+- `fat_g` (grams)
+- `carbs_g` (grams)
+- `fiber_g` (grams)
+- `sugar_g` (grams)
+- `sodium_mg` (milligrams)
+- `vitamin_a_iu`
+- `vitamin_c_mg`
+- `calcium_mg`
+- `iron_mg`
+- `potassium_mg`
+- `cholesterol_mg`
+
+### Conclusion
+By mapping these heavily typed numeric tags directly to the UI, the frontend Javascript can seamlessly pipe JSON data directly into HTML element IDs without additional filtering, allowing the fastest possible response times.

+ 26 - 29
seed_food_db.py

@@ -50,8 +50,8 @@ def fetch_and_seed():
     for row in reader:
         if len(row) < 3: continue
         
-        # In this dataset, index 1 is name
-        name = row[1] if len(row) > 1 else row[0]
+        # In this dataset, index 0 is always the food name
+        name = row[0]
         
         try:
             calories = float(get_val(row, ['calorie', 'energy']))
@@ -75,33 +75,30 @@ def fetch_and_seed():
         if cursor.fetchone():
             continue
 
-        try:
-            cursor.execute('''
-                INSERT INTO foods (name, category, calories, protein_g, fat_g, carbs_g, fiber_g, sugar_g, sodium_mg, vitamin_a_iu, vitamin_c_mg, calcium_mg, iron_mg, potassium_mg, cholesterol_mg, source)
-                VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
-            ''', (
-                name[:100],
-                "Sourced Ingredient",
-                calories,
-                protein,
-                fat,
-                carbs,
-                fiber,
-                sugar,
-                sodium_mg,
-                vitamin_a,
-                vitamin_c,
-                calcium,
-                iron,
-                potassium,
-                cholesterol,
-                'Sourced_CSV'
-            ))
-            count += 1
-            if count >= 8000:  # Seed max 8000 to keep it lightweight locally
-                break
-        except Exception as e:
-            continue
+        cursor.execute('''
+            INSERT INTO foods (name, category, calories, protein_g, fat_g, carbs_g, fiber_g, sugar_g, sodium_mg, vitamin_a_iu, vitamin_c_mg, calcium_mg, iron_mg, potassium_mg, cholesterol_mg, source)
+            VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
+        ''', (
+            name[:100],
+            "Sourced Ingredient",
+            calories,
+            protein,
+            fat,
+            carbs,
+            fiber,
+            sugar,
+            sodium_mg,
+            vitamin_a,
+            vitamin_c,
+            calcium,
+            iron,
+            potassium,
+            cholesterol,
+            'Sourced_CSV'
+        ))
+        count += 1
+        if count >= 8000:  
+            break
 
     conn.commit()
     conn.close()