-
Notifications
You must be signed in to change notification settings - Fork 6
/
app.py
224 lines (185 loc) · 5.76 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
# -*- coding:utf-8 -*-
from flask import Flask, url_for, render_template, request, session, redirect
from functools import wraps
import hashlib
from cores.chart import get_area, get_chart, get_alphas, get_m, get_mu, get_pas
from cores.calc import Calculator
from cores.db_info import area_info
app = Flask(__name__)
app.secret_key = '23@#@34232DA4r2@#%33rdfRQd34@$@R#fqa23qf232@#%323r'
user = 'admin'
pwd = '8c6976e5b5410415bde908bd4dee15dfb167a9c873fc4bb8a81f6f2ab448a918'
def check_login(f):
@wraps(f)
def wrap(*args, **kwargs):
if session.get('user') == user and session.get('pwd') == pwd:
return f(*args, **kwargs)
else:
session['current_page'] = request.url
# print(session['current_page'])
return redirect(url_for('login'))
return wrap
@app.route('/login', methods=["POST", "GET"])
def login():
if request.method == 'POST':
user_get = request.form['user']
pwd_get = request.form['pwd']
pwd_hash = hashlib.sha256(pwd_get.encode()).hexdigest()
if user == user_get and pwd == pwd_hash:
session['user'] = user
session['pwd'] = pwd_hash
return redirect(session.get('current_page') or url_for('frame'))
else:
return redirect(request.url)
else:
if session.get('user') == user and session.get('pwd') == pwd:
return redirect(url_for('frame'))
return render_template('login.html')
@app.route('/logout')
def logout():
session['user'] = ""
session['pwd'] = ""
return redirect(url_for('login'))
@app.route('/')
def frame():
return render_template('frame.html')
@app.route('/index')
def index():
session['all_ps'] = [2, 20, 3, 30, 4, 40, 5, 50, 10, 100] # 设计频率列表
session['k'] = 3.5 # Cs/Cv
session['imaxs'] = [50, 45, 40, 50, 55, 60]
coord = request.args.get('coord')
check = check_coord(coord)
warning = ""
if isinstance(check, str):
warning = check
coord = ''
flood_info = {
'warning': warning,
'coord': coord,
**session,
}
for k, v in flood_info.items():
if not v:
flood_info[k] = ""
return render_template('index.html', **flood_info)
@app.route('/pick')
def pick_coord():
return render_template('picker.html')
@app.route('/chart')
@check_login
def chart():
coord = request.args.get('coord')
for k, v in request.args.items():
if k != 'coord':
session[k] = float(v)
check = check_coord(coord)
if isinstance(check, tuple):
lon, lat = check
session['lon'] = lon
session['lat'] = lat
session['imax'] = ''
chart_info = get_chart(lon, lat)
# for k, v in chart_info.items():
# session[k] = v
area = chart_info['area']
if 'area' in session:
del session['area']
if area < 7:
imax = session['imaxs'][area - 1]
session['imax'] = imax
session['alphas'] = get_alphas(area, session['f'])
session['theta'] = session['l'] / session['j'] ** (1 / 3) / session['f'] ** 0.25
session['m'] = get_m(area, session['theta'])
session['mu'] = get_mu(area)
return render_template('chart.html', **chart_info, **session)
else:
warning = check
# print(session)
# if session.get('lon'):
# return render_template('chart.html', **view.chart(session['lon'], session['lat']), **session, warning=warning)
return render_template('index.html', **session, warning=warning)
@app.route('/result')
@check_login
def result():
for k, v in request.args.items():
if k == 'area':
session[k] = int(v)
else:
session[k] = float(v)
ps = []
session['ps_var'] = []
# 获取计算频率列表
for p_var in request.args.keys():
if p_var.startswith('p_'):
p = 1 / float(p_var.split('_')[-1])
ps.append(p)
ps.sort(reverse=True)
session['ps_var'].append(p_var)
session['ps'] = ps
if not ps:
warning = '请选择计算频率!'
del session['area']
return render_template('chart.html', **get_chart(session['lon'], session['lat']), **session, warning=warning)
# 获取4各点雨量列表
yls = []
for i in range(4):
yls.append(session['yl_%d' % (i + 1)])
session['yls'] = yls
# 获取4各点雨量Cv列表
cvs = []
for i in range(4):
cvs.append(session['cv_%d' % (i + 1)])
session['cvs'] = cvs
# 获取4各点雨量Cs列表
session['css'] = [session['k'] * cv for cv in cvs]
# 获取4各点面系数α列表
alphas = []
for i in range(4):
alphas.append(session['alpha_%d' % i])
session['alphas'] = alphas
c = Calculator(**session)
# for attr in dir(c):
# if not attr.startswith('__'):
# session[attr] = getattr(c, attr)
# print(session)
return render_template(
'result.html', **session,
ns=c.ns, r24ps=c.r24ps, kps=c.kps, design_point_rainfalls=c.design_point_rainfalls,
design_area_rainfalls=c.design_area_rainfalls, r_24h_allocate=c.r_24h_allocate, qs=c.qs,
pas=get_pas(ps, session['imax']), area_name=area_info[session['area']],
)
@app.route('/image')
def get_image():
key = request.args.get('key')
file = url_for('static', filename='tu/%s.jpg' % key)
return render_template('image.html', file=file)
@app.route('/show-doc-images')
def show_doc_images():
return render_template('doc_images.html', image_num=range(1, 21))
@app.route('/clear-history')
def clear_history():
keys = list(session.keys())[:]
for k in keys:
del session[k]
return redirect(url_for('frame'))
def check_coord(coord):
if coord:
try:
coord = coord.replace(',', ',')
coord = coord.replace(' ', ',')
coord = coord.replace('|', ',')
lon, lat = [float(x) for x in coord.split(',')]
area = get_area(lon, lat)
if not area:
return '省外坐标点!'
# if area > 6:
# return "山丘区以外坐标点"
except Exception:
return '无效坐标点!'
else:
return ""
return lon, lat
if __name__ == '__main__':
#app.run(debug=True, host='0.0.0.0')
app.run()