-
Notifications
You must be signed in to change notification settings - Fork 21
/
hi-4-x.rb
executable file
·227 lines (196 loc) · 7.97 KB
/
hi-4-x.rb
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
require_relative './model/global_2050_model'
require 'sinatra'
require 'json/pure'
# If we are running in production mode, then we allow browsers
# and caches to store items from here for an hour
MAX_TIME_TO_ALLOW_CACHING = 60 * 60
if settings.production?
# This normally doesn't work, because files served directly from public
# without hitting this server first
set :static_cache_control, [:public, :max_age => MAX_TIME_TO_ALLOW_CACHING]
after do
expires MAX_TIME_TO_ALLOW_CACHING, :public
end
end
# --------------------------------------------------------
# cache the cfps for quick access v22
# --------------------------------------------------------
class Cache
@@cfps
def self.init()
s = "11111111111111111111111111111111111111111111111111111111111";
g = Global2050ModelResult.new
a = []
a << g.calculate_cfps_v22(s)
# #puts "--------------------------------------------------"
# #puts a
# #puts "--------------------------------------------------"
@@cfps = a
#puts "--------------------------------------------------"
#puts @@cfps
#puts "--------------------------------------------------"
end
def self.cfps()
return @@cfps
end
end
# --------------------------------------------------------
# initb the cfps cache
# --------------------------------------------------------
configure do
#puts "init cache"
Cache::init()
end
# --------------------------------------------------------
# send cfps from cache
# --------------------------------------------------------
get '/cfps_v22' do
last_modified Global2050Model.last_modified_date if settings.production? # Don't bother recalculating unless the model has changed
Cache::cfps().to_json
end
# --------------------------------------------------------
# make sure globcalc.html is sent on default
# --------------------------------------------------------
get '/' do
send_file "public/globcalc.html"
end
# --------------------------------------------------------
# pathway access shortcuts
# --------------------------------------------------------
get '/foe/?' do
redirect "/globcalc.html?levers=32334434433444444333314411212324myw121l121111113f2211111111/dashboard/en"
end
get '/distributedeffort/?' do
redirect "/globcalc.html?levers=22rfoe2ss3besss1ssssssssssssssss222sssssss11111sr2211111111/dashboard/en"
end
get '/consumerreluctance/?' do
redirect "/globcalc.html?levers=22rfoe2s23be22312333333333rrr2rr2223333333111112sp211111111/dashboard/en"
end
get '/lowactiononforests/?' do
redirect "/globcalc.html?levers=22rfoe2333be3331333333332s333333222232332311111p32211111111/dashboard/en"
end
get '/consumeractivism/?' do
redirect "/globcalc.html?levers=22rf32o333be333232222233322223222m323f3222111113s2211111111/dashboard/en"
end
get '/iea6ds/?' do
redirect "/globcalc.html?levers=22rfoe2e13be1111c2c2c1n31hfjdcef222hp233f211111fn2211111111/dashboard/en"
end
get '/iea4ds/?' do
redirect "/globcalc.html?levers=22rfoe2ib3becdd1ep2p2cp3e2ilgfgi222r3233j3111112f2211111111/dashboard/en"
end
get '/iea2ds/?' do
redirect "/globcalc.html?levers=22rfzhgsi3bee331jx3xp3C333lnoojp222333332f111113r2211111111/dashboard/en"
end
get '/shellmountains/?' do
redirect "/globcalc.html?levers=m22l3221w4211f3123333p23z32g1wd322223mqpfD111112A2211111111/dashboard/en"
end
get '/shelloceans/?' do
redirect "/globcalc.html?levers=m21d22m3l3211p4123333c34jhogb4e422op3oqpt411111242211111111/dashboard/en"
end
get '/mottmacdonald/?' do
redirect "/globcalc.html?levers=223C322C2C332pCpdzzn22p322of1lf2plp2rspAC211111322211111111/dashboard/en"
end
get '/climact/?' do
redirect "/globcalc.html?levers=2233333333333333333331331fnnnnnn333222222d111112s2211111111/dashboard/en"
end
get '/icept/?' do
redirect "/globcalc.html?levers=22rfzhgw33bee331dzzn2j33p2sn33jy2332322p2f11111232211111111/dashboard/en"
end
get '/rcp85/?' do
redirect "/globcalc.html?levers=g311111111111111c1b111cybihogjgi233ssr2eAs11111gA2211111111/dashboard/en"
end
get '/rcp60/?' do
redirect "/globcalc.html?levers=mjfffeedbmmosqr2jj2jj1s31bg11e11333213312111111112211111111/dashboard/en"
end
get '/rcp26/?' do
redirect "/globcalc.html?levers=p1ql222n2fffcjgt3stttBppBhhg1d11y3x3333np311111ot2211111111/dashboard/en"
end
get '/tiamucl4ds/?' do
redirect "/globcalc.html?levers=l23xiiiqpi2p2f1cf2poj12p12db1nr1ppp2p222ph11111c22211111111/dashboard/en"
end
get '/tiamucl2ds/?' do
redirect "/globcalc.html?levers=l2wz222CBpp3pC3f2Dw3DC3plzgj1tA13pp2p223ri11111p22211111111/dashboard/en"
end
get '/wecpsijazz/?' do
redirect "/globcalc.html?levers=rirfne2bb2bd1111jx3xpb13igihghih222pp23312111112f2211111111/dashboard/en"
end
get '/wecpsisymphony/?' do
redirect "/globcalc.html?levers=jnrfxg22pobdeoo1zzzz3l23vqhwo3gm22233333bf111113r2211111111/dashboard/en"
end
get '/vegansociety/?' do
redirect "/globcalc.html?levers=2222jjj21222gfgebf1jg1igcjgjeeefDDDDD11n2211111DB2211111111/dashboard/en"
end
get '/cambridgearchitecturalresearch/?' do
redirect "/globcalc.html?levers=pps3p32p3p33333p2qqqqf33f2s33j33p2t2p1p21p11111p32211111111/dashboard/en"
end
get '/chathamhouselowmeat/?' do
redirect "/globcalc.html?levers=22rfoe2ib3becdd1dr1hhcp3e2ilgfgi33433333j3111113g2211111111/dashboard/en"
end
get '/chathamhousehighmeat/?' do
redirect "/globcalc.html?levers=22rfzhgsi3bee331dzzn2jC333lnoojp111333332f11111332211111111/dashboard/en"
end
# --------------------------------------------------------
# sankey data server for prototype 22
# --------------------------------------------------------
get '/serve_sankey_v22/:parameterstring' do
#puts "---- start get -------------"
s = params[:parameterstring]
# do some brut force testing and input error fixing --> needs to be improved !
#puts "original params = " + s
# !!! ATTENTION: this needs to be flexible for different versions of calculator !!! :
if s.length != 59
s = "11111111111111111111111111111111111111111111111111111111111";
#puts "corrected params = " + s
end
g = Global2050ModelResult.new
a = []
a << g.calculate_sankey_v22(s)
##puts "--------------------------------------------------"
##puts a
##puts "--------------------------------------------------"
a.to_json
end
# --------------------------------------------------------
# data plus setup server for prototype 22
# --------------------------------------------------------
get '/serve_plus_setup_v22/:parameterstring' do
last_modified Global2050Model.last_modified_date if settings.production?# Don't bother recalculating unless the model has changed
#puts "---- start get -------------"
s = params[:parameterstring]
# do some brut force testing and input error fixing --> needs to be improved !
#puts "original params = " + s
# !!! ATTENTION: this needs to be flexible for different versions of calculator !!! :
if s.length != 59
s = "11111111111111111111111111111111111111111111111111111111111";
#puts "corrected params = " + s
end
g = Global2050ModelResult.new
a = []
a << g.calculate_pathway_plus_setup_v22(s)
##puts "--------------------------------------------------"
##puts a
##puts "--------------------------------------------------"
a.to_json
end
# --------------------------------------------------------
# data server for prototype 22
# --------------------------------------------------------
get '/serve_v22/:parameterstring' do
last_modified Global2050Model.last_modified_date if settings.production? # Don't bother recalculating unless the model has changed
#puts "---- start get -------------"
s = params[:parameterstring]
# do some brut force testing and input error fixing --> needs to be improved !
#puts "original params = " + s
# !!! ATTENTION: this needs to be flexible for different versions of calculator !!! :
if s.length != 59
s = "11111111111111111111111111111111111111111111111111111111111";
#puts "corrected params = " + s
end
g = Global2050ModelResult.new
a = []
a << g.calculate_pathway_v22(s)
#puts "--------------------------------------------------"
#puts a
#puts "--------------------------------------------------"
a.to_json
end