-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathviewandcompare.php
365 lines (311 loc) · 20.8 KB
/
viewandcompare.php
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
<?php
/*
* This file is part of enviroCar.
*
* enviroCar is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* enviroCar is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with enviroCar. If not, see <http://www.gnu.org/licenses/>.
*/
include('header.php');
?>
<div id="loadingIndicator" class="loadingIndicator">
<div style="background:url(./assets/img/ajax-loader.gif) no-repeat center center; height:100px;"></div>
</div>
<div class="container leftband">
<div class="span5 offset6">
<div class="btn-group" style="float:right">
<button class="btn dropdown-toggle" data-toggle="dropdown" style="width:250px"><strong><? echo $pickfriends ?></strong> <span class="caret"></span>
</button>
<ul id="friendsDropdown" class="dropdown-menu" style=" max-height: 300px; width:200px; overflow-y: scroll;">
</ul>
</div>
</div>
</div>
<div class="container rightband">
<div class="span5">
<div id="userStatistics" style="max-height:400px; overflow:auto;">
<p style="font-size:25px"><? echo $statisticsOf ?> <? echo $_SESSION['name'] ?>:</p>
</div>
</div>
<div class="span5" >
<div id ="friendStatistics" style="font-size:25px"> </div>
<p id="friendHeadline" style="font-size:25px"></p>
<div id="loadingIndicator_friend_statistics" style="background:url(./assets/img/ajax-loader.gif) no-repeat center center; height:100px; display:none"></div>
<div id="fStatistics"></div>
</div>
</div>
<div class="container leftband">
<div id="chart_div" style="width: 900px; height: 500px;">
<div id="loadingIndicator_graph" style="background:url(./assets/img/ajax-loader.gif) no-repeat center center; height:100px; display:none"></div>
</div>
</div>
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript">
var values = []; // user statistical data
var values2 = []; // friend statistical data
var fname;
var count=0; // count of statsical values according to the user
var phen=[]; //global phenomenon names
//Display the user Statistics.. Append the statistics values, icons, tooltips.... if any statistical value equal to Zero, do not display 0 display '<strong>Not Calculated</strong>'
//fetch the statiscial values from the server
$.get('assets/includes/users.php?userStatistics=<? echo $_SESSION['name'] ?>', function(data) {
if(data >= 400){
error_msg("<? echo $statisticsError ?>");
$('#loadingIndicator').hide();
}else{
data = JSON.parse(data);
count=data.statistics.length;
for(i = 0; i < data.statistics.length; i++){
if (data.statistics[i].phenomenon.name=="Speed")
{
if(Math.round(data.statistics[i].avg*100)/100==0)
$('#userStatistics').append('<p data-toggle="tooltip" data-placement="left" title="Average Driving Speed"><img style="height: 30px; width: 30px; padding-right:15px " src="./assets/img/Speed.png"/>'+data.statistics[i].phenomenon.name+': '+'<strong>Not Calculated</strong>'+'</p>');
else
$('#userStatistics').append('<p data-toggle="tooltip" data-placement="left" title="Average Driving Speed"><img style="height: 30px; width: 30px; padding-right:15px " src="./assets/img/Speed.png"/>'+data.statistics[i].phenomenon.name+': '+Math.round(data.statistics[i].avg*100)/100+" "+data.statistics[i].phenomenon.unit+'</p>');
}
else if (data.statistics[i].phenomenon.name=="CO2")
{
if(Math.round(data.statistics[i].avg*100)/100==0)
$('#userStatistics').append('<p data-toggle="tooltip" data-placement="left" title="CO2 Emission"><img style="height: 30px; width: 30px; padding-right:15px " src="./assets/img/CO2.png"/>'+data.statistics[i].phenomenon.name+': '+'<strong>Not Calculated</strong>'+'</p>');
else
$('#userStatistics').append('<p data-toggle="tooltip" data-placement="left" title="CO2 Emission"><img style="height: 30px; width: 30px; padding-right:15px " src="./assets/img/CO2.png"/>'+data.statistics[i].phenomenon.name+': '+Math.round(data.statistics[i].avg*100)/100+" "+data.statistics[i].phenomenon.unit+'</p>');
}
else if (data.statistics[i].phenomenon.name=="MAF")
{
if(Math.round(data.statistics[i].avg*100)/100==0)
$('#userStatistics').append('<p data-toggle="tooltip" data-placement="left" title="Mass Air Flow"><img style="height: 30px; width: 30px; padding-right:15px " src="./assets/img/MAF.png"/>'+data.statistics[i].phenomenon.name+': '+'<strong>Not Calculated</strong>'+'</p>');
else
$('#userStatistics').append('<p data-toggle="tooltip" data-placement="left" title="Mass Air Flow"><img style="height: 30px; width: 30px; padding-right:15px " src="./assets/img/MAF.png"/>'+data.statistics[i].phenomenon.name+': '+Math.round(data.statistics[i].avg*100)/100+" "+data.statistics[i].phenomenon.unit+'</p>');
}
else if (data.statistics[i].phenomenon.name=="Calculated MAF")
{
if(Math.round(data.statistics[i].avg*100)/100==0)
$('#userStatistics').append('<p data-toggle="tooltip" data-placement="left" title="Calculated Mass Air Flow"><img style="height: 30px; width: 30px; padding-right:15px " src="./assets/img/Calculated MAF.png"/>'+data.statistics[i].phenomenon.name+': '+'<strong>Not Calculated</strong>'+'</p>');
else
$('#userStatistics').append('<p data-toggle="tooltip" data-placement="left" title="Calculated Mass Air Flow"><img style="height: 30px; width: 30px; padding-right:15px " src="./assets/img/Calculated MAF.png"/>'+data.statistics[i].phenomenon.name+': '+Math.round(data.statistics[i].avg*100)/100+" "+data.statistics[i].phenomenon.unit+'</p>');
}
else if (data.statistics[i].phenomenon.name=="Intake Temperature")
{
if(Math.round(data.statistics[i].avg*100)/100==0)
$('#userStatistics').append('<p data-toggle="tooltip" data-placement="left" title="Intake Air Temperature"><img style="height: 30px; width: 30px; padding-right:15px " src="./assets/img/Intake Temperature.png"/>'+data.statistics[i].phenomenon.name+': '+'<strong>Not Calculated</strong>'+'</p>');
else
$('#userStatistics').append('<p data-toggle="tooltip" data-placement="left" title="Intake Air Temperature"><img style="height: 30px; width: 30px; padding-right:15px " src="./assets/img/Intake Temperature.png"/>'+data.statistics[i].phenomenon.name+': '+Math.round(data.statistics[i].avg*100)/100+" "+data.statistics[i].phenomenon.unit+'</p>');
}
else if (data.statistics[i].phenomenon.name=="Intake Pressure")
{
if(Math.round(data.statistics[i].avg*100)/100==0)
$('#userStatistics').append('<p data-toggle="tooltip" data-placement="left" title="Intake Air Pressure"> <img style="height: 30px; width: 30px; padding-right:15px " src="./assets/img/Intake Pressure.png"/>'+data.statistics[i].phenomenon.name+': '+'<strong>Not Calculated</strong>'+'</p>');
else
$('#userStatistics').append('<p data-toggle="tooltip" data-placement="left" title="Intake Air Pressure"> <img style="height: 30px; width: 30px; padding-right:15px " src="./assets/img/Intake Pressure.png"/>'+data.statistics[i].phenomenon.name+': '+Math.round(data.statistics[i].avg*100)/100+" "+data.statistics[i].phenomenon.unit+'</p>');
}
else if (data.statistics[i].phenomenon.name=="Consumption")
{
if(Math.round(data.statistics[i].avg*100)/100==0)
$('#userStatistics').append('<p data-toggle="tooltip" data-placement="left" title="Average Gasoline Consumption"><img style="height: 30px; width: 30px; padding-right:15px " src="./assets/img/Consumption.png"/>'+data.statistics[i].phenomenon.name+': '+'<strong>Not Calculated</strong>'+'</p>');
else
$('#userStatistics').append('<p data-toggle="tooltip" data-placement="left" title="Average Gasoline Consumption"><img style="height: 30px; width: 30px; padding-right:15px " src="./assets/img/Consumption.png"/>'+data.statistics[i].phenomenon.name+': '+Math.round(data.statistics[i].avg*100)/100+" "+data.statistics[i].phenomenon.unit+'</p>');
}
else if (data.statistics[i].phenomenon.name=="Rpm")
{
if(Math.round(data.statistics[i].avg*100)/100==0)
$('#userStatistics').append('<p data-toggle="tooltip" data-placement="left" title="Revolutions Per Minute"><img style="height: 30px; width: 30px; padding-right:15px " src="./assets/img/Rpm.png"/>'+data.statistics[i].phenomenon.name+': '+'<strong>Not Calculated</strong>'+'</p>');
else
$('#userStatistics').append('<p data-toggle="tooltip" data-placement="left" title="Revolutions Per Minute"><img style="height: 30px; width: 30px; padding-right:15px " src="./assets/img/Rpm.png"/>'+data.statistics[i].phenomenon.name+': '+Math.round(data.statistics[i].avg*100)/100+" "+data.statistics[i].phenomenon.unit+'</p>');
}
else
{
if(Math.round(data.statistics[i].avg*100)/100==0)
$('#userStatistics').append('<p><img style="height: 30px; width: 30px; padding-right:15px " src="./assets/img/others.png"/>'+data.statistics[i].phenomenon.name+': '+'<strong>Not Calculated</strong>'+'</p>');
else
$('#userStatistics').append('<p><img style="height: 30px; width: 30px; padding-right:15px " src="./assets/img/others.png"/>'+data.statistics[i].phenomenon.name+': '+Math.round(data.statistics[i].avg*100)/100+" "+data.statistics[i].phenomenon.unit+'</p>');
}
values[i]= Math.round(data.statistics[i].avg*100)/100;
phen[i]=data.statistics[i].phenomenon.name;
$('#loadingIndicator').hide();
}
}
});
google.load("visualization", "1", {packages:["corechart"]});
function convertToLocalTime(serverDate) {
var dt = new Date(Date.parse(serverDate));
var localDate = dt;
var gmt = localDate;
var min = gmt.getTime() / 1000 / 60; // convert gmt date to minutes
var localNow = new Date().getTimezoneOffset(); // get the timezone
// offset in minutes
var localTime = min - localNow; // get the local time
var dateStr = new Date(localTime * 1000 * 60);
var d = dateStr.getDate();
var m = dateStr.getMonth() + 1;
var y = dateStr.getFullYear();
var totalSec = dateStr.getTime() / 1000;
var hours = parseInt( totalSec / 3600 ) % 24;
var minutes = parseInt( totalSec / 60 ) % 60;
return '' + y + '-' + (m<=9 ? '0' + m : m) + '-' + (d <= 9 ? '0' + d : d) + ' ' + hours +':'+ minutes;
}
function getAvatar(name){
return './assets/includes/get.php?redirectUrl=https://envirocar.org/api/stable/users/'+name+'/avatar&auth=true';
}
//Display the friend Statistics.. Append the statistics values, icons, tooltips.... if any statistical value equal to Zero, do not display 0 display '<strong>Not Calculated</strong>'
//fetch the statiscial values from the server
function getFriendStatistics(friend){
$('#loadingIndicator_graph').show();
$('#loadingIndicator_friend_statistics').show();
fname = friend;
$.get('assets/includes/users.php?friendStatistics='+friend, function(data) {
if(data >= 400){
if(data == 401 || data == 403) error_msg(friend+" <? echo $noFriendsYet ?>.");
else error_msg("<? echo $statisticsNotFound ?>");
}else{
$('#fStatistics').text("");
data = JSON.parse(data);
if(data.length)
for (h=0; h<count; h++ ){
values2[h]=0;
}
$('#friendHeadline').html("<? echo $statisticsOf ?> "+friend+":");
for(i = 0; i < data.statistics.length; i++){
if (data.statistics[i].phenomenon.name=="Speed")
{
if(Math.round(data.statistics[i].avg*100)/100==0)
$('#fStatistics').append('<p data-toggle="tooltip" data-placement="left" title="Average Driving Speed"> <img style="height: 30px; width: 30px; padding-right:15px " src="./assets/img/Speed.png"/>'+data.statistics[i].phenomenon.name+': '+'<strong>Not Calculated</strong>'+'</p>');
else
$('#fStatistics').append('<p data-toggle="tooltip" data-placement="left" title="Average Driving Speed"> <img style="height: 30px; width: 30px; padding-right:15px " src="./assets/img/Speed.png"/>'+data.statistics[i].phenomenon.name+': '+Math.round(data.statistics[i].avg*100)/100+" "+data.statistics[i].phenomenon.unit+'</p>');
}
else if (data.statistics[i].phenomenon.name=="CO2")
{
if(Math.round(data.statistics[i].avg*100)/100==0)
$('#fStatistics').append('<p data-toggle="tooltip" data-placement="left" title="CO2 Emission"> <img style="height: 30px; width: 30px; padding-right:15px " src="./assets/img/CO2.png"/>'+data.statistics[i].phenomenon.name+': '+'<strong>Not Calculated</strong>'+'</p>');
else
$('#fStatistics').append('<p data-toggle="tooltip" data-placement="left" title="CO2 Emission"> <img style="height: 30px; width: 30px; padding-right:15px " src="./assets/img/CO2.png"/>'+data.statistics[i].phenomenon.name+': '+Math.round(data.statistics[i].avg*100)/100+" "+data.statistics[i].phenomenon.unit+'</p>');
}
else if (data.statistics[i].phenomenon.name=="MAF")
{
if(Math.round(data.statistics[i].avg*100)/100==0)
$('#fStatistics').append('<p data-toggle="tooltip" data-placement="left" title="Mass Air Flow"> <img style="height: 30px; width: 30px; padding-right:15px " src="./assets/img/MAF.png"/>'+data.statistics[i].phenomenon.name+': '+'<strong>Not Calculated</strong>'+'</p>');
else
$('#fStatistics').append('<p data-toggle="tooltip" data-placement="left" title="Mass Air Flow"> <img style="height: 30px; width: 30px; padding-right:15px " src="./assets/img/MAF.png"/>'+data.statistics[i].phenomenon.name+': '+Math.round(data.statistics[i].avg*100)/100+" "+data.statistics[i].phenomenon.unit+'</p>');
}
else if (data.statistics[i].phenomenon.name=="Calculated MAF")
{
if(Math.round(data.statistics[i].avg*100)/100==0)
$('#fStatistics').append('<p data-toggle="tooltip" data-placement="left" title="Calculated Mass Air Flow"> <img style="height: 30px; width: 30px; padding-right:15px " src="./assets/img/Calculated MAF.png"/>'+data.statistics[i].phenomenon.name+': '+'<strong>Not Calculated</strong>'+'</p>');
else
$('#fStatistics').append('<p data-toggle="tooltip" data-placement="left" title="Calculated Mass Air Flow"> <img style="height: 30px; width: 30px; padding-right:15px " src="./assets/img/Calculated MAF.png"/>'+data.statistics[i].phenomenon.name+': '+Math.round(data.statistics[i].avg*100)/100+" "+data.statistics[i].phenomenon.unit+'</p>');
}
else if (data.statistics[i].phenomenon.name=="Intake Temperature")
{
if(Math.round(data.statistics[i].avg*100)/100==0)
$('#fStatistics').append('<p data-toggle="tooltip" data-placement="left" title="Intake Air Temperature"> <img style="height: 30px; width: 30px; padding-right:15px " src="./assets/img/Intake Temperature.png"/>'+data.statistics[i].phenomenon.name+': '+'<strong>Not Calculated</strong>'+'</p>');
else
$('#fStatistics').append('<p data-toggle="tooltip" data-placement="left" title="Intake Air Temperature"> <img style="height: 30px; width: 30px; padding-right:15px " src="./assets/img/Intake Temperature.png"/>'+data.statistics[i].phenomenon.name+': '+Math.round(data.statistics[i].avg*100)/100+" "+data.statistics[i].phenomenon.unit+'</p>');
}
else if (data.statistics[i].phenomenon.name=="Intake Pressure")
{
if(Math.round(data.statistics[i].avg*100)/100==0)
$('#fStatistics').append('<p data-toggle="tooltip" data-placement="left" title="Intake Air Pressure"> <img style="height: 30px; width: 30px; padding-right:15px " src="./assets/img/Intake Pressure.png"/>'+data.statistics[i].phenomenon.name+': '+'<strong>Not Calculated</strong>'+'</p>');
else
$('#fStatistics').append('<p data-toggle="tooltip" data-placement="left" title="Intake Air Pressure"> <img style="height: 30px; width: 30px; padding-right:15px " src="./assets/img/Intake Pressure.png"/>'+data.statistics[i].phenomenon.name+': '+Math.round(data.statistics[i].avg*100)/100+" "+data.statistics[i].phenomenon.unit+'</p>');
}
else if (data.statistics[i].phenomenon.name=="Consumption")
{
if(Math.round(data.statistics[i].avg*100)/100==0)
$('#fStatistics').append('<p data-toggle="tooltip" data-placement="left" title="Aerage Gasoline Consumption"> <img style="height: 30px; width: 30px; padding-right:15px " src="./assets/img/Consumption.png"/>'+data.statistics[i].phenomenon.name+': '+'<strong>Not Calculated</strong>'+'</p>');
else
$('#fStatistics').append('<p data-toggle="tooltip" data-placement="left" title="Aerage Gasoline Consumption"> <img style="height: 30px; width: 30px; padding-right:15px " src="./assets/img/Consumption.png"/>'+data.statistics[i].phenomenon.name+': '+Math.round(data.statistics[i].avg*100)/100+" "+data.statistics[i].phenomenon.unit+'</p>');
}
else if (data.statistics[i].phenomenon.name=="Rpm")
{
if(Math.round(data.statistics[i].avg*100)/100==0)
$('#fStatistics').append('<p data-toggle="tooltip" data-placement="left" title="Revolutions Per Minute"><img style="height: 30px; width: 30px; padding-right:15px " src="./assets/img/Rpm.png"/>'+data.statistics[i].phenomenon.name+': '+'<strong>Not Calculated</strong>'+'</p>');
else
$('#fStatistics').append('<p data-toggle="tooltip" data-placement="left" title="Revolutions Per Minute"><img style="height: 30px; width: 30px; padding-right:15px " src="./assets/img/Rpm.png"/>'+data.statistics[i].phenomenon.name+': '+Math.round(data.statistics[i].avg*100)/100+" "+data.statistics[i].phenomenon.unit+'</p>');
}
else
{
if(Math.round(data.statistics[i].avg*100)/100==0)
$('#fStatistics').append('<p"> <img style="height: 30px; width: 30px; padding-right:15px " src="./assets/img/others.png"/>'+data.statistics[i].phenomenon.name+': '+'<strong>Not Calculated</strong>'+'</p>');
else
$('#fStatistics').append('<p"> <img style="height: 30px; width: 30px; padding-right:15px " src="./assets/img/others.png"/>'+data.statistics[i].phenomenon.name+': '+Math.round(data.statistics[i].avg*100)/100+" "+data.statistics[i].phenomenon.unit+'</p>');
}
//insert the friend statistics values with referance to user statistics
for (j=0; j<count; j++ )
{
if ((data.statistics[i].phenomenon.name)==phen[j]){
values2[j]= Math.round(data.statistics[i].avg*100)/100;
break;
}
}
}
if(data.statistics.length==0){
$('#fStatistics').text(friend+" <? echo $noDataYet ?>");
values2 = [0,0,0,0];
}
google.setOnLoadCallback(drawChart());
}
$('#loadingIndicator_graph').hide();
$('#loadingIndicator_friend_statistics').hide();
});
}
$.get('./assets/includes/users.php?friendsOf=<? echo $_SESSION['name'] ?>', function(data) {
if(data >= 400){
error_msg("<? echo $friendsError ?>");
}else{
data = JSON.parse(data);
if(data.users.length > 0 ){
for(i = 0; i < data.users.length; i++){
$('#friendsDropdown').append('<li class="customLi" onclick="getFriendStatistics(\''+data.users[i].name+'\')"><img src="'+getAvatar(data.users[i].name)+'" style="height: 30px; margin-right: 10px; "/><a style="display:inline;">'+data.users[i].name+'</a></li>');
}
}
}
});
(function(){
var s = window.location.search.substring(1).split('&');
if(!s.length) return;
var c = {};
for(var i = 0; i < s.length; i++) {
var parts = s[i].split('=');
c[unescape(parts[0])] = unescape(parts[1]);
}
window.$_GET = function(name){return name ? c[name] : c;}
}())
//chart drawing
function drawChart()
{
var data = new google.visualization.DataTable();
data.addColumn('string','Measurement'); //y-axis values
data.addColumn('number', '<? echo $_SESSION['name'] ?>'); //user chart seriese
data.addColumn('number', fname); // friend chart seriese
data.addRows(count);
for(i = 0; i < count; i++)
{
if(phen[i] == 'Rpm') //Rpm values are very big comparing with other values, so adjust the value on the chart by dividing 100
{
phen[i] = phen[i]+' (100/min)';
values[i] = values[i]/100;
values2[i] = values2[i]/100;
}
data.setValue(i, 0, phen[i]);
data.setValue(i, 1, values[i]);
data.setValue(i, 2, values2[i]);
}
var options = {
title: '<? echo $statistics ?>',
vAxis: {title: '', titleTextStyle: {color: 'red'}}
};
var chart = new google.visualization.BarChart(document.getElementById('chart_div'));
chart.draw(data, options);
};
</script>
<?
include('footer.php');
?>