-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstats.php
252 lines (201 loc) · 5.38 KB
/
stats.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
<?php
function mobiloud_charts()
{
global $ml_api_key, $ml_secret_key, $ml_server_host;
mobiloud_display_charts();
}
function mobiloud_display_charts()
{
global $ml_api_key, $ml_secret_key;
$parameters = array(
'api_key' => $ml_api_key,
'secret_key' => $ml_secret_key
);
//SUBSCRIPTIONS
$request = new WP_Http;
$ml_host = "https://api.mobiloud.com";
$url_subscriptions = "$ml_host/product/stats/devices/count";
$result_subscriptions = $request->request( $url_subscriptions,
array('method' => 'POST', 'timeout' => 10,'body' => $parameters));
if($result_subscriptions)
{
$json_subscriptions = $result_subscriptions['body'];
}
//MODELS
$request = new WP_Http;
$url_models = "$ml_host/product/stats/devices/models";
$result_models = $request->request( $url_models,
array('method' => 'POST', 'timeout' => 10,'body' => $parameters));
if($result_models)
{
$json_models = $result_models['body'];
}
//SESSIONS
$request = new WP_Http;
$url_sessions = "$ml_host/product/stats/events/sessions";
$result_sessions = $request->request( $url_sessions,
array('method' => 'POST', 'timeout' => 10,'body' => $parameters));
if($result_sessions)
{
$json_sessions = $result_sessions['body'];
}
?>
<script type="text/javascript" src="<?php echo $ml_host;?>/assets/highcharts.js"></script>
<div id="mobiloud_analytics_title" style="margin-top:20px;">
<h1>Mobiloud Analytics</h1>
<div style="clear:both;">
</div>
<table width="100%">
<tr>
<td align="center">
<div id="mobiloud_subscriptions_chart" style="width: 400px; height: 400px;margin-top:50px;margin-left:50px;"></div>
</td>
<td align="center">
<div id="mobiloud_sessions_chart" style="width: 400px; height: 400px;margin-top:50px;margin-left:50px;"></div>
</td>
</tr>
<tr>
<td align="center" colspan=2>
<div id="mobiloud_models_chart" style="width: 700px; height: 400px;margin-top:50px;"></div>
</td>
</tr>
</table>
<script type="text/javascript">
jQuery(document).ready(function(){
var today = new Date();
var oneday = 24 * 3600 * 1000;
var start_date = today - oneday*7;
var end_date = today;
var result_subscriptions = <?php echo $json_subscriptions; ?>;
var result_sessions = <?php echo $json_sessions; ?>;
//dates
var x_values = [];
//DEVICE SUBSCRIPTIONS
var y_devices_subscriptions = [];
var avg_subs = 0.0;
//DEVICE USING APP PER DAY
var y_sessions = [];
//filling the dates
for(loopTime = start_date; loopTime <= end_date; loopTime += oneday)
{
var d = new Date(loopTime);
var day = d.getDate();
var oday = day;
var month = d.getMonth()+1;
var omonth = month;
var year = d.getUTCFullYear();
if(oday < 10) oday = "0"+oday;
if(omonth < 10) omonth = "0"+omonth;
x_values.push(day + "/" + month);
var key = year + "-" + omonth + "-" + oday;
//DEVICES SUBSCRIPTIONS
var v = result_subscriptions[key];
if(!v) v = 0;
y_devices_subscriptions.push(v);
//DEVICE SESSIONS
var v = result_sessions[key];
if(!v) v = 0;
y_sessions.push(v);
}
//MODELS
var result_models = <?php echo $json_models; ?>;
var models = result_models['models'];
var models_data = new Array();
for(var k in models)
{
var model = new Array();
model.push(k);
model.push(models[k]);
models_data.push(model);
}
subscriptions_chart = new Highcharts.Chart({
chart: {
renderTo: 'mobiloud_subscriptions_chart',
},
legend: {
enabled: false
},
title: {
text: 'New App Installs'
},
xAxis: {
categories: x_values
},
yAxis: {
title: {text: "Devices"},
min: 0,
allowDecimals: false,
minRange: 5
},
series: [{
name: 'Devices',
type: 'column',
data: y_devices_subscriptions
}]
});
models_chart = new Highcharts.Chart({
chart: {
renderTo: 'mobiloud_models_chart',
type: 'pie',
backgroundColor: 'rgba(255,255,255,0)'
},
plotOptions: {
pie: {
allowPointSelect: true,
cursor: 'pointer',
dataLabels: {
enabled: true,
color: '#000000',
connectorColor: '#000000',
formatter: function() {
return '<b>'+ this.point.name +'</b><br/>'+ Math.round(this.percentage) +' %';
}
}
}
},
tooltip: {
formatter: function() {
return '<b>'+ this.point.name +'</b>'+ Math.round(this.percentage) +' %';
}
},
legend: {
enabled: false
},
title: {
text: "Models"
},
series: [{
name: 'Models',
data: models_data
}]
});
sessions_chart = new Highcharts.Chart({
chart: {
renderTo: 'mobiloud_sessions_chart',
type: 'column'
},
legend: {
enabled: false
},
title: {
text: 'Sessions'
},
xAxis: {
categories: x_values
},
yAxis: {
title: {text: "Devices"},
min: 0,
allowDecimals: false,
minRange: 5
},
series: [{
name: 'Unique devices',
data: y_sessions
}]
});
});
</script>
<?php
}
?>