-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
371 lines (323 loc) · 10.4 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
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
#!/usr/bin/python
# -*- coding: utf-8 -*-
from flask import Flask, render_template, request, send_file
import csv
import pandas as pd
import rank_algo
fields = [
'Project Name',
'Creativity',
'Appearance',
'Complexity',
'Efficiency',
'Execution',
'Composite Score',
]
rank1 = ''
total = ''
data = []
cat1 = 'Creativity'
cat2 = ''
cat3 = ''
cat4 = ''
cat5 = ''
cat1_cus = ''
cat2_cus = ''
cat3_cus = ''
cat4_cus = ''
cat5_cus = ''
creativity_list = {}
appearance_list = {}
complexity_list = {}
efficiency_list = {}
execution_list = {}
name1_global = 'Creativity'
name2_global = 'Appearance'
name3_global = 'Complexity'
name4_global = 'Efficiency'
name5_global = 'Execution'
name1 = ''
name2 = ''
name3 = ''
name4 = ''
name5 = ''
alt = ''
change = ''
creativity_weight = 0.05
complexity_weight = 0.3
efficiency_weight = 0.3
execution_weight = 0.3
appearance_weight = 0.3
# Declare App
app = Flask(__name__)
@app.route('/')
def main(
cat1=cat1,
cat2=cat2,
cat3=cat3,
cat4=cat4,
cat5=cat5,
):
with open('database.csv', mode='w', newline='') as csv_file:
csv_writer = csv.writer(csv_file, delimiter=',', quotechar='"',
quoting=csv.QUOTE_MINIMAL)
csv_writer.writerow(fields)
print (name1_global)
cat1 = name1_global
cat2 = name2_global
cat3 = name3_global
cat4 = name4_global
cat5 = name5_global
return render_template(
'app.html',
cat1=cat1,
cat2=cat2,
cat3=cat3,
cat4=cat4,
cat5=cat5,
)
if __name__ == '__main__':
app.run(debug=True)
@app.route('/')
def appfunc():
return render_template('app.html')
@app.route('/customization')
def customization(
cat1_cus=cat1_cus,
cat2_cus=cat2_cus,
cat3_cus=cat3_cus,
cast4_cus=cat4_cus,
cat5_cus=cat5_cus,
):
cat1_cus = name1_global + ' Weight'
cat2_cus = name2_global + ' Weight'
cat3_cus = name3_global + ' Weight'
cat4_cus = name4_global + ' Weight'
cat5_cus = name5_global + ' Weight'
return render_template(
'customization.html',
cat1_cus=cat1_cus,
cat2_cus=cat2_cus,
cat3_cus=cat3_cus,
cat4_cus=cat4_cus,
cat5_cus=cat5_cus,
)
@app.route('/onecat')
def cat(
cat1=cat1,
cat2=cat2,
cat3=cat3,
cat4=cat4,
cat5=cat5,
):
cat1 = name1_global
cat2 = name2_global
cat3 = name3_global
cat4 = name4_global
cat5 = name5_global
return render_template(
'onecat.html',
cat1=cat1,
cat2=cat2,
cat3=cat3,
cat4=cat4,
cat5=cat5,
)
@app.route('/cat1method', methods=['POST'])
def cat1method():
cur = 0
cat1List = sorted(creativity_list.items(), key=lambda x: x[1],
reverse=True)
textfile = open('static/cat1.txt', 'w')
for element in cat1List:
cur += 1
textfile.write(str(cur) + '. ' + str(element) + '\n')
textfile.close()
return send_file('static/cat1.txt', mimetype='text/plain',
attachment_filename=name1_global + ' Sort' + '.txt'
, as_attachment=True)
@app.route('/cat2method', methods=['POST'])
def cat2method():
cur = 0
cat2List = sorted(appearance_list.items(), key=lambda x: x[1],
reverse=True)
textfile = open('static/cat2.txt', 'w')
for element in cat2List:
cur += 1
textfile.write(str(cur) + '. ' + str(element) + '\n')
textfile.close()
return send_file('static/cat2.txt', mimetype='text/plain',
attachment_filename=name2_global + ' Sort' + '.txt'
, as_attachment=True)
@app.route('/cat3method', methods=['POST'])
def cat3method():
cur = 0
cat3List = sorted(complexity_list.items(), key=lambda x: x[1],
reverse=True)
textfile = open('static/cat3.txt', 'w')
for element in cat3List:
cur += 1
textfile.write(str(cur) + '. ' + str(element) + '\n')
textfile.close()
return send_file('static/cat3.txt', mimetype='text/plain',
attachment_filename=name3_global + ' Sort' + '.txt'
, as_attachment=True)
@app.route('/cat4method', methods=['POST'])
def cat4method():
cur = 0
cat4List = sorted(efficiency_list.items(), key=lambda x: x[1],
reverse=True)
textfile = open('static/cat4.txt', 'w')
for element in cat4List:
cur += 1
textfile.write(str(cur) + '. ' + str(element) + '\n')
textfile.close()
return send_file('static/cat4.txt', mimetype='text/plain',
attachment_filename=name4_global + ' Sort' + '.txt'
, as_attachment=True)
@app.route('/cat5method', methods=['POST'])
def cat5method():
cur = 0
cat5List = sorted(execution_list.items(), key=lambda x: x[1],
reverse=True)
textfile = open('static/cat5.txt', 'w')
for element in cat5List:
cur += 1
textfile.write(str(cur) + '. ' + str(element) + '\n')
textfile.close()
return send_file('static/cat5.txt', mimetype='text/plain',
attachment_filename=name5_global + ' Sort' + '.txt'
, as_attachment=True)
@app.route('/customize2', methods=['POST'])
def customize2(
name1=name1,
name2=name2,
name3=name3,
name4=name4,
name5=name5,
):
global name1_global
global name2_global
global name3_global
global name4_global
global name5_global
if request.method == 'POST':
name1_global = request.form['Category 1']
name2_global = request.form['Category 2']
name3_global = request.form['Category 3']
name4_global = request.form['Category 4']
name5_global = request.form['Category 5']
name1 = request.form['Category 1']
name2 = request.form['Category 2']
name3 = request.form['Category 3']
name4 = request.form['Category 4']
name5 = request.form['Category 5']
print (name5)
return render_template(
'customization.html',
name1=name1,
name2=name2,
name3=name3,
name4=name4,
name5=name5,
)
@app.route('/customize', methods=['POST'])
def customize(
total=total,
cat1_cus=cat1_cus,
cat2_cus=cat2_cus,
cat3_cus=cat3_cus,
cat4_cus=cat4_cus,
cat5_cus=cat5_cus
):
global creativity_weight
global appearance_weight
global complexity_weight
global efficiency_weight
global execution_weight
cat1_cus = name1_global + ' Weight'
cat2_cus = name2_global + ' Weight'
cat3_cus = name3_global + ' Weight'
cat4_cus = name4_global + ' Weight'
cat5_cus = name5_global + ' Weight'
if request.method == 'POST':
check = float(request.form['Creativity Weight']) \
+ float(request.form['Appearance Weight']) \
+ float(request.form['Complexity Weight']) \
+ float(request.form['Efficiency Weight']) \
+ float(request.form['Execution Weight'])
if check == 1:
creativity_weight = float(request.form['Creativity Weight'])
appearance_weight = float(request.form['Appearance Weight'])
complexity_weight = float(request.form['Complexity Weight'])
efficiency_weight = float(request.form['Efficiency Weight'])
execution_weight = float(request.form['Execution Weight'])
total = 'Success'
return render_template('customization.html', total=total,cat1_cus=cat1_cus,cat2_cus=cat2_cus,cat3_cus=cat3_cus,cat4_cus=cat4_cus,cat5_cus=cat5_cus)
else:
total = 'ERROR: Weights Did Not Add to 1'
return render_template('customization.html', total=total)
@app.route('/send', methods=['POST'])
def send(
sum=sum,
cat1=cat1,
cat2=cat2,
cat3=cat3,
cat4=cat4,
cat5=cat5
):
global creativity_list
global appearance_list
global complexity_list
global efficiency_list
global execution_list
cat1 = name1_global
cat2 = name2_global
cat3 = name3_global
cat4 = name4_global
cat5 = name5_global
if request.method == 'POST':
project_name = request.form['Project Name']
Creativity = float(request.form['Creativity'])
Appearance = float(request.form['Appearance'])
Complexity = float(request.form['Complexity'])
Efficiency = float(request.form['Efficiency'])
Execution = float(request.form['Execution'])
creativity_list[project_name] = Creativity
appearance_list[project_name] = Appearance
complexity_list[project_name] = Complexity
efficiency_list[project_name] = Efficiency
execution_list[project_name] = Execution
composite = creativity_weight * Creativity + complexity_weight \
* Complexity + efficiency_weight * Efficiency \
+ execution_weight * Execution + appearance_weight \
* Appearance
data = [
project_name,
Creativity,
Appearance,
Complexity,
Efficiency,
Execution,
composite,
]
with open('database.csv', mode='a', newline='') as csv_file:
csv_writer = csv.writer(csv_file, delimiter=',',
quotechar='"',
quoting=csv.QUOTE_MINIMAL)
csv_writer.writerow(data)
sum = 'Successful'
return render_template('app.html', sum=sum,cat1=cat1,cat2=cat2,cat3=cat3,cat4=cat4,cat5=cat5)
@app.route('/rank', methods=['POST'])
def rank(rank1=rank1):
if request.method == 'POST':
cur = 0
rank1 = rank_algo.rank_pd('database.csv')
textfile = open('static/rankings.txt', 'w')
for element in rank1:
cur += 1
textfile.write(str(cur) + '. ' + str(element) + '\n')
textfile.close()
return send_file('static/rankings.txt', mimetype='text/plain',
attachment_filename='rankings.txt',
as_attachment=True)