-
Notifications
You must be signed in to change notification settings - Fork 1
/
views.py
305 lines (227 loc) · 9.01 KB
/
views.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
#!/usr/bin/env python
#
# Copyright 2007 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#Not needed
#os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
# Note this must be the first line
from google.appengine.dist import use_library
use_library('django', '1.2')
import os
import cgi
from google.appengine.api import users
from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app
from google.appengine.ext.webapp import template
from google.appengine.ext import db
from corestats import Stats
from HTML_Snippets import HTML_snip
from data_samples import data_samples
from analysis_plus import HT
from national_DRL import NDRL_tables
# Define a global data variable for the data
My_Global_DRL = [None]
My_Global_NDRL = [None]
My_local_DRL = [None]
My_Units_Conversion = [None]
class MainPage(webapp.RequestHandler):
def get(self):
HTML = HTML_snip()
# self.response.headers['Content-Type'] = 'text/plain'
# Displays in text if you leave this in!!
#self.response.out.write(HTML.header("DRL Calculator","Home"," "))
#self.response.out.write(HTML.body_header())
#self.response.out.write(HTML.welcome())
#self.response.out.write(HTML.footer)
template_values = {
# 'my_qr_code': my_qr_code,
# 'login_url' : login_url,
# 'logout_url' : logout_url,
# 'logon_message' : logon_message,
# 'user_nickname_or_url' : user_nickname_or_url,
'menu_item' : 'Home',
'pageTitle': 'DRL Calculator',
}
path = os.path.join(os.path.dirname(__file__), 'html/index.html')
self.response.out.write(template.render(path, template_values))
class enterPage(webapp.RequestHandler):
def get(self):
global My_Global_DRL
DRL_num = My_Global_DRL
global My_Global_NDRL
NDRL_num = My_Global_NDRL
global My_local_DRL
local_DRL = My_local_DRL
global My_Units_Conversion
Units_Conversion = My_Units_Conversion
HTML = HTML_snip()
DRL_stats = Stats(DRL_num)
DRL_Histo = HT(DRL_num, NDRL_num,Units_Conversion, local_DRL)
#Anlysis_stats = Dispatch
number_of_points = len(DRL_num)
#self.response.headers['Content-Type'] = 'text/plain'
self.response.out.write(HTML.header("Data Entry","DataEntry", "enterdata"))
self.response.out.write(HTML.body_header())
# This has now output the menu up to the point at which we insert the actual content
self.response.out.write(HTML.calc_header())
# Need to put the input output result header here
self.response.out.write(HTML.data_entry_form_1(NDRL_num))
if number_of_points > 1:
for item in DRL_num:
self.response.out.write('%s\n' % item)
self.response.out.write(HTML.data_entry_form_2())
self.response.out.write(HTML.footer)
class ResultsPage(webapp.RequestHandler):
def get(self):
global My_Global_DRL
DRL_num = My_Global_DRL
global My_Global_NDRL
NDRL_num = My_Global_NDRL
global My_local_DRL
local_DRL = My_local_DRL
global My_Units_Conversion
Units_Conversion = My_Units_Conversion
HTML = HTML_snip()
DRL_stats = Stats(DRL_num)
DRL_Histo = HT(DRL_num, NDRL_num,Units_Conversion,local_DRL)
#Anlysis_stats = Dispatch
number_of_points = len(DRL_num)
#self.response.headers['Content-Type'] = 'text/plain'
self.response.out.write(HTML.header("Results","DataEntry","results"))
self.response.out.write(HTML.body_header())
# This has now output the menu up to the point at which we insert the actual content
self.response.out.write(HTML.calc_header())
# Need to put the input output result header here
# self.response.out.write(HTML.data_entry_form_1(NDRL_num))
# if number_of_points > 1:
# for item in DRL_num:
# self.response.out.write('%s\n' % item)
# self.response.out.write(HTML.data_entry_form_2())
self.response.out.write(HTML.openResultContainer)
if number_of_points > 1:
HTML_bits = DRL_Histo.quick_results()
# This bit is the results and can be included in a separate page
HTML_bits_count = len(HTML_bits)
for item in range(HTML_bits_count):
self.response.out.write(HTML_bits[item])
else:
self.response.out.write("""<div class="Result">""")
self.response.out.write('No data has been entered yet! <br> Copy and paste data or enter directly in the box to the left using a new line for each data point.<br> When you are done click the calculate button.<br> This page will give you a summary of your data. <br>Go to the analysis tab for a detailed breakdown of your data. <br> You may edit data points directly and use calculate to update the results. <br> Go to the sample tab to use pre-set data. ')
self.response.out.write("""</div>""")
# This is the data entry form. Its position is determined by stylesheet parameters
self.response.out.write(HTML.closeResultContainer)
self.response.out.write(HTML.footer)
class enter_data(webapp.RequestHandler):
def post(self):
global My_Global_DRL
global My_Global_NDRL
NDRL_num = My_Global_NDRL
DRL_num = My_Global_DRL
global My_local_DRL
local_DRL = My_local_DRL
global My_Units_Conversion
#Units_Conversion = My_Units_Conversion
# Note the format self.request.get('name') used to collect data from the form.
# Collect the raw string from the text area field
local_DRL = self.request.get('localDRL')
My_local_DRL = local_DRL.decode( 'unicode-escape' ).encode( 'ascii' )
Units_Conversion = self.request.get('units')
My_Units_Conversion = Units_Conversion.decode( 'unicode-escape' ).encode( 'ascii' )
DRL_num_string = self.request.get('DRL_data')
My_NDRL = self.request.get('2005_NDRL')
My_NDRL = My_NDRL.decode( 'unicode-escape' ).encode( 'ascii' )
My_Global_NDRL =My_NDRL.split(',')
DRL_num_string = DRL_num_string.strip()
My_Global_DRL = DRL_num_string.splitlines()
# Test for numbers we do not want anyone pasting scripts here!
# Need to re-write this to ignore blank lines!!
# This fails if a single line is not a number
my_test_list = []
my_test_drl = My_Global_DRL
for item in my_test_drl:
try:
i = float(item)
my_test_list.append(item)
except ValueError, TypeError:
# not numeric
item = item
My_Global_DRL = my_test_list
try:
My_test = My_Global_DRL
[float(item) for item in My_test]
except (TypeError, ValueError):
# total = sum(My_test)
My_Global_DRL = [0]
try:
My_Test_Local=local_DRL
float(My_Test_Local)
except:
My_local_DRL = 0
self.redirect('/results')
class analysis_plus_page(webapp.RequestHandler):
def get(self):
global My_Global_DRL
DRL_num = My_Global_DRL
global My_Global_NDRL
NDRL_num = My_Global_NDRL
global My_Units_Conversion
my_unit_conversion = My_Units_Conversion
global My_local_DRL
local_DRL = My_local_DRL
HTML = HTML_snip()
DRL_stats = Stats(DRL_num)
DRL_Histo = HT(DRL_num, NDRL_num,my_unit_conversion,local_DRL)
#self.response.headers['Content-Type'] = 'text/plain'
self.response.out.write(HTML.header("Analysis","DataEntry", "analysis"))
self.response.out.write(HTML.body_header())
# data = "true"
self.response.out.write(HTML.calc_header())
HTML_bits = DRL_Histo.data_table()
# if data == "true":
#HTML_bits = DRL_Histo.data_table()
HTML_bits_count = len(HTML_bits)
for item in range(HTML_bits_count):
self.response.out.write(HTML_bits[item])
self.response.out.write(HTML.footer)
class SampleData(webapp.RequestHandler):
def get(self):
HTML = HTML_snip()
sample = data_samples()
global My_Units_Conversion
#My_Units_Conversion = "1"
# self.response.headers['Content-Type'] = 'text/plain'
# Displays in text if you leave this in!!
self.response.out.write(HTML.header("Sample Data","sample"," "))
self.response.out.write(HTML.body_header())
self.response.out.write(sample.sample_data())
#self.response.out.write(sample.sample_data_2())
#self.response.out.write(sample.sample_data_3())
#self.response.out.write(sample.sample_data_4())
#self.response.out.write(sample.sample_data_5())
#self.response.out.write(sample.sample_data_6())
self.response.out.write(HTML.footer)
class nationalDRL(webapp.RequestHandler):
def get(self):
HTML = HTML_snip()
NDRL = NDRL_tables()
#NDRL_v2 = NDRL_tables_v2()
#self.response.headers['Content-Type'] = 'text/plain'
# Displays in text if you leave this in!!
self.response.out.write(HTML.header("National DRLs","National_DRLs", " "))
self.response.out.write(HTML.body_header())
#self.response.out.write(NDRL.DRL_2005())
#self.response.out.write(NDRL.NDRL_table_2005())
for item in NDRL.NDRL_table_2005():
self.response.out.write(item)
self.response.out.write(HTML.footer)