-
Notifications
You must be signed in to change notification settings - Fork 4
/
query_data.php
executable file
·281 lines (235 loc) · 7.84 KB
/
query_data.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
<?php
// library for exporting data from DB
/**
* Export browser statistics
* @param int $year year of the required data
* @param int $month month of the required data
* @return array('result_report_query','total_visitor')
*/
function query_browser($year, $month) {
$browser_query = array(
array(
"id" => "Chrome",
"query" => array(
"select" => "CAST(SUBSTRING(browserVersion, 1, LOCATE('.', browserVersion) - 1) AS SIGNED)",
"where" => "browser = 'Chrome'"
)
),
array(
"id" => "Firefox",
"query" => array(
"select" => "CAST(SUBSTRING_INDEX(browserVersion, '.', 2) AS DECIMAL(3,1))",
"where" => "browser = 'Firefox'"
)
),
array(
"id" => "Safari mobile",
"query" => array(
"select" => "operatingSystem",
"where" => "browser = 'Safari' AND CAST(SUBSTRING(browserVersion, 1, LOCATE('.', browserVersion) - 1) AS SIGNED) > 6000"
)
),
array(
"id" => "Safari 3",
"query" => array(
"select" => "3",
"where" => "browser = 'Safari' AND CAST(SUBSTRING(browserVersion, 1, LOCATE('.', browserVersion) - 1) AS DECIMAL(6,2)) < 526"
)
),
array(
"id" => "Safari 4",
"query" => array(
"select" => "4",
"where" => "browser = 'Safari' AND CAST(SUBSTRING(browserVersion, 1, LOCATE('.', browserVersion) - 1) AS DECIMAL(6,2)) BETWEEN 526 AND 532"
)
),
array(
"id" => "Safari 5",
"query" => array(
"select" => "5",
"where" => "browser = 'Safari' AND CAST(SUBSTRING(browserVersion, 1, LOCATE('.', browserVersion) - 1) AS DECIMAL(6,2)) BETWEEN 533 AND 6000"
)
),
array(
"id" => "Everything else",
"query" => array(
"select" => "browserVersion",
"where" => "browser != 'Firefox' AND browser != 'Chrome' AND browser != 'Safari'"
)
)
);
$report_query = "";
for ($i = 0; $i < count($browser_query); $i++) {
if ($i != 0) {
$report_query .= " UNION ";
}
$report_query .= "(SELECT browser, ";
$report_query .= $browser_query[$i]['query']['select'];
$report_query .= " AS ver, SUM(visitors) AS v FROM browsers WHERE ";
$report_query .= $browser_query[$i]['query']['where'];
$report_query .= " AND year = $year AND month = $month GROUP BY browser, ver)";
}
$report_total_query = "SELECT SUM(visitors) AS v FROM browsers WHERE year = $year AND month = $month";
$total_visitor = mysql_fetch_array(mysql_query($report_total_query));
$total_visitor = $total_visitor['v'];
$result_report_query = mysql_query($report_query);
$arr = array();
$c = 0;
while ($row = mysql_fetch_row($result_report_query)) {
foreach ($row as $k => $v) {
$arr[$c][$k] = $v;
}
$arr[$c][$k + 1] = number_format(($v * 100 / $total_visitor), 2);
$c++;
}
return array(
'result_report_query' => $arr,
'total_visitor' => $total_visitor
);
}
/**
* Export os statistics
* @param int $year year of the required data
* @param int $month month of the required data
* @return array('result_report_query','total_visitor')
*/
function query_os($year, $month) {
$report_query = "SELECT operatingSystem, operatingSystemVersion, SUM(visitors) AS v
FROM browsers
WHERE year = $year AND month = $month
GROUP BY year, month, operatingSystem, operatingSystemVersion
ORDER BY v DESC";
$report_total_query = "SELECT SUM(visitors) AS v FROM browsers WHERE year = $year AND month = $month";
$total_visitor = mysql_fetch_array(mysql_query($report_total_query));
$total_visitor = $total_visitor['v'];
$result_report_query = mysql_query($report_query);
$arr = array();
$c = 0;
while ($row = mysql_fetch_row($result_report_query)) {
foreach ($row as $k => $v) {
$arr[$c][$k] = $v;
}
$arr[$c][$k + 1] = number_format(($v * 100 / $total_visitor), 2);
$c++;
}
return array(
'result_report_query' => $arr,
'total_visitor' => $total_visitor
);
}
/**
* Export screen resolutions statistics
* @param int $year year of the required data
* @param int $month month of the required data
* @return array('result_report_query','total_visitor')
*/
function query_screen_res($year, $month) {
$report_query = "SELECT width, height, SUM(visitors) AS v
FROM screens
WHERE year = $year AND month = $month
GROUP BY year, month, width, height
ORDER BY v DESC";
$report_total_query = "SELECT SUM(visitors) AS v FROM screens WHERE year = $year AND month = $month";
$total_visitor = mysql_fetch_array(mysql_query($report_total_query));
$total_visitor = $total_visitor['v'];
$result_report_query = mysql_query($report_query);
$arr = array();
$c = 0;
while ($row = mysql_fetch_row($result_report_query)) {
foreach ($row as $k => $v) {
$arr[$c][$k] = $v;
}
$arr[$c][$k + 1] = number_format(($v * 100 / $total_visitor), 2);
$c++;
}
return array(
'result_report_query' => $arr,
'total_visitor' => $total_visitor
);
}
/**
* Export help pages statistics
* @param int $year year of the required data
* @param int $month month of the required data
* @return array('result_report_query','total_visitor')
*/
function query_help_page($year, $month) {
$report_query = "SELECT REPLACE(pagePath, '/_act/get_page.php?pgName=/help/', ''), visitors AS v, pageviews, CONCAT('=', avgTimeOnPage, '/(60*60*24)')
FROM helppages
WHERE year = $year AND month = $month
GROUP BY year, month, pagePath
ORDER BY v DESC";
$report_total_query = "SELECT SUM(visitors) AS v FROM helppages WHERE year = $year AND month = $month";
$total_visitor = mysql_fetch_array(mysql_query($report_total_query));
$total_visitor = $total_visitor['v'];
$result_report_query = mysql_query($report_query);
$arr = array();
$c = 0;
while ($row = mysql_fetch_row($result_report_query)) {
foreach ($row as $k => $v) {
$arr[$c][$k] = $v;
}
$c++;
}
return array(
'result_report_query' => $arr,
'total_visitor' => $total_visitor
);
}
/**
* Export countries statistics
* @param int $year year of the required data
* @param int $month month of the required data
* @return array('result_report_query','total_visitor')
*/
function query_countries($year, $month) {
$report_query = "SELECT country, visitors AS v
FROM countries
WHERE year = $year AND month = $month
GROUP BY year, month, country
ORDER BY v DESC";
$report_total_query = "SELECT SUM(visitors) AS v FROM countries WHERE year = $year AND month = $month";
$total_visitor = mysql_fetch_array(mysql_query($report_total_query));
$total_visitor = $total_visitor['v'];
$result_report_query = mysql_query($report_query);
$arr = array();
$c = 0;
while ($row = mysql_fetch_row($result_report_query)) {
foreach ($row as $k => $v) {
$arr[$c][$k] = $v;
}
$arr[$c][$k + 1] = number_format(($v * 100 / $total_visitor), 2);
$c++;
}
return array(
'result_report_query' => $arr,
'total_visitor' => $total_visitor
);
}
/**
* Export access times statistics
* @param int $year year of the required data
* @param int $month month of the required data
* @return array('result_report_query','total_visitor')
*/
function query_access_time($year, $month) {
$report_query = "SELECT CONCAT('=CHOOSE(',dayOfWeek + 1, ', \"Sunday\", \"Monday\", \"Tuesday\", \"Wednesday\", \"Thursday\", \"Friday\", \"Saturday\")'), hour, AVG(noext_visitors) AS v, AVG(noext_visits) AS w, CONCAT('=', AVG(noext_avgTimeOnSite), '/(60*60*24)') AS t
FROM accesstimes
WHERE year(date) = $year AND month(date) = $month
GROUP BY hour, dayOfWeek
ORDER BY dayOfWeek, hour";
$result_report_query = mysql_query($report_query);
$arr = array();
$c = 0;
while ($row = mysql_fetch_row($result_report_query)) {
foreach ($row as $k => $v) {
$arr[$c][$k] = $v;
}
$c++;
}
return array(
'result_report_query' => $arr,
'total_visitor' => $total_visitor
);
}
?>