-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.py
executable file
·345 lines (297 loc) · 11.6 KB
/
server.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
#!env/bin/python
import web
import json
from tracer import run_tracer, is_landpoint, get_closest_index, is_lacking_data
# from cache import get_cached_results, NotCached, cache_results, NotWritten
from logging import getLogger, INFO, Formatter
from logging.handlers import TimedRotatingFileHandler
from time import strptime
import math
urls = ('/fukushima', 'Fukushima',
'/deepwaterhorizon', 'DeepWaterHorizon',
'/rubberduckiespill', 'RubberDuckieSpill',
'/renaspill', 'RenaSpill',
'/', 'Index',
'/favicon.ico', 'Favicon',
'/map', 'Map',
'/run', 'RunTracer',
'/backward', 'Backward',
'/runBwd', 'RunTracerBwd',
'/australia', 'Australia',
'/runAus','RunTracerAus',
'/mediterranean', 'Mediterranean',
'/runMed','RunTracerMed',
'/europe', 'Europe',
'/runEurope','RunTracerEurope',
'/klokhuis','Klokhuis',
'/runKlok','RunTracerKlok',
'/what', 'What',
'/how', 'How',
'/background', 'Background',
'/faq', 'FAQ',
'/media', 'Media',
'/team', 'Team',
'/plastinography','Plastinography',
'/regions', 'Regions',
'/bwdfwd','BwdFwd')
render = web.template.render('templates', base='map_layout')
servemap750 = web.template.render('templates', base='map750_layout')
render675 = web.template.render('templates', base='map675_layout')
# set up logging. for more information, see
# http://docs.python.org/2/howto/logging.html#logging-basic-tutorial
logger = getLogger(__name__)
logger.propagate = False
handler = TimedRotatingFileHandler("log/adrift.log", when="D", interval=1)
formatter = Formatter("%(asctime)s,%(message)s", datefmt='%m/%d/%Y %H:%M:%S')
handler.setFormatter(formatter)
logger.addHandler(handler)
logger.setLevel(INFO)
# dedicated experiments
class Fukushima:
def GET(self):
logger.info(str(web.ctx.ip) + " fukushima")
return render.map(lat=37.8, lng=142, center=141.0, icon_filename="/static/MarkerTsunami.png")
class DeepWaterHorizon:
def GET(self):
logger.info(str(web.ctx.ip) + " deepwaterhorizon")
return render.map(lat=28, lng=-89.4, center=-70.0, icon_filename="/static/MarkerOilRig.png")
class RubberDuckieSpill:
def GET(self):
logger.info(str(web.ctx.ip) + " rubberduckiespill")
return render.map(lat=44.7, lng=178.1, center=-165)
class RenaSpill:
def GET(self):
logger.info(str(web.ctx.ip) + " renaspill")
return render.map(lat=-37.5, lng=176.7, center=-140, icon_filename="/static/MarkerShip.png")
# other pages
class Index:
def GET(self):
logger.info(str(web.ctx.ip) + " root")
return render.map()
class Map:
def GET(self):
i = web.input()
try:
try:
center = i.center
except AttributeError:
center = 30
try:
monthDict={'Jan':'Jan', 'Feb':'Jan', 'Mar':'Mar', 'Apr':'Mar', 'May':'May', 'Jun':'May', 'Jul':'Jul', 'Aug':'Jul', 'Sep':'Sep', 'Oct':'Sep', 'Nov':'Nov', 'Dec':'Nov'}
try:
startmon = str(i.startmon)
startmon = startmon[:1].upper() + startmon[1:].lower()
startmon = monthDict[startmon]
except KeyError:
startmon = 'Jan'
except AttributeError:
startmon = 'Jan'
return render.map(lat=i.lat, lng=i.lng, center=center, startmon=startmon)
except AttributeError:
return render.map()
class Favicon:
def GET(self):
raise web.redirect("/static/favicon.ico")
class RunTracer:
def GET(self):
i = web.input()
try:
given_lat = float(i.lat)
given_lng = float(i.lng)
except AttributeError:
# if no attributes are given, return nothing.
return ""
logger.info(str(web.ctx.ip) + " map," + str(given_lat) + "," + str(given_lng))
closest_index = get_closest_index(given_lat, given_lng,'Global')
ret = ""
if is_lacking_data(closest_index,'Global'):
ret = json.dumps("Sorry, we have no data for that ocean area")
elif is_landpoint(closest_index,'Global'):
ret = json.dumps("You clicked on land, please click on the ocean")
else:
linkfile = "https://swift.rc.nectar.org.au/v1/AUTH_24efaa1ca77941c18519133744a83574/globalCsvMonthly/Global_index"+str(closest_index).zfill(5)+"_startsin"+i.startmon+".csv";
ret = json.dumps(linkfile)
return ret
class What:
def GET(self):
logger.info(str(web.ctx.ip) + " what")
return render.map(open_page="what")
class How:
def GET(self):
logger.info(str(web.ctx.ip) + " how")
return render.map(open_page="how")
class Background:
def GET(self):
logger.info(str(web.ctx.ip) + " background")
return render.map(open_page="background")
class FAQ:
def GET(self):
logger.info(str(web.ctx.ip) + " faq")
return render.map(open_page="faq")
class Team:
def GET(self):
logger.info(str(web.ctx.ip) + " team")
return render.map(open_page="team")
class Media:
def GET(self):
logger.info(str(web.ctx.ip) + " media")
return render.map(open_page="media")
class Plastinography:
def GET(self):
logger.info(str(web.ctx.ip) + " plastinography")
return servemap750.map750()
class Klokhuis:
def GET(self):
logger.info(str(web.ctx.ip) + " klokhuis")
return render675.map675()
class RunTracerKlok:
def GET(self):
i = web.input()
try:
given_lat = float(i.lat)
given_lng = float(i.lng)
except AttributeError:
# if no attributes are given, return nothing.
return ""
logger.info(str(web.ctx.ip) + " klokhuis," + str(given_lat) + "," + str(given_lng))
closest_index = get_closest_index(given_lat, given_lng,'Global')
ret = ""
if is_lacking_data(closest_index,'Global'):
ret = json.dumps("Sorry, we hebben geen data voor die locatie")
elif is_landpoint(closest_index,'Global'):
ret = json.dumps("Sorry, je klikte niet op de oceaan")
else:
linkfile = "https://swift.rc.nectar.org.au/v1/AUTH_24efaa1ca77941c18519133744a83574/globalCsv/Global_index"+str(closest_index).zfill(5)+".csv";
ret = json.dumps(linkfile)
return ret
class Regions:
def GET(self):
logger.info(str(web.ctx.ip) + " regions")
return render.map(open_page="regions")
class BwdFwd:
def GET(self):
logger.info(str(web.ctx.ip) + " bwdfwd")
return render.map(open_page="bwdfwd")
class Australia:
def GET(self):
i = web.input()
try:
return render.australia(lat=i.lat, lng=i.lng)
except AttributeError:
return render.australia()
class RunTracerAus:
def GET(self):
i = web.input()
try:
given_lat = float(i.lat)
given_lng = float(i.lng)
except AttributeError:
# if no attributes are given, return nothing.
return ""
logger.info(str(web.ctx.ip) + " australia," + str(given_lat) + "," + str(given_lng))
closest_index = get_closest_index(given_lat, given_lng,'Australia')
ret = ""
if is_lacking_data(closest_index,'Australia'):
ret = json.dumps("Sorry, we have no data for that ocean area")
elif is_landpoint(closest_index,'Australia'):
ret = json.dumps("You clicked on land, please click on the ocean")
else:
linkfile = "https://swift.rc.nectar.org.au/v1/AUTH_24efaa1ca77941c18519133744a83574/australiaCsv/Australia_index"+str(closest_index).zfill(5)+".csv";
ret = json.dumps(linkfile)
return ret
class Mediterranean:
def GET(self):
i = web.input()
try:
return render.mediterranean(lat=i.lat, lng=i.lng)
except AttributeError:
return render.mediterranean()
class RunTracerMed:
def GET(self):
i = web.input()
try:
given_lat = float(i.lat)
given_lng = float(i.lng)
except AttributeError:
# if no attributes are given, return nothing.
return ""
logger.info(str(web.ctx.ip) + " mediterranean," + str(given_lat) + "," + str(given_lng))
closest_index = get_closest_index(given_lat, given_lng,'Mediterranean')
ret = ""
if is_lacking_data(closest_index,'Mediterranean'):
ret = json.dumps("Sorry, we have no data for that ocean area")
elif is_landpoint(closest_index,'Mediterranean'):
ret = json.dumps("You clicked on land, please click on the ocean")
else:
linkfile = "https://swift.rc.nectar.org.au/v1/AUTH_24efaa1ca77941c18519133744a83574/MediterraneanCsv/Mediterranean_index"+str(closest_index).zfill(5)+".csv";
ret = json.dumps(linkfile)
return ret
class Europe:
def GET(self):
i = web.input()
try:
return render.europe(lat=i.lat, lng=i.lng)
except AttributeError:
return render.europe()
class RunTracerEurope:
def GET(self):
i = web.input()
try:
given_lat = float(i.lat)
given_lng = float(i.lng)
except AttributeError:
# if no attributes are given, return nothing.
return ""
logger.info(str(web.ctx.ip) + " europe," + str(given_lat) + "," + str(given_lng))
closest_index = get_closest_index(given_lat, given_lng,'Europe')
ret = ""
if is_lacking_data(closest_index,'Europe'):
ret = json.dumps("Sorry, we have no data for that ocean area")
elif is_landpoint(closest_index,'Europe'):
ret = json.dumps("You clicked on land, please click on the ocean")
else:
linkfile = "https://swift.rc.nectar.org.au/v1/AUTH_24efaa1ca77941c18519133744a83574/europeCsv/Europe_index"+str(closest_index).zfill(5)+".csv";
ret = json.dumps(linkfile)
return ret
class Backward:
def GET(self):
i = web.input()
try:
try:
center = i.center
except AttributeError:
center = 30
return render.backward(lat=i.lat, lng=i.lng, center=center)
except AttributeError:
return render.backward()
class RunTracerBwd:
def GET(self):
i = web.input()
try:
given_lat = float(i.lat)
given_lng = float(i.lng)
except AttributeError:
# if no attributes are given, return nothing.
return ""
logger.info(str(web.ctx.ip) + " backward," + str(given_lat) + "," + str(given_lng))
closest_index = get_closest_index(given_lat, given_lng,'GlobalBwd')
ret = ""
if is_lacking_data(closest_index,'GlobalBwd'):
ret = json.dumps("Sorry, we have no data for that ocean area")
elif is_landpoint(closest_index,'GlobalBwd'):
ret = json.dumps("You clicked on land, please click on the ocean")
else:
linkfile = "https://swift.rc.nectar.org.au/v1/AUTH_24efaa1ca77941c18519133744a83574/globalbwdCsv/Global_index"+str(closest_index).zfill(5)+".csv";
ret = json.dumps(linkfile)
return ret
def notfound():
return web.notfound(render.map())
if __name__ == "__main__":
from sys import argv
if not (len(argv) >= 2 and argv[1].startswith("dev")):
web.wsgi.runwsgi = lambda func, addr=None: web.wsgi.runfcgi(func, addr)
else:
argv.pop(1)
app = web.application(urls,globals())
app.notfound = notfound
app.run()