Delete Essential directory

This commit is contained in:
sosokker 2023-05-02 15:23:55 +07:00 committed by GitHub
parent 17d534b341
commit 5c566e29be
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 0 additions and 235 deletions

View File

@ -1,13 +0,0 @@
import sqlite3
class FoodSearch:
def __init__(self, db_path):
self.conn = sqlite3.connect(db_path)
self.cursor = self.conn.cursor()
def search(self, user_input) -> list:
query = f"SELECT * FROM food_data WHERE product_name LIKE '%{user_input}%'"
self.cursor.execute(query)
results = self.cursor.fetchall()
return results

View File

@ -1,83 +0,0 @@
import sqlite3
conn = sqlite3.connect('food.db')
c = conn.cursor()
# create table
c.execute('''CREATE TABLE food
(id INTEGER PRIMARY KEY AUTOINCREMENT,
product_name TEXT,
brands TEXT,
brands_tags TEXT,
categories TEXT,
categories_tags TEXT,
categories_en TEXT,
origins TEXT,
origins_tags TEXT,
origins_en TEXT,
countries TEXT,
countries_tags TEXT,
countries_en TEXT,
image_url TEXT,
image_ingredients_url TEXT,
image_nutrition_url TEXT,
energy_kcal_100g REAL,
fat_100g REAL,
saturated_fat_100g REAL,
unsaturated_fat_100g REAL,
omega_3_fat_100g REAL,
omega_6_fat_100g REAL,
omega_9_fat_100g REAL,
trans_fat_100g REAL,
cholesterol_100g REAL,
carbohydrates_100g REAL,
sugars_100g REAL,
sucrose_100g REAL,
glucose_100g REAL,
fructose_100g REAL,
lactose_100g REAL,
maltose_100g REAL,
fiber_100g REAL,
soluble_fiber_100g REAL,
insoluble_fiber_100g REAL,
proteins_100g REAL,
salt_100g REAL,
added_salt_100g REAL,
sodium_100g REAL,
alcohol_100g REAL,
vitamin_a_100g REAL,
beta_carotene_100g REAL,
vitamin_d_100g REAL,
vitamin_e_100g REAL,
vitamin_k_100g REAL,
vitamin_c_100g REAL,
vitamin_b1_100g REAL,
vitamin_b2_100g REAL,
vitamin_pp_100g REAL,
vitamin_b6_100g REAL,
vitamin_b9_100g REAL,
vitamin_b12_100g REAL,
bicarbonate_100g REAL,
potassium_100g REAL,
chloride_100g REAL,
calcium_100g REAL,
phosphorus_100g REAL,
iron_100g REAL,
magnesium_100g REAL,
zinc_100g REAL,
copper_100g REAL,
manganese_100g REAL,
fluoride_100g REAL,
selenium_100g REAL,
chromium_100g REAL,
molybdenum_100g REAL,
iodine_100g REAL,
caffeine_100g REAL,
carbon_footprint_100g REAL,
carbon_footprint_from_meat_or_fish_100g REAL,
cocoa_100g REAL)''')
# commit changes and close connection
conn.commit()
conn.close()

View File

