did stuff

This commit is contained in:
Askill 2020-04-10 23:34:58 +02:00
commit 962e6b3166
4 changed files with 33447 additions and 3 deletions

View File

@ -61,8 +61,7 @@ class Recipe(Base):
"instructions":self.instructions,
"url": self.url,
"img": img,
"ingredients": self.ingredient.ingredient
"ingredients": self.ingredients()
}
return data

File diff suppressed because one or more lines are too long

53
test.py Normal file
View File

@ -0,0 +1,53 @@
from application.db import Session, Recipe, Ingredient, Link
dbSession = Session()
inputArr = ["wasser", "MEHL", "zucker", "zitrone", "stift"]
def slow():
recipes = dbSession.query(Recipe).all()
arr = {}
for recipe in recipes:
rec = recipe
recipe = recipe.ingredients()
counter = 0
for i in inputArr:
for x in recipe:
if i in x:
counter += 1
continue
counter = str(counter)
if counter not in arr:
arr[counter] = []
arr[counter].append(rec.ingredients())
#print(rec.name)
print(arr['5'])
def faster():
indx = {}
for inpu in inputArr:
ids = []
for x in dbSession.query(Ingredient).filter(Ingredient.name.contains(inpu)).all():
for y in x.recipe:
ids.append(y.recipe_id)
for i in ids:
if str(i) not in indx:
indx[str(i)] = 0
indx[str(i)] += 1
for key, value in indx.items():
if value >= len(inputArr):
print(dbSession.query(Recipe).filter(Recipe.recipe_id==key).first().ingredients())
#print(key)
faster()