-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
50 lines (40 loc) · 1.31 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
from flask import Flask, render_template, request
import pandas as pd
import os
app = Flask(__name__)
FILE = "./data/diabetes_clean.csv"
# 读取csv文档
data = pd.read_csv(FILE)
i = 0
@app.route('/')
def index():
global i
qa = data.iloc[[i]].to_dict(orient='records')[0]
i += 1
# qa = data.sample(1).to_dict(orient='records')[0]
names = [qa['doc1'], qa['doc2'], qa['doc3']]
infos = [qa['info1'], qa['info2'], qa['info3']]
answers = [qa['ans1'], qa['ans2'], qa['ans3']]
template = render_template(
'index.html',
title=qa['title'],
question=qa['question'],
names=names,
infos=infos,
answers=answers
)
return template
@app.route('/submit', methods=['POST'])
def submit():
scores = [request.form['score1'], request.form['score2'], request.form['score3']]
question = request.form['question']
answers = [request.form['answer1'], request.form['answer2'], request.form['answer3']]
# 将评分追加到csv文档
for i, answer in enumerate(answers):
data.loc[(data['question'] == question), f'score{i+1}'] = scores[i]
global FILE
filename = FILE.split('_', 1)[0] + '_result.csv'
data.to_csv(filename, index=False)
return render_template('success.html')
if __name__ == '__main__':
app.run(debug=True)