-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmodel_helpers.py
59 lines (52 loc) · 1.6 KB
/
model_helpers.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import json
from KB import *
from app.models.knowledgebases import KnowledgeBaseModel
from app.db import db
def create_KB(user_id):
"""
Create the KB for each user & Update the KB
"""
knowledgebase = db.session.query(KnowledgeBaseModel).filter_by(user_id=user_id).first()
knowledgebase.update_kb()
db.session.commit()
return knowledgebase.kb
def get_questions_dict(user_id):
"""
Generate questions dictionary to use in creating KB
"""
knowledgebase = db.session.query(KnowledgeBaseModel).filter_by(user_id=user_id).first()
return knowledgebase.get_questions_dict()
def create_ask_question(A, V, question):
"""
Create question to ask users includes
- questions for askables
- options with numbered list
- error for previous input
"""
if str(A) == 'ingredient':
askable_question = 'Do you want ' + str(V) +' ?'
else:
askable_question = str(question[str(A)])
return json.dumps({
"message": askable_question,
"options": ["yes", "no"]
})
def create_numberask_question(A, question):
"""
Create questions to ask for number
"""
askable_question = question[str(A)]+'\n'+'Your answer is: ' if str(A) in question else str(A)
return json.dumps({
"message": askable_question,
"options": []
})
def create_menuask_question(A, menu, question):
"""
Create questions to have menuasks
"""
menuask_question = question[str(A)]
menu_list = [str(i) for i in menu]
return json.dumps({
"message": menuask_question,
"options": menu_list
})