-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsources.php
More file actions
executable file
·408 lines (373 loc) · 13.1 KB
/
sources.php
File metadata and controls
executable file
·408 lines (373 loc) · 13.1 KB
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
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
<!doctype html><html><head>
<?php include'imports.php'?>
<script>
function init(){
calculateGHG();
findCriticGHG();
Caption.listeners();
addDetailedListeners();
updateResult();
//onclick listeners for substage counters: link to substages.php
var tds=document.querySelectorAll('td.ss');
for(var i=0;i<tds.length;i++) {
tds[i].onclick=function(){window.location='substages.php'}
}
}
function drawCharts(){ }
function calculateGHG() {
//kg, kg per year, or kg per serviced population
var divisor=(function() {
var ret=1;//return value
var select=document.querySelector('#ghg_divisor');
switch(select.value) {
case 'years':
ret=Global.General.Years();
break;
case 'serv_pop':
ret=function(code)
{
var ye=Global.General.Years();
var ws=ye*Global.Water.ws_serv_pop;
var ww=ye*Global.Waste.ww_serv_pop;
var To=ye*(ws+ww);
switch(code.substring(0,2))
{
case "ws": return ws; break;
case "ww": return ww; break;
case "To": return To; break;
default: return ye; break;
}
};
break;
default:
break;
}
return ret;
})();
var fields=document.querySelectorAll('#sources [field]');
for(var i=0;i<fields.length;i++)
{
var element=fields[i];
var code=element.getAttribute('field');
var divisor_value = typeof(divisor)=="function" ? divisor(code) : divisor;
var loc=locateVariable(code);
var ghg_type = document.querySelector('#ghg_divisor').value; // pass GHG divisor to Global functions - improv #2
var value = loc.sublevel ? (Global[loc.level][loc.sublevel][code](ghg_type) / divisor_value) : (Global[loc.level][code](ghg_type) / divisor_value);
// ensure only display "NA" at GHG Emissions Summary tab - improv #2
if(isNaN(value) && code == 'TotalGHG' && document.querySelector('#ghg_divisor').value == 'serv_pop') {
element.innerHTML = "NA";
}else {
element.innerHTML = format(value);
}
element.setAttribute('value', value);
}
}
function findCriticGHG() {
let value = 0;
let area = '';
var max=0;
var critic=false;
var fields=document.querySelectorAll('#sources td[field]');
for(var i=0;i<fields.length;i++) {
value=parseFloat(fields[i].getAttribute('value'));
if(value>max) {
max=value;
critic=fields[i].getAttribute('field')
area = 'sources';
}
}
// patch - also seek max with outside utility boundaries
var outside_fields = document.querySelectorAll('#outside td[field]');
outside_fields.forEach(function(td) {
value=parseFloat(td.innerText.split(',').join(''));
if(value > max) {
max = value;
critic=td.getAttribute('field');
area = 'outside';
}
});
if(!critic)return;
var element=document.querySelector("#"+area+" td[field="+critic+"]");
if (area === 'sources') {
//CO2
element.classList.add('critic');
element.setAttribute('cap',translate("This is the highest GHG emission of your system"));
//substages number
element.previousSibling.classList.add('critic');
element.previousSibling.setAttribute('caption',element.getAttribute('cap'));
//name
element.previousSibling.previousSibling.classList.add('critic');
element.previousSibling.previousSibling.setAttribute('caption',element.getAttribute('cap'));
}else if (area === 'outside') {
element.classList.add('critic');
element.setAttribute('cap',"Outside utility has highest GHG emission of your system");
//name
element.previousSibling.classList.add('critic');
element.previousSibling.setAttribute('caption',element.getAttribute('cap'));
}
}
function addDetailedListeners() {
var tds=document.querySelectorAll("td[field][level][sublevel]");
for(var i=0;i<tds.length;i++)
{
tds[i].onmousemove=function(event)
{
var con=document.querySelector('#container_detailed');
con.style.display=''
con.style.left=(event.clientX+35)+"px"
con.style.top=(event.clientY-50)+"px"
}
}
}
//fill table of detailed ghg sources
function fillSources(td,ev) {
//fill table
var lvl=td.getAttribute('level');
var sub=td.getAttribute('sublevel');
var obj=Global[lvl][sub];
var t=document.querySelector('table#detailed');
while(t.rows.length>0)t.deleteRow(-1);
for(var field in obj)
{
if(field.search('_KPI_GHG_')+1)
{
var newRow=t.insertRow(-1);
newRow.insertCell(-1).innerHTML=translate(field+"_descr");
var newCell=newRow.insertCell(-1)
newCell.style.textAlign='right'
newCell.innerHTML=format(obj[field]());
}
}
//hide table
td.onmouseout=function(){document.querySelector('#container_detailed').style.display='none'};
}
</script>
<style>
#sources td.ss {text-align:center;cursor:pointer} /*substages counter*/
#sources td[field][level][sublevel]{cursor:help;padding-right:1em}
#sources td[field][level][sublevel]:hover{background:rgba(64,83,109,0.2);transition:all 0.5s}
#sources {
box-shadow: 1px 1px 1px 1px rgba(0,0,0,.1);
}
</style>
</head><body onload=init()><center>
<!--sidebar--><?php include'sidebar.php'?>
<!--navbar--> <?php include'navbar.php'?>
<!--linear--> <?php include'linear.php'?>
<!--caption--><?php include'caption.php'?>
<!--title-->
<h1>
<script>document.write(Global.General.Name)</script>
—
<?php write("#GHG Emissions Summary (Overview)")?>
</h1>
<h4>
<?php write("#assessment_period")?>
<b>
<script>document.write(Global.General.Days())</script> <?php write("#days")?>
(<script>document.write(Global.General.Years())</script> <?php write("#years")?>)
</b>
</h4>
<h4>
<?php write("#move_the_mouse")?>
</h4>
<!--mobile div detailed sources-->
<div id=container_detailed style=display:none>
<div><b>
<?php write("#Detailed GHG sources")?>
</b></div>
<table id=detailed></table>
<style>
div#container_detailed {
font-size:11px;
font-family:monospace;
position:fixed;
z-index:998;
background:white;
padding:0.3em 0.5em;
box-shadow: 1px 1px 1px 1px rgba(0,0,0,.1);
border:1px solid #ccc;
text-align:left;
}
</style>
</div>
<!--content-->
<div style=width:66%;>
<!--tab buttons-->
<div class=tab_buttons id=ghg_summary_tabs>
<button class=left onclick="tabs_show_tables()" disabled>
<?php write("#Tables")?>
</button>
<button class=right onclick="tabs_show_graphs()">
<?php write("#Charts")?>
</button>
<script>
function tabs_show_graphs(){
document.getElementById('tables').style.display='none'
document.getElementById('graphs_container').style.display=''
Graphs.graph4(false,'graph_1');
Graphs.graph1(false,'graph_2');
document.querySelector('#ghg_summary_tabs button.right').setAttribute('disabled',true)
document.querySelector('#ghg_summary_tabs button.left').removeAttribute('disabled')
}
function tabs_show_tables(){
document.getElementById('tables').style.display=''
document.getElementById('graphs_container').style.display='none'
document.querySelector('#ghg_summary_tabs button.right').removeAttribute('disabled')
document.querySelector('#ghg_summary_tabs button.left').setAttribute('disabled',true)
}
</script>
</div>
<!--tables: left tab-->
<div id=tables>
<!--sources of ghg-->
<div>
<div>
<table id=sources>
<tr><td colspan=5 style=text-align:center>
<?php write("#GHG emissions")?>
<!--select divisor-->
<select id=ghg_divisor onchange=init()>
<option value=none>Kg CO2 eq
<option value=years>Kg CO2 eq / <?php write("#year")?>
<option value=serv_pop>Kg CO2 eq / <?php write("#year")?> / <?php write("#ws_serv_pop_descr")?>
</select>
<!--legend-->
<span style=float:right>
<span class=circle style=background:orange></span>
<?php write("#highest emission")?>
</span>
<tr><th rowspan=9 style="font-weight:bold;background:#2b6488;color:white">
<?php write('#TOTAL GHG')?>
<br><br><span field=TotalGHG>
<?php write("#Loading")?>...
</span>
<th rowspan=3 style="background:#00aff1">
<a href="edit.php?level=Water" style=color:white>
<?php write("#Water")?>
(<script>
document.write(Global.Water.ws_serv_pop)
</script>
<?php write("#people")?>
)
</a>
<br><br><span field=ws_KPI_GHG>
<?php write("#Loading")?>...
</span>
</th>
<!--wsa-->
<td><img src=img/waterAbs.png> <a href='edit.php?level=Water&sublevel=Abstraction'><?php write('#Abstraction')?></a>
<td caption="Number of substages" class=ss><script>document.write(Substages.Water.Abstraction.length)</script>
<td field=wsa_KPI_GHG level=Water sublevel=Abstraction onmouseenter=fillSources(this,event)><?php write('#Loading')?>...
<!--wst-->
<tr><td><img src=img/waterTre.png> <a href='edit.php?level=Water&sublevel=Treatment'><?php write('#Treatment')?></a>
<td caption="Number of substages" class=ss><script>document.write(Substages.Water.Treatment.length)</script>
<td field=wst_KPI_GHG level=Water sublevel=Treatment onmouseenter=fillSources(this,event)><?php write('#Loading')?>...
</tr>
<!--wsd-->
<tr><td><img src=img/waterDis.png> <a href='edit.php?level=Water&sublevel=Distribution'><?php write('#Distribution')?></a>
<td caption="Number of substages" class=ss><script>document.write(Substages.Water.Distribution.length)</script>
<td field=wsd_KPI_GHG level=Water sublevel=Distribution onmouseenter=fillSources(this,event)>
<?php write('#Loading')?>...
<tr>
<th rowspan=3 class=red>
<a href="edit.php?level=Waste" style=color:white>
<?php write("#Waste")?>
(<script>
document.write(Global.Waste.ww_serv_pop)
</script> <?php write("#people")?>)
</a>
<br><br>
<span field=ww_KPI_GHG>
<?php write('#Loading')?>...
</span>
</th>
<!--wwc-->
<td><img src=img/wasteCol.png> <a href='edit.php?level=Waste&sublevel=Collection'><?php write('#Collection')?></a>
<td caption="<?php write('#Number of substages')?>" class=ss><script>document.write(Substages.Waste.Collection.length)</script>
<td field=wwc_KPI_GHG level=Waste sublevel=Collection onmouseenter=fillSources(this,event)><?php write('#Loading')?>...
</td>
<!--wwt-->
<tr><td><img src=img/wasteTre.png> <a href='edit.php?level=Waste&sublevel=Treatment'><?php write('#Treatment')?></a>
<td caption="<?php write('#Number of substages')?>" class=ss><script>document.write(Substages.Waste.Treatment.length)</script>
<td field=wwt_KPI_GHG level=Waste sublevel=Treatment onmouseenter=fillSources(this,event)><?php write('#Loading')?>...
</tr>
<!--wwd-->
<tr><td><img src=img/wasteDis.png> <a href='edit.php?level=Waste&sublevel=Discharge'><?php write('#Discharge')?></a>
<td caption="<?php write('#Number of substages')?>" class=ss><script>document.write(Substages.Waste.Discharge.length)</script>
<td field=wwd_KPI_GHG level=Waste sublevel=Discharge onmouseenter=fillSources(this,event)><?php write('#Loading')?>...
</tr>
</table>
</div>
<style>
@keyframes blink { from {background-color: white;} to {background-color: orange;} }
table#sources .critic {
color:black;
cursor:help;
font-weight:bold;
animation:blink 3s ease 0.5s infinite alternate;
}
#sources a {color:black;font-weight:bold}
table#sources td[field][value].critic:before {
content:'\26a0 ';
float:left;
color:red;
}
table#sources{
margin:10px 0;
width:95%;
}
table#sources td {padding:1.2em 0.5em;max-width:70px}
table#sources td[field] {text-align:right}
table#sources img {vertical-align:middle;width:30px;margin-right:10px}
/* Patch for outside utility critial highlight */
table#outside .critic {animation:blink 3s ease 0.5s infinite alternate;}
</style>
</div>
<!--emissions outside boundaries-->
<div>
<table id=outside style="width:95%;margin:1.5em 0">
<tr>
<th rowspan=2 style=background:purple>
<?php write("#GHG emissions")?>
<br>
<?php write("#outside utility boundaries")?>
<br>
(kg CO2 eq)
</th>
<td>
<?php write("#wwc_SL_ghg_unc_descr")?>
(<a href=variable.php?id=wwc_SL_ghg_unc>wwc_SL_ghg_unc</a>)
<td field=wwc_SL_ghg_unc>
<script>
document.write(format(Global.Waste.Collection.wwc_SL_ghg_unc()))
</script>
</td>
</tr>
<tr>
<td>
<?php write("#wwc_SL_ghg_ons_descr")?>
(<a href=variable.php?id=wwc_SL_ghg_ons>wwc_SL_ghg_ons</a>)
<td field=wwc_SL_ghg_ons>
<script>
document.write(format(Global.Waste.Collection.wwc_SL_ghg_ons()))
</script>
</td>
</tr>
</table>
<style>
table#outside td[field] {text-align:right}
</style>
</div>
</div>
<!--graph 1: right tab-->
<div id=graphs_container style=display:none>
<div id=graph_1><?php write('#Loading')?>...</div>
<div style="border-top:1px solid #ccc"></div>
<div id=graph_2><?php write('#Loading')?>...</div>
</div>
</div>
<!--CURRENT JSON--><?php include'currentJSON.php'?>
<script>
google.charts.load('current',{'packages':['corechart','gauge','bar']});
</script>