-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.html
447 lines (362 loc) · 16.8 KB
/
index.html
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
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
<!doctype html>
<html>
<style>
path {
fill: none;
}
.axis path,
.axis line {
fill: none;
stroke: grey;
stroke-width: 1;
shape-rendering: crispEdges;
}
</style>
<head>
<meta charset="utf-8"/>
<script src="https://polygit.org/components/webcomponentsjs/webcomponents-lite.min.js"></script>
<link href="https://polygit.org/components/polymer/polymer.html" rel="import">
<link rel="import" href="https://polygit.org/components/paper-tabs/paper-tabs.html">
<link rel="import" href="https://polygit.org/components/paper-input/paper-input.html">
<link rel="import" href="https://polygit.org/components/paper-button/paper-button.html">
<script src='https://cdn.firebase.com/js/client/2.3.0/firebase.js'></script>
<link rel='stylesheet' type='text/css' href='index.css'>
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<script src="http://d3js.org/d3.v3.min.js"></script>
<script src='io.js'></script>
<script src='../TestingLineChart/plot.js'></script>
<script type="text/javascript" src='../OverViewCharts/overview.js'></script>
<title>Ecaura</title>
</head>
<body>
<div id="logo">
<img src="ecauragreen.png" alt="logo" height="25px" >
<select id='monthInput' >
<option value=''>Month</option>
<option selected value='january'>Jan</option>
<option value='february'>Feb</option>
<option value='march'>Mar</option>
<option value='april'>Apr</option>
<option value='may'>May</option>
<option value='june'>Jun</option>
<option value='july'>Jul</option>
<option value='august'>Aug</option>
<option value='september'>Sep</option>
<option value='october'>Oct</option>
<option value='november'>Nov</option>
<option value='december'>Dec</option>
</select>
<select id='yearInput'>
<option value=''>Year</option>
<option value='2006'>2006</option>
<option value='2007'>2007</option>
<option value='2008'>2008</option>
<option value='2009'>2009</option>
<option value='2010'>2010</option>
<option value='2011'>2011</option>
<option value='2012'>2012</option>
<option value='2013'>2013</option>
<option value='2014'>2014</option>
<option value='2015'>2015</option>
<option selected value='2016'>2016</option>
<option value='2017'>2017</option>
<option value='2018'>2018</option>
<option value='2019'>2019</option>
<option value='2020'>2020</option>
</select>
<span id= "user">
<paper-button raised type="submit" > nyuad ▼</paper-button>
</span>
</div>
</div>
<!-- Left Side Form -->
<div id="ParameterBox">
<!-- Tab Titles (Parameters) -->
<!-- Logo and Date -->
<paper-tabs id="papertabs" selected="0">
<paper-tab data-toggle="tab" href="#water" data-id:"water">Water</paper-tab>
<paper-tab data-toggle="tab" href="#electricity">Electricity</paper-tab>
<paper-tab data-toggle="tab" href="#waste">Waste</paper-tab>
<paper-tab data-toggle="tab" href="#fuel">Fuel</paper-tab>
<paper-tab data-toggle="tab" href="#food">Food</paper-tab></paper-tabs>
<!-- Content for each tab -->
<div class="tab-content">
<div id="water" class="tab-pane fade in active">
<p class="ParameterDescription">
<!-- SubContent for each tab -->
<paper-input id='WaterReservoir' label='Water Reservoir (litres/month)'></paper-input><br>
<paper-input id='GroundWater' label='Ground Water (litres/month)'></paper-input><br>
<paper-input id='DesalinatedWater' label='Desalinated Water (litres/month)'></paper-input><br>
<paper-input id='RecycledWater' label='RecycledWater (litres/month)'></paper-input><br>
</p>
</div>
<div id="electricity" class="tab-pane fade">
<p class="ParameterDescription">
<!-- SubContent for each tab -->
<paper-input id='Nuclear' label='Nuclear (kWh/month)'></paper-input><br>
<paper-input id='Solar' label='Solar (kWh/month)'></paper-input><br>
<paper-input id='Wind' label='Wind (kWh/month)'></paper-input><br>
<paper-input id='HydroElectric' label='HydroElectric (kWh/month)'></paper-input><br>
<paper-input id='FossilFuels' label='Fossil Fuels (kWh/month)'></paper-input>
</p>
</div>
<div id="waste" class="tab-pane fade">
<p class="ParameterDescription">
<!-- SubContent for each tab -->
<paper-input id='Plastic' label='Plastic (kg/month)'></paper-input><br>
<paper-input id='Paper' label='Paper (kg/month)'></paper-input><br>
<paper-input id='Glass' label='Glass (kg/month)'></paper-input><br>
<paper-input id='Metal' label='Metal (kg/month)'></paper-input><br>
<paper-input id='Landfill' label='Landfill (kg/month)'></paper-input></p>
</div>
<div id="fuel" class="tab-pane fade">
<p class="ParameterDescription">
<!-- SubContent for each tab -->
<paper-input id='NaturalGas' label='Natural Gas (litres/month)'></paper-input><br>
<paper-input id='FuelOil' label='Fuel Oil (litres/month)'></paper-input><br>
<paper-input id='LPG' label='LPG (litres/month)'></paper-input></p>
</div>
<div id="food" class="tab-pane fade">
<p class="ParameterDescription">
<!-- SubContent for each tab -->
<paper-input id='Beef' placeholder='Amount of Beef (kg/month)'></paper-input><br>
<paper-input id='Chicken' placeholder='Chicken (kg/month)'></paper-input><br>
<paper-input id='Dairy' placeholder='Dairy (kg/month)'></paper-input><br>
<paper-input id='Veggies' placeholder='Veggies (kg/month)'></paper-input><br>
<paper-input id='Fruits' placeholder='Fruits (kg/month)'></paper-input><br>
<paper-input id='Grains' placeholder='Grains (kg/month)'></paper-input></p>
</div>
<paper-button raised class="custom green" id="submitButton"> Add</paper-button>
<paper-button raised id="clickMe" class="custom score" type="button" value="score"> Get Score</paper-button>
</div>
</div>
<!-- Right Side Panel -->
<div id="OutputBox">
<div id="upperwrapper">
<div id="top-title"><h3>Water</h3></div>
<div id="InputVisualization"></div>
<div id="overview"></div>
</div>
<div id='bottomwrapper'>
<div id="bottom-title">
<h3>E Score</h3>
</div>
<div id="legenddiv">
<ul>
<li><span class="Water" style="background-color: black;"></span> Water</li>
<li><span class="Waste" style="background-color: orange;"></span>Waste</li>
<li><span class="Fuel" style="background-color: green;"></span> Fuel</li>
<li><span class="Electricity" style="background-color: blue;"></span>Electricity</li>
<li><span class="Food" style="background-color: red;"></span> Food</li>
</ul>
</div>
<div id="OverallVisualization"></div>
</div>
</div>
<script>
var firebasepath = "https://ecaura.firebaseIO.com"
//console.log("Starting request")
var myDataRef = new Firebase(firebasepath);
//console.log("Connected")
// Set the dimensions of the canvas / graph
// Parse the date / time
var parseDate = d3.time.format("%Y %B").parse;
var fields = ["WaterReservoir", "GroundWater", "DesalinatedWater", "RecycledWater", "Nuclear", "Solar", "Wind", "HydroElectric",
"FossilFuels", "Plastic", "Paper", "Glass", "Metal", "Landfill", "NaturalGas", "FuelOil", "LPG", "Beef", "Chicken", "Dairy", "Veggies", "Fruits", "Grains"]
//console.log("About to create listener")
function clear_fields(fields) {
for (i in fields) {
//console.log($("#" + fields[i]))
$("#" + fields[i]).val('');
}
}
function get_current_tab() {
current_graph = $(".iron-selected").attr("href");
current_graph = current_graph.substring(1, current_graph.length);
return current_graph;
}
function make_recommendations() {
recommendations = "If you used " + Math.floor(Math.random() * 50) + " percent less electricity, you would save" + Math.floor(Math.random() * 1000000) + "AED. Your score puts you " + Math.floor(Math.random() * 25) + 5 + "percent better than the industry average."
return recommendations
}
function update_graphs() {
var str = get_current_tab();
str = str.toLowerCase().replace(/\b[a-z]/g, function(letter) {
return letter.toUpperCase();
});
$("#top-title h3").html(str);
current_graph = $(".iron-selected").attr("href")
current_graph = current_graph.substring(1, current_graph.length);
//console.log(current_graph)
////console.log($(".iron-selected").value);
//console.log("Change found.")
//get_feature(firebasepath, "electricity")
//console.log(d3.select("svg"))
//d3.select('svg').remove();
//d3.select('svg').remove();
//console.log(d3.select("svg"))
var x1 = get_org(firebasepath, "nyuad")
//console.log(x1)
data = x1[current_graph]
//console.log(data)
if (data) {
d3.selectAll("#InputVisualization > *").remove();
add_series_to_svg(data, parseDate, "#InputVisualization");
}
var averages = get_score(firebasepath, "nyuad")
d3.selectAll("#OverallVisualization > *").remove();
add_many_series_to_svg(averages, parseDate, "#OverallVisualization")
// render overview graph
var feature = get_current_tab()
var average_data = get_average_series(firebasepath, feature);
var org_feature = get_org_feature(firebasepath, 'nyuad', feature );
d3.selectAll("#overview > *").remove();
append_2col_svg(org_feature, average_data, '#overview', 'nyuad', feature);
}
$('#predictionsDiv').html(make_recommendations())
myDataRef.on('value', function(snapshot) {
update_graphs()
// current_graph = $(".iron-selected").attr("href")
// current_graph = current_graph.substring(1, current_graph.length);
// //console.log(current_graph)
// ////console.log($(".iron-selected").value);
// //console.log("Change found.")
// //get_feature(firebasepath, "electricity")
// //console.log(d3.select("svg"))
// //d3.select('svg').remove();
// //d3.select('svg').remove();
// //console.log(d3.select("svg"))
// var x1 = get_org(firebasepath, "nyuad")
// //console.log(x1)
// data = x1[current_graph]
// //console.log(data)
// if (data) {
// d3.selectAll("#InputVisualization > *").remove();
// add_series_to_svg(data, parseDate, "#InputVisualization");
// }
// var averages = get_score(firebasepath, "nyuad")
// d3.selectAll("#OverallVisualization > *").remove();
// add_many_series_to_svg(averages, parseDate, "#OverallVisualization")
});
$('#submitButton').on('click', function () {
d3.select("svg").remove();
var name = "nyuad"
var month = $('#monthInput').val();
var year = $('#yearInput').val();
var water_ones = ["WaterReservoir", "GroundWater", "DesalinatedWater", "RecycledWater"]
var electricity_ones = ["Nuclear", "Solar", "Wind", "HydroElectric", "FossilFuels"]
var waste_ones = ["Plastic", "Paper", "Glass", "Metal", "Landfill"]
var fuel_ones = ["NaturalGas", "FuelOil", "LPG"]
var food_ones = ["Beef", "Chicken", "Dairy", "Veggies", "Fruits", "Grains"]
water_total = 0
electricity_total = 0
waste_total = 0
fuel_total = 0
food_total = 0
var newdate = year + " " + month;
//console.log("Starting the pushes")
for (i in water_ones) {
feature = water_ones[i]
var val = $("#" + feature).val();
if (val > 0) {
d3.select("svg").remove();
set_date(firebasepath, name, feature, newdate, {date: newdate, value:val});
}
water_total = water_total + parseInt(val);
$("#" + feature).val('');
}
if (water_total > 0) {
//console.log("Added some waters")
d3.select("svg").remove();
set_date(firebasepath, name, "water", newdate, {date: newdate, value:water_total} )
clear_fields(water_ones)
}
for (i in electricity_ones) {
feature = electricity_ones[i]
////console.log("#" + feature)
var val = $("#" + feature).val();
if (val > 0) {
d3.select("svg").remove();
set_date(firebasepath, name, feature, newdate, {date: newdate, value:val});
}
electricity_total = electricity_total + parseInt(val);
$("#" + feature).val('');
}
if (electricity_total > 0) {
//console.log("Added some electricity")
d3.select("svg").remove();
set_date(firebasepath, name, "electricity", newdate, {date: newdate, value:electricity_total} )
clear_fields(electricity_ones)
}
for (i in waste_ones) {
feature = waste_ones[i]
var val = $("#" + feature).val();
if (val > 0) {
d3.select("svg").remove();
set_date(firebasepath, name, feature, newdate, {date: newdate, value:val});
}
waste_total = waste_total + parseInt(val);
$("#" + feature).val('');
}
if (waste_total > 0) {
//console.log("Added some wastes")
d3.select("svg").remove();
set_date(firebasepath, name, "waste", newdate, {date: newdate, value:waste_total} )
clear_fields(waste_ones)
}
for (i in fuel_ones) {
feature = fuel_ones[i]
var val = $("#" + feature).val();
if (val > 0) {
d3.select("svg").remove();
set_date(firebasepath, name, feature, newdate, {date: newdate, value:val});
}
fuel_total = fuel_total + parseInt(val);
$("#" + feature).val('');
}
if (fuel_total > 0) {
d3.select("svg").remove();
//console.log("Added some fuels")
set_date(firebasepath, name, "fuel", newdate, {date: newdate, value:fuel_total} )
clear_fields(fuel_ones)
}
for (i in food_ones) {
feature = food_ones[i]
var val = $("#" + feature).val();
if (val > 0) {
d3.select("svg").remove();
set_date(firebasepath, name, feature, newdate, {date: newdate, value:val});
}
food_total = food_total + parseInt(val);
$("#" + feature).val('');
}
if (food_total > 0) {
d3.select("svg").remove();
//console.log("Added some electricity")
set_date(firebasepath, name, "food", newdate, {date: newdate, value:food_total} )
clear_fields(food_ones)
}
//console.log("Done with the pushes")
d3.selectAll("#OverallVisualization > *").remove();
var averages = get_score(firebasepath, name)
add_many_series_to_svg(averages, parseDate, "#OverallVisualization")
});
$('#papertabs').on('click', function() {
//console.log("Tab was clicked!");
for (i in fields) {
////console.log($("#" + fields[i]))
$("#" + fields[i]).val('');
}
update_graphs()
});
function displayChatMessage(name, text) {
$('<div/>').text(text).prepend($('<em/>').text(name+': ')).appendTo($('#messagesDiv'));
$('#messagesDiv')[0].scrollTop = $('#messagesDiv')[0].scrollHeight;
};
</script>
</body>
</html>