added 2nd db model
This commit is contained in:
parent
cb9b8183e6
commit
b70dc0bb54
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
|
@ -0,0 +1,69 @@
|
|||
import sqlalchemy as db
|
||||
from sqlalchemy import Column, String, Integer, Numeric, Table, DateTime, ARRAY, ForeignKey, create_engine, LargeBinary, Enum, Text
|
||||
from sqlalchemy.orm import sessionmaker, relationship, column_property
|
||||
from datetime import datetime
|
||||
from sqlalchemy.ext.declarative import declarative_base
|
||||
import enum
|
||||
from flask import Flask
|
||||
import time
|
||||
|
||||
engine = db.create_engine('mysql+mysqldb://root@server/fs2?charset=utf8mb4', echo=False, encoding="utf8", pool_size=1000, max_overflow=0)
|
||||
|
||||
Base = declarative_base()
|
||||
Session = sessionmaker(bind=engine)
|
||||
|
||||
# https://docs.sqlalchemy.org/en/13/orm/basic_relationships.html#association-object
|
||||
|
||||
class Recipe(Base):
|
||||
__tablename__ = "recipe"
|
||||
recipe_id = Column('recipe_id', Integer, primary_key=True, autoincrement=True)
|
||||
name = Column('name', Text)
|
||||
instructions = Column('instructions', Text)
|
||||
url = Column('url', Text)
|
||||
img = Column('img', LargeBinary)
|
||||
imgURL = Column('imgURL', Text)
|
||||
ingredient = relationship("RecIngred", back_populates="recipe")
|
||||
|
||||
class RecIngred(Base):
|
||||
|
||||
__tablename__ = 'recingred'
|
||||
ingredient_amount = Column('ingredient_amount', Text)
|
||||
ingredient_amount_mu = Column('ingredient_amount_mu', Text) # measurement unit
|
||||
|
||||
recipe_id = Column(Integer, ForeignKey('recipe.recipe_id'), primary_key=True)
|
||||
ingredient_name = Column(String(50), ForeignKey('ingredient.name'), primary_key=True)
|
||||
|
||||
recipe = relationship("Recipe", back_populates="ingredient")
|
||||
ingredient = relationship("Ingredient", back_populates="recipe")
|
||||
|
||||
class Ingredient(Base):
|
||||
__tablename__ = "ingredient"
|
||||
name = Column('name', String(50), primary_key=True)
|
||||
recipe = relationship("RecIngred", back_populates="ingredient")
|
||||
trunks = relationship("IngredTrunk", back_populates="ingredient")
|
||||
|
||||
class IngredTrunk(Base):
|
||||
__tablename__ = 'ingredtrunk'
|
||||
ingredient_name = Column(String(50), ForeignKey('ingredient.name'), primary_key=True)
|
||||
trunk_name = Column(String(50), ForeignKey('ingredient.name'), primary_key=True)
|
||||
|
||||
ingredient = relationship("Ingredient", back_populates="trunk")
|
||||
trunk = relationship("Trunk", back_populates="ingredient")
|
||||
|
||||
class Trunk(Base):
|
||||
__tablename__ = "trunk"
|
||||
name = Column('name', String(50), primary_key=True)
|
||||
ingredients = relationship("IngredTrunk", back_populates="trunk")
|
||||
|
||||
|
||||
def initDB(counter=0):
|
||||
try:
|
||||
Base.metadata.create_all(engine)
|
||||
except Exception as e:
|
||||
print(e)
|
||||
counter += 1
|
||||
if counter < 13:
|
||||
time.sleep(5)
|
||||
initDB(counter)
|
||||
|
||||
initDB()
|
||||
|
|
@ -14,7 +14,7 @@ class RecipeList(Resource):
|
|||
def get(self):
|
||||
""" """
|
||||
g.session = Session()
|
||||
|
||||
g.session = Session()
|
||||
parser = reqparse.RequestParser()
|
||||
parser.add_argument('ingred', type=str, action='append')
|
||||
args = parser.parse_args()
|
||||
|
|
|
|||
4
run.py
4
run.py
|
|
@ -1,9 +1,11 @@
|
|||
from application import app
|
||||
import nltk
|
||||
from search import defaultArr, stem
|
||||
|
||||
|
||||
nltk.download('stopwords')
|
||||
nltk.download('punkt')
|
||||
|
||||
delattr = stem(defaultArr)
|
||||
app.run(host="0.0.0.0", port='5001', debug=True, threaded=True)
|
||||
|
||||
|
||||
|
|
|
|||
11
search.py
11
search.py
|
|
@ -38,11 +38,11 @@ def getRecDict(indx, inputArr):
|
|||
|
||||
outDict = {}
|
||||
k = Counter(indx)
|
||||
# Finding 1000 highest values
|
||||
# Finding 1000 highest values TODO: this is not correct
|
||||
indx = k.most_common(1000)
|
||||
indx = dict(indx)
|
||||
for key, value in indx.items():
|
||||
ingred = dbSession.query(Trunk.name).filter(Trunk.recipe_id==int(key)).all()
|
||||
ingred = [x[0] for x in dbSession.query(Trunk.name).filter(Trunk.recipe_id==int(key)).all()]
|
||||
outDict[calcOverlay(inputArr, ingred)] = int(key)
|
||||
|
||||
outDict2 = {}
|
||||
|
|
@ -72,10 +72,9 @@ def stem(l1):
|
|||
|
||||
def calcOverlay(l1, l2):
|
||||
counter = 0
|
||||
|
||||
for x in l2:
|
||||
for l in l1:
|
||||
if l not in defaultArr and l == x[0]:
|
||||
for l in l1:
|
||||
if l not in defaultArr:
|
||||
if l in l2:
|
||||
#print(l)
|
||||
counter +=1
|
||||
counter = counter / len(l2)
|
||||
|
|
|
|||
Loading…
Reference in New Issue