-
Notifications
You must be signed in to change notification settings - Fork 0
/
constants.py
161 lines (154 loc) · 6.9 KB
/
constants.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
# CP-SAT only does integers, and no nutrient or requirement is less than .001, so scale to make .001 * NUMBER_SCALE = 1.
# This value affects both the number of decimal places to which the source data is rounded
# and the scale of the integer variables in the CP-SAT model.
NUMBER_SCALE = 1_000
FOOD_OFFSET = 2 # The first few columns of the food data are labels.
DB_URL = "postgresql://postgres:pg_password@localhost:5432/food"
USDA_NUTRIENT_NAMES = [
"Calcium, Ca",
"Carbohydrate, by difference",
"Choline, total",
"Copper, Cu",
"Energy",
"Total lipid (fat)",
"Fiber, total dietary",
"Fluoride, F",
"Folate, total",
"Iron, Fe",
"Magnesium, Mg",
"Manganese, Mn",
"Niacin",
"Phosphorus, P",
"Potassium, K",
"Protein",
"Riboflavin",
"Selenium, Se",
"Sodium, Na",
"Thiamin",
"Vitamin A, RAE",
"Vitamin B-6",
"Vitamin B-12",
"Vitamin C, total ascorbic acid",
"Vitamin D (D2 + D3)",
"Vitamin E (alpha-tocopherol)",
"Vitamin K (phylloquinone)",
"Water",
"Zinc, Zn",
]
NUTRIENT_UNITS = [
"mg",
"g",
"mg",
"mg",
"kcal",
"g",
"g",
"µg",
"µg",
"mg",
"mg",
"µg",
"mg",
"mg",
"mg",
"g",
"mg",
"µg",
"mg",
"mg",
"µg",
"mg",
"µg",
"mg",
"µg",
"mg",
"µg",
"g",
"mg",
]
NUTRIENT_NAMES = [ # Columns of the CSV that are in SQL.
"calcium",
"carbohydrate",
"choline",
"copper",
"energy",
"fat",
"total_fiber",
"fluoride",
"folate",
"iron",
"magnesium",
"manganese",
"niacin",
"phosphorus",
"potassium",
"protein",
"riboflavin",
"selenium",
"sodium",
"thiamin",
"vitamin_a",
"vitamin_b6",
"vitamin_b12",
"vitamin_c",
"vitamin_d",
"vitamin_e",
"vitamin_k",
"water",
"zinc",
]
# fmt: off
KNOWN_SOLUTIONS = {
7: [
[(2009, 58), (4531, 138), (9520, 1110), (11998, 300), (14412, 23564), (20129, 568), (31020, 330)],
[(4047, 117), (9436, 2328), (9520, 784), (11998, 349), (14412, 11628), (16112, 643), (31020, 208)],
[(4510, 116), (9436, 2363), (9520, 784), (11998, 349), (14412, 11628), (16112, 643), (31020, 208)],
[(4516, 116), (9436, 2363), (9520, 784), (11998, 349), (14412, 11628), (16112, 643), (31020, 208)],
[(4517, 116), (9436, 2363), (9520, 784), (11998, 349), (14412, 11628), (16112, 643), (31020, 208)],
[(4518, 116), (9436, 2337), (9520, 780), (11998, 349), (14412, 11628), (16112, 641), (31020, 210)],
[(4531, 144), (9520, 1043), (11271, 423), (11936, 283), (14412, 11891), (20129, 580), (31020, 358)],
[(4531, 146), (9520, 995), (11576, 328), (11936, 259), (14412, 16118), (20129, 595), (31020, 382)],
[(4531, 142), (9520, 1060), (11577, 421), (11936, 308), (14412, 12831), (20522, 557), (31020, 344)],
[(4581, 116), (9436, 2364), (9520, 784), (11998, 349), (14412, 11628), (16112, 643), (31020, 208)],
[(4588, 116), (9436, 2363), (9520, 784), (11998, 349), (14412, 11628), (16112, 643), (31020, 208)],
[(4037, 116), (9436, 2352), (9520, 788), (11998, 349), (14412, 11628), (16112, 645), (31020, 206)],
[(4044, 116), (9436, 2352), (9520, 788), (11998, 349), (14412, 11628), (16112, 645), (31020, 206)],
[(4060, 116), (9436, 2363), (9520, 784), (11998, 349), (14412, 11628), (16112, 643), (31020, 208)],
[(4506, 116), (9436, 2364), (9520, 784), (11998, 349), (14412, 11628), (16112, 643), (31020, 208)],
[(4511, 116), (9436, 2363), (9520, 784), (11998, 349), (14412, 11628), (16112, 643), (31020, 208)],
[(4513, 116), (9436, 2395), (9520, 790), (11998, 349), (14412, 11628), (16112, 646), (31020, 205)],
[(4514, 116), (9436, 2363), (9520, 784), (11998, 349), (14412, 11628), (16112, 643), (31020, 208)],
[(4515, 116), (9436, 2363), (9520, 784), (11998, 349), (14412, 11628), (16112, 643), (31020, 208)],
[(4530, 116), (9436, 2363), (9520, 784), (11998, 349), (14412, 11628), (16112, 643), (31020, 208)],
[(4531, 115), (9436, 2565), (9520, 816), (11998, 349), (14412, 11628), (16112, 659), (31020, 192)],
[(4531, 121), (9520, 992), (11271, 277), (11936, 308), (14412, 16776), (20129, 642), (31019, 50)],
[(4531, 128), (9520, 1058), (11422, 610), (11998, 320), (14412, 25099), (20129, 593), (31019, 47)],
[(4531, 134), (9520, 1106), (11517, 68), (11936, 308), (14412, 26945), (20129, 599), (31019, 45)],
[(4531, 142), (9520, 1060), (11577, 421), (11936, 308), (14412, 12831), (20422, 557), (31020, 344)],
[(4531, 144), (9520, 1063), (11208, 364), (11936, 233), (14412, 11629), (20129, 576), (31020, 368)],
[(4531, 145), (9520, 1051), (11207, 271), (11936, 308), (14412, 11628), (20129, 573), (31020, 347)],
[(4531, 145), (9520, 1076), (11208, 295), (11936, 290), (14412, 14180), (20129, 573), (31019, 47)],
[(4531, 146), (9520, 987), (11504, 399), (11936, 246), (14412, 21445), (20129, 594), (31020, 389)],
[(4531, 146), (9520, 1019), (11257, 361), (11936, 250), (14412, 24574), (20129, 598), (31020, 377)],
[(4531, 146), (9520, 1064), (11086, 245), (11936, 304), (14412, 18857), (20129, 588), (31020, 344)],
[(4531, 146), (9520, 1078), (11504, 312), (11936, 267), (14412, 22323), (20129, 580), (31019, 48)],
[(4531, 146), (9520, 1086), (11257, 297), (11936, 259), (14412, 24645), (20129, 586), (31019, 48)],
[(4531, 147), (9520, 1043), (11487, 616), (11936, 280), (14412, 22941), (20129, 508), (31020, 359)],
[(4531, 147), (9520, 1090), (11487, 512), (11936, 298), (14412, 23270), (20129, 513), (31019, 46)],
[(4532, 116), (9436, 2363), (9520, 784), (11998, 349), (14412, 11628), (16112, 643), (31020, 208)],
[(4534, 116), (9436, 2363), (9520, 784), (11998, 349), (14412, 11628), (16112, 643), (31020, 208)],
[(4536, 116), (9436, 2363), (9520, 784), (11998, 349), (14412, 11628), (16112, 643), (31020, 208)],
[(4541, 116), (9436, 2363), (9520, 784), (11998, 349), (14412, 11628), (16112, 643), (31020, 208)],
[(4572, 116), (9436, 2363), (9520, 784), (11998, 349), (14412, 11628), (16112, 643), (31020, 208)],
[(4573, 116), (9436, 2363), (9520, 784), (11998, 349), (14412, 11628), (16112, 643), (31020, 208)],
[(4669, 116), (9436, 2364), (9520, 784), (11998, 349), (14412, 11628), (16112, 643), (31020, 208)],
[(4707, 117), (9436, 2331), (9520, 794), (11998, 349), (14412, 11628), (16112, 648), (31020, 203)],
[(9192, 3019), (9520, 999), (11936, 285), (14412, 11628), (16112, 840), (31019, 15), (42231, 101)],
[(9436, 2224), (9520, 848), (11998, 349), (14412, 11628), (16112, 675), (31020, 176), (35092, 170)],
],
}
# fmt: on
if __name__ == "__main__":
for number_of_foods in KNOWN_SOLUTIONS:
for known_solution in KNOWN_SOLUTIONS[number_of_foods]:
assert known_solution == sorted(known_solution, key=lambda x: x[0])