From 5c566e29be11ac7cbb6948a8de14d97bf5cca2c6 Mon Sep 17 00:00:00 2001 From: sosokker Date: Tue, 2 May 2023 15:23:55 +0700 Subject: [PATCH] Delete Essential directory --- Essential/FoodSearch.py | 13 -- .../__pycache__/FoodSearch.cpython-311.pyc | Bin 1355 -> 0 bytes .../__pycache__/foodItem.cpython-311.pyc | Bin 7358 -> 0 bytes Essential/foodDatabase.py | 83 ------------- Essential/foodItem.py | 115 ------------------ Essential/prepare_db.py | 24 ---- 6 files changed, 235 deletions(-) delete mode 100644 Essential/FoodSearch.py delete mode 100644 Essential/__pycache__/FoodSearch.cpython-311.pyc delete mode 100644 Essential/__pycache__/foodItem.cpython-311.pyc delete mode 100644 Essential/foodDatabase.py delete mode 100644 Essential/foodItem.py delete mode 100644 Essential/prepare_db.py diff --git a/Essential/FoodSearch.py b/Essential/FoodSearch.py deleted file mode 100644 index 25ad312..0000000 --- a/Essential/FoodSearch.py +++ /dev/null @@ -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 \ No newline at end of file diff --git a/Essential/__pycache__/FoodSearch.cpython-311.pyc b/Essential/__pycache__/FoodSearch.cpython-311.pyc deleted file mode 100644 index 6134ad6a885c8ff22f3c1fec8634c526517429a4..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1355 zcmZ`&-D?v;5TE->E@=}rmiQ5nqtKdY@j>52M9}zwTEz%LC>-&2V^gn5x_bv2qMXo& zJoqGq7DVV%Mfy+pCzujwSP%rCe2df%B>`pY)m`#k z0r)ImMxy^R_MW4$4g`qeLK#%J21H#2qHU=F+qj2PR#c!0(YFw18}~1-O4Utm^fvw^ z#vhS7<{R{nd7jeGg);xMn#GOXHP90C^(hxDnXS~4*s?a%gt0GPw+Rci$$mN}u^<$2lUvL`B zP1bm1bGm%iu40=DMb2s6t5w{E-(8<+J{6{I*XlLTwp)kC4n|J-$@v_r06tFT*6wUx z>rTz}rsg{O%S1nWe66;do!!aKcC-0jHjmDU4z4}fm54Fw`Kw~iB-27+lQJ^K!^vwM8l!#aGVz#SLKQ&&VCjAN z!@<(<*D?C$rHi}(yx@S&*FsJ*O?Aqzw%+%EL*W{k+kh)?9G+-q;0SG6?b^TQWz_Ax5hn|Me`km*?Idy=*Sm?CUScMQ^}z^?p!y=UnhL@d7V{I_bt`rN diff --git a/Essential/__pycache__/foodItem.cpython-311.pyc b/Essential/__pycache__/foodItem.cpython-311.pyc deleted file mode 100644 index 93fbb59638c8f1398468d83bed02c6f08854ec71..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 7358 zcmbW6OKcm*8ON7zN+d;Dl5IUL>Mh1rte53yoH((iByE+Tc7RlNuvl?d(#9lLnO)ko zN(U}rplT2xPGG<)kb_Qc3}137pks~(dMIfSFfl-Y0KHT<25x~ir+(iqcR8PA18qju zXy*IP&imW_&-l-YM6(3pKX=|&|9Vi8{*Dvlzog( z+hHlHhP9>@zZ$t4TxwRM&_)xFt{8^;j-}-?ZVOlz(*gK>J{ZB)iayoXg?2j>CD~0P z@e|^65s&~OUj0CVgkVc{01_g^oiS`DOh`z0CPGM9AW=eKEKY#hnh1#sq?wQ=fy4;0 z*BL3)7AGVoJd+?KE|3;N5&}sQ(jt&nLXrYGKuD`V+6Xxykaj}a1kyoByFd;S(jkyT zguvc+0?f`~LJkR}laRv#=^~_4Al-y`8EB`+%Sf7(e zB9Igz{Q?;vBqfkRLIwmfM982(h6x!G$Os|B0vRP_L?B~?j0$9&kTHRz2^km2D}HLLhU5%n9TqAtwcLijY$RIZeoEft(@aj6lv3a#kSc2stN^*9dt{Am<4=FOb&> zd0ilH5b}mVE)a4-Aa4@#ra;~zi z%#^%p@|g2iwv<(qH)j+}TQ!)jnLOD@J1`*_v^$yDu@N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@(qx!dEu?(n%>2-cw~ULQtZH1N2TlNv#zP9 zT~p<*nM&78DK=A+0!>{zk?*X^!f&1}$WIsK@`6%XP)es18&%s6-<$oRz4P7)_8!zj z<_kaQIA_n#Lw9h#R6qO#)SwDCd+;})hT#Wok*^cCeY$kpU-WIm1N*~6Fg^Cn7p0G` zT!T02?ZEAzg)P)WQ7Q)1=mzBIE#&P`G4%U07OIhYP@63822GOG=3=lIDoWcymy3Uk zfrrrl$KLvGfNt4zzM*6bnwgH+yP3DzhdH1y5IEd0IC6RxGh;9~gGOBg z4?AUe$gYFOEYRv%*(rw8m2!gP9PRF7P67CSTiK0X@9X^n`aV=){tY51 z>b2_V*v`OrpOh|Nsg9?2{7>3SA1+mgM{AKl?>M+g?|3QNS!&spUYh02LS`Phxhu^ac2+tG4s`rrQw zOCS}FKkJ@++C5qBp00FHmk-TU4$W-Fen@tgqTP=BqD*mv=e~M%5;@ z8UDu9xS9a>^~2_NpCo_bGINisz;j75WUT(%9v(fJ@?~Avf0)@=C zA%Ybi9^GksGEllESI3U-WS;!Gv~;bSKDsmX6-!xRaDgQF(+enmLCtp{x+DG2esD8dJ=FQ&`d8P#%-zq` zB!AP09sO~B^TMVHTKQgPYv{|h`)ivE)p*Aj?|t^()KHrxm_6IPgea@Nn3Z%u4XhfDxi-EFlZEPOLf?LYOcRcKt zWP2ruCT0 diff --git a/Essential/foodDatabase.py b/Essential/foodDatabase.py deleted file mode 100644 index a02a969..0000000 --- a/Essential/foodDatabase.py +++ /dev/null @@ -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() - diff --git a/Essential/foodItem.py b/Essential/foodItem.py deleted file mode 100644 index 3365bfc..0000000 --- a/Essential/foodItem.py +++ /dev/null @@ -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 \ No newline at end of file diff --git a/Essential/prepare_db.py b/Essential/prepare_db.py deleted file mode 100644 index a92987c..0000000 --- a/Essential/prepare_db.py +++ /dev/null @@ -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() \ No newline at end of file