This commit is contained in:
Askill 2020-04-11 00:42:37 +02:00
parent 962e6b3166
commit 5289681b09
1 changed files with 13 additions and 9 deletions

18
test.py
View File

@ -2,7 +2,7 @@
from application.db import Session, Recipe, Ingredient, Link from application.db import Session, Recipe, Ingredient, Link
dbSession = Session() dbSession = Session()
inputArr = ["wasser", "MEHL", "zucker", "zitrone", "stift"] inputArr = ["kartoffeln", "zwiebel", "steak", "würfel"]
def slow(): def slow():
recipes = dbSession.query(Recipe).all() recipes = dbSession.query(Recipe).all()
@ -12,6 +12,8 @@ def slow():
for recipe in recipes: for recipe in recipes:
rec = recipe rec = recipe
recipe = recipe.ingredients() recipe = recipe.ingredients()
if len(recipe) > len(inputArr) + 2:
continue
counter = 0 counter = 0
for i in inputArr: for i in inputArr:
for x in recipe: for x in recipe:
@ -27,21 +29,22 @@ def slow():
#print(rec.name) #print(rec.name)
print(arr['5']) print(arr)
def faster(): def faster():
indx = {} indx = {}
for inpu in inputArr: for inpu in inputArr:
ids = [] ids = []
for x in dbSession.query(Ingredient).filter(Ingredient.name.contains(inpu)).all(): for x in dbSession.query(Ingredient).filter(Ingredient.name.contains(inpu)).all():
for y in x.recipe: for y in x.recipe:
ids.append(y.recipe_id)
for i in ids: if dbSession.query(Link).filter(Link.recipe_id==y.recipe_id).count() > len(inputArr) + 5:
if str(i) not in indx: continue
indx[str(i)] = 0 if str(y.recipe_id) not in indx:
indx[str(y.recipe_id)] = 0
indx[str(i)] += 1 indx[str(y.recipe_id)] += 1
for key, value in indx.items(): for key, value in indx.items():
@ -51,3 +54,4 @@ def faster():
print(dbSession.query(Recipe).filter(Recipe.recipe_id==key).first().ingredients()) print(dbSession.query(Recipe).filter(Recipe.recipe_id==key).first().ingredients())
#print(key) #print(key)
faster() faster()
slow()