-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfunction.py
78 lines (62 loc) · 1.59 KB
/
function.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import pandas as pd
import random
import json
import sys
def jsontolist(a):
f = open(str(a))
l = json.load(f)
al = list(l.values())
al
for i in range(len(al)):
al[i] = int(al[i])
return al
df = pd.read_csv("/var/www/html/FoodFighters/api/foodfighters/Dataset/dummydataset.csv")
f = open('data.json')
l = json.load(f)
def mainfun(filename):
al = jsontolist(filename)
valid = (1,2,3,4,5,6)
ingiq = al[0]
dis = al[1]
if ingiq == 1:
ingiq = ingiq+1
if dis not in valid:
print("ERROR: invalid response")
if ingiq not in valid:
print("ERROR: invalid response")
# checking for diseases
#conditions
if dis == 1:
discon = "Fat < 50 and Carbs < 57"
elif dis == 2:
discon = "Fat < 50 and Carbs < 57"
elif dis == 3:
discon = "Fat < 50"
elif dis == 4:
discon = "Protein > 50"
elif dis == 5:
discon = "Carbs < 57 and Protein > 50"
elif dis == 6:
discon = "Protein > 50"
#checking for ingredients in question
#conditions
if ingiq == 2:
ingcon = "Carbs < 59"
if ingiq == 3:
ingcon = "Fat > 54"
if ingiq == 4:
ingcon = "Carbs > 59"
if ingiq == 5:
ingcon = "Carbs > 59"
if ingiq == 6:
ingcon = "Protein > 54"
condition = str(ingcon + " and " + discon)
set = df.query(condition)
l = list(set["Recipe_name"])
if len(l) == 0:
return 'no'
else:
ans = l[random.randint(0, len(l))]
return ans
print(mainfun('data.json'))
sys.modules[__name__] = mainfun