@ -1,115 +0,0 @@
class foodItem():
def __init__(self, row):
self.product_name = row['product_name']
self.brands = row['brands']
self.brands_tags = row['brands_tags']
self.categories = row['categories']
self.categories_tags = row['categories_tags']
self.categories_en = row['categories_en']
self.origins = row['origins']
self.origins_tags = row['origins_tags']
self.origins_en = row['origins_en']
self.countries = row['countries']
self.countries_tags = row['countries_tags']
self.countries_en = row['countries_en']
self.image_url = row['image_url']
self.image_ingredients_url = row['image_ingredients_url']
self.image_nutrition_url = row['image_nutrition_url']
self.energy_kcal_100g = row['energy-kcal_100g']
self.fat_100g = row['fat_100g']
self.saturated_fat_100g = row['saturated-fat_100g']
self.unsaturated_fat_100g = row['unsaturated-fat_100g']
self.omega_3_fat_100g = row['omega-3-fat_100g']
self.omega_6_fat_100g = row['omega-6-fat_100g']
self.omega_9_fat_100g = row['omega-9-fat_100g']
self.trans_fat_100g = row['trans-fat_100g']
self.cholesterol_100g = row['cholesterol_100g']
self.carbohydrates_100g = row['carbohydrates_100g']
self.sugars_100g = row['sugars_100g']
self.sucrose_100g = row['sucrose_100g']
self.glucose_100g = row['glucose_100g']
self.fructose_100g = row['fructose_100g']
self.lactose_100g = row['lactose_100g']
self.maltose_100g = row['maltose_100g']
self.fiber_100g = row['fiber_100g']
self.soluble_fiber_100g = row['soluble-fiber_100g']
self.insoluble_fiber_100g = row['insoluble-fiber_100g']
self.proteins_100g = row['proteins_100g']
self.salt_100g = row['salt_100g']
self.added_salt_100g = row['added-salt_100g']
self.sodium_100g = row['sodium_100g']
self.alcohol_100g = row['alcohol_100g']
self.vitamin_a_100g = row['vitamin-a_100g']
self.beta_carotene_100g = row['beta-carotene_100g']
self.vitamin_d_100g = row['vitamin-d_100g']
self.vitamin_e_100g = row['vitamin-e_100g']
self.vitamin_k_100g = row['vitamin-k_100g']
self.vitamin_c_100g = row['vitamin-c_100g']
self.vitamin_b1_100g = row['vitamin-b1_100g']
self.vitamin_b2_100g = row['vitamin-b2_100g']
self.vitamin_pp_100g = row['vitamin-pp_100g']
self.vitamin_b6_100g = row['vitamin-b6_100g']
self.vitamin_b9_100g = row['vitamin-b1_100g']
self.vitamin_b12_100g = row['vitamin-b12_100g']
self.bicarbonate_100g = row['bicarbonate_100g']
self.potassium_100g = row['potassium_100g']
self.chloride_100g = row['chloride_100g']
self.calcium_100g = row['calcium_100g']
self.phosphorus_100g = row['phosphorus_100g']
self.iron_100g = row['iron_100g']
self.magnesium_100g = row['magnesium_100g']
self.zinc_100g = row['zinc_100g']
self.copper_100g = row['copper_100g']
self.manganese_100g = row['manganese_100g']
self.fluoride_100g = row['fluoride_100g']
self.selenium_100g = row['selenium_100g']
self.chromium_100g = row['chromium_100g']
self.molybdenum_100g = row['molybdenum_100g']
self.iodine_100g = row['iodine_100g']
self.caffeine_100g = row['caffeine_100g']
self.carbon_footprint_100g = row['carbon-footprint_100g']
self.carbon_footprint_from_meat_or_fish_100g = row['carbon-footprint-from-meat-or-fish_100g']
self.cocoa_100g = row['cocoa_100g']
def is_vegan(self):
if "meat" not in self.categories_en.lower() and "dairy" not in self.categories_en.lower():
return True
else:
return False
def nutrient_score_intl(self):
nutrient_factors = {'fat': 9, 'saturated_fat': 10, 'trans_fat': 10, 'cholesterol': 5,
'sodium': 6, 'carbohydrates': 7, 'sugars': 6, 'fiber': 5,
'proteins': 5, 'vitamin_a': 15, 'vitamin_c': 15, 'calcium': 10,
'iron': 10}
nutrient_scores = {}
for nutrient, factor in nutrient_factors.items():
value = getattr(self, nutrient+'_100g')
if value is not None:
nutrient_scores[nutrient] = min(100, max(0, factor * (value / self._get_daily_requirement(nutrient))))
# sum the nutrient scores to arrive at the total nutrient score
total_score = sum(nutrient_scores.values())
return total_score
def _get_daily_requirement(self, nutrient):
daily_requirement = {'fat': 70, 'saturated_fat': 20, 'trans_fat': 2, 'cholesterol': 300,
'sodium': 2000, 'carbohydrates': 260, 'sugars': 90, 'fiber': 38,
'proteins': 50, 'vitamin_a': 900, 'vitamin_c': 90, 'calcium': 1000,
'iron': 18}
# for nutrients without a daily requirement, return None
return daily_requirement.get(nutrient, None)
@classmethod
def load_from_dataframe(cls, df):
products = []
for i, row in df.iterrows():
product = cls(row)
products.append(product)
return products
def __str__(self) -> str:
return self.product_name

View File

@ -1,24 +0,0 @@
import sqlite3
import pandas as pd
import re
thai_df = pd.read_csv('thai_data.csv')
us_df = pd.read_csv('us_data.csv')
japan_df = pd.read_csv('japan_data.csv')
conn = sqlite3.connect('food_data.db')
thai_df = thai_df[~thai_df.product_name.str.contains('to be deleted', na=False, flags=re.IGNORECASE)]
japan_df = japan_df[~japan_df.product_name.str.contains('to be deleted', na=False, flags=re.IGNORECASE)]
us_df = us_df[~us_df.product_name.str.contains('to be deleted', na=False, flags=re.IGNORECASE)]
thai_df = thai_df.dropna(subset=['product_name'])
japan_df = japan_df.dropna(subset=['product_name'])
us_df = us_df.dropna(subset=['product_name'])
thai_df.to_sql('thai_food', conn, if_exists='replace', index=False)
us_df.to_sql('us_food', conn, if_exists='replace', index=False)
japan_df.to_sql('japan_food', conn, if_exists='replace', index=False)
conn.commit()
conn.close()