-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
268 lines (212 loc) · 7.95 KB
/
app.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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
from flask import Flask, request, render_template
#Create an app object using the Flask class.
app = Flask(__name__)
@app.route('/')
def home():
return render_template('index.html')
@app.route('/i_questions')
def i_questions():
return render_template('i_questions.html')
@app.route('/d_questions')
def d_questions():
return render_template('d_questions.html')
@app.route('/i_pell', methods=['POST','GET'])
def i_pell():
lookup_table = {"48DC":
{2: 18310,
3: 23030,
4: 27750,
5: 32470,
6: 37190,
7: 41910,
8: 46630,
9: 4720 },
"AK":
{2: 22890,
3: 28790,
4: 34690,
5: 40590,
6: 46490,
7: 52390,
8: 58290,
9: 5900,
},
"HI":
{2: 21060,
3: 26490,
4: 31920,
5: 37350,
6: 42780,
7: 48210,
8: 53640,
9: 5430},
"1_48DC":
{1: 13590,
2: 18310,
3: 23030,
4: 27750,
5: 32470,
6: 37190,
7: 41910,
8: 46630,
9: 4720},
"1_AK":
{1: 16990,
2: 22890,
3: 28790,
4: 34690,
5: 40590,
6: 46490,
7: 52390,
8: 58290,
9: 5900,
},
"1_HI":
{1: 15630,
2: 21060,
3: 26490,
4: 31920,
5: 37350,
6: 42780,
7: 48210,
8: 53640,
9: 5430 },
1: {"max": 1.75,"min": 2.25}, #not parent
2: {"max": 2.25,"min": 4.0}, #single
3: {"max": 1.75,"min": 3.5}, #couple
}
result = ""
parents = children = live = -1
if 'parents' in request.form:
try:
parents = int(request.form['parents'])
except:
pass
if 'children' in request.form:
try:
children = int(request.form['children'])
except:
pass
if 'live' in request.form:
try:
live = request.form['live']
except:
pass
missing = []
if parents == -1:
missing.append("parents.")
if children == -1:
missing.append("children.")
if live == -1:
missing.append("location.")
if missing:
return render_template('i_questions.html', result=["Please complete the form. You are missing:"] + missing)
if live == "NOTUS":
result = [f"Sorry, you have to be a US resident to be eligible for a Pell Grant."]
return render_template('results.html', result=result)
if parents == 1 and children > 0:
return render_template('i_questions.html', result=["Try again, you can't be not a parent and have more than 0 children!"])
if parents == 1:
deps = lookup_table[f"1_{live}"]
else:
deps = lookup_table[live]
family_size = parents -1 + children + 1 #the student
if family_size > 8:
pov_level = deps[8] + (family_size - 8) * deps[9]
else:
pov_level = deps[family_size]
max_pell = pov_level * lookup_table[parents]["max"]
min_pell = pov_level * lookup_table[parents]["min"]
parental_status = {1: "not-a-parent", 2: "single-parent", 3: "couple"}[parents]
result = [f"You are an independent student, {parental_status}, with {children} children, in {live}:",
f"If your family's Annual Gross Income (AGI) is less than ${max_pell:2.2f}, then you are entitled to the maximun Pell Grant ($5000 pa).",
f"If your family's AGI is greater than ${min_pell:2.2f}, then unfortunately you are not eligble for any Pell Grant." ,
f"If your family's AGI is between these two amounts, you are entitled to a proportion of the Pell Grant."]
return render_template('results.html', result=result)
@app.route('/d_pell',methods=['POST','GET'])
def d_pell():
lookup_table = {"48DC":
{2: 18310,
3: 23030,
4: 27750,
5: 32470,
6: 37190,
7: 41910,
8: 46630,
9: 4720 },
"AK":
{2: 22890,
3: 28790,
4: 34690,
5: 40590,
6: 46490,
7: 52390,
8: 58290,
9: 5900,
},
"HI":
{2: 21060,
3: 26490,
4: 31920,
5: 37350,
6: 42780,
7: 48210,
8: 53640,
9: 5430},
1: {"max": 2.25,"min": 3.25},
2: {"max": 1.75,"min": 2.75},
}
result = ""
age = parents = siblings = live = -1
if 'age' in request.form:
try:
age = int(request.form['age'])
except:
pass
if 'parents' in request.form:
try:
parents = int(request.form['parents'])
except:
pass
if 'siblings' in request.form:
try:
siblings = int(request.form['siblings'])
except:
pass
if 'live' in request.form:
try:
live = request.form['live']
except:
pass
missing = []
if age == -1:
missing.append("age.")
if age > 24:
result = [f"You are over 24 years of age. Please fill out the indendepent version!"]
return render_template('i_questions.html', result=result)
if parents == -1:
missing.append("parents.")
if siblings == -1:
missing.append("siblings.")
if live == -1:
missing.append("location.")
if missing:
return render_template('d_questions.html', result=["Please complete the form. You are missing:"] + missing)
if live == "NOTUS":
result = [f"Sorry, you have to be a US resident to be eligible for a Pell Grant."]
return render_template('results.html', result=result)
deps = lookup_table[live]
family_size = parents + siblings + 1 #the student
if family_size > 8:
pov_level = deps[8] + (family_size - 8) * deps[9]
else:
pov_level = deps[family_size]
max_pell = pov_level * lookup_table[parents]["max"]
min_pell = pov_level * lookup_table[parents]["min"]
result = [f"You live with {parents} parent(s), with {siblings} sibling(s), in {live}:",
f"If your family's Annual Gross Income (AGI) is less than ${max_pell:2.2f}, then you are entitled to the maximun Pell Grant ($5000 pa).",
f"If your family's AGI is greater than ${min_pell:2.2f}, then unfortunately you are not eligble for any Pell Grant." ,
f"If your family's AGI is between these two amounts, you are entitled to a proportion of the Pell Grant."]
return render_template('results.html', result=result)
if __name__ == "__main__":
app.run(debug=True)