forked from watussi/watussibox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
analyse.php
executable file
·427 lines (351 loc) · 17.1 KB
/
analyse.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
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
<?php
/* analyse.php
* Première version : 26 novembre 2012
* Dernière modification : 2 décembre 2012
.---------------------------------------------------------------------------.
| Software: WatussiBox Free |
| Version: 0.1 |
| Contact: [email protected] |
| Info: http://www.watussi.fr |
| Support: http://www.watussi.fr |
| ------------------------------------------------------------------------- |
| Author: Jean-Benoît MOINGT |
| ------------------------------------------------------------------------- |
| License: Distributed under the Creative Commons license (BY-NC-SA ) |
| http://creativecommons.org/licenses/by-nc-sa/3.0/ |
| |
| This program is distributed in the hope that it will be useful - WITHOUT |
| ANY WARRANTY. |
| ------------------------------------------------------------------------- |
| Licence: Distribué sous licence Creative Commons (BY-NC-SA) |
| http://creativecommons.org/licenses/by-nc-sa/3.0/fr/ |
| |
| Ce programme est distribué dans l'espoir qu'il sera utile - SANS AUCUNE |
| GARANTIE. |
| ------------------------------------------------------------------------- |
| Nous offrons un certain nombre de services complémentaire : |
| - Versions enrichies en fonctionnalitées |
| - Support |
| - Formation |
| - Conseil |
| - Développements spécifiques |
| --> Contactez-nous : [email protected] |
'---------------------------------------------------------------------------'
*/
set_time_limit(0);
$timestart = microtime(true);
include_once('inc/connect.inc.php');
include_once('inc/fonctions.inc.php');
//login();
echo heure_minute_seconde() . ' - DEBUT' . '<br />';
/*
.---------------------------------------------------------------------------.
| Calcul des KPIs |
'---------------------------------------------------------------------------'
*/
// Nb URLs
echo heure_minute_seconde() . ' - CALCUL NB URLS' . '<br />';
$qry = 'SELECT COUNT(*) AS nb FROM watussi_url';
$res = $dbh->query($qry);
$row = $res->fetch(PDO::FETCH_OBJ);
$nb_urls = $row->nb;
// Nb Crawl / 30 j
echo heure_minute_seconde() . ' - CALCUL NB CRAWL / 30 JOURS' . '<br />';
$qry = 'SELECT COUNT(DISTINCT(url_id)) AS nb FROM watussi_log WHERE type_id = 0 AND watussi_log.date_id IN (SELECT date_id FROM watussi_date WHERE date >= NOW() - INTERVAL 30 DAY);';
$res = $dbh->query($qry);
$row = $res->fetch(PDO::FETCH_OBJ);
$nb_crawl_30j = $row->nb;
// Nb pa / 30 j
echo heure_minute_seconde() . ' - CALCUL NB PA / 30 JOURS' . '<br />';
$qry = 'SELECT COUNT(DISTINCT(url_id)) AS nb FROM watussi_log WHERE type_id = 1 AND watussi_log.date_id IN (SELECT date_id FROM watussi_date WHERE date >= NOW() - INTERVAL 30 DAY);';
$res = $dbh->query($qry);
$row = $res->fetch(PDO::FETCH_OBJ);
$nb_pa_30j = $row->nb;
// Nb nouvelles pages / 30j
echo heure_minute_seconde() . ' - CALCUL NOUVELLES PAGES / 30 JOURS' . '<br />';
$qry = 'SELECT COUNT(*) AS nb FROM watussi_url WHERE first_crawl IN (SELECT date_id FROM watussi_date WHERE date >= NOW() - INTERVAL 30 DAY);';
$res = $dbh->query($qry);
$row = $res->fetch(PDO::FETCH_OBJ);
$nouvelles_pages_30j = $row->nb;
// Temps execution moyen
echo heure_minute_seconde() . ' - CALCUL TEMPS EXECUTION' . '<br />';
$qry = 'SELECT AVG(response_time) AS nb FROM watussi_log WHERE watussi_log.date_id IN (SELECT date_id FROM watussi_date WHERE date >= NOW() - INTERVAL 30 DAY) AND type_id = 0;';
$res = $dbh->query($qry);
$row = $res->fetch(PDO::FETCH_OBJ);
$avg_execution_time = $row->nb;
// ENREGISTREMENT
$qry = "INSERT INTO watussi_kpi(kpi_id, date, nb_urls, nb_crawl_30j, nb_pa_30j, new_pages_30j, avg_execution_time)
VALUES('', NOW(), '$nb_urls', '$nb_crawl_30j', '$nb_pa_30j', '$nouvelles_pages_30j', '$avg_execution_time')";
$dbh->query($qry);
/*
.---------------------------------------------------------------------------.
| EVENEMENT UNIQUE / JOUR |
'---------------------------------------------------------------------------'
*/
echo heure_minute_seconde() . ' - EVENEMENT UNIQUE / JOUR' . '<br />';
$qry = 'TRUNCATE TABLE watussi_tmp_evenement_unique_jour';
$dbh->query($qry);
$qry = 'SELECT date_id FROM watussi_date WHERE date >= NOW() - INTERVAL 90 DAY ORDER BY date;';
$res = $dbh->query($qry);
while($row = $res->fetch(PDO::FETCH_OBJ)){
$date_id = $row->date_id;
$qry = "SELECT COUNT(DISTINCT(url_id)) AS nb, type_id FROM watussi_log WHERE watussi_log.date_id = $date_id GROUP BY type_id";
$res2 = $dbh->query($qry);
while($row2 = $res2->fetch(PDO::FETCH_OBJ)){
$nb = $row2->nb;
$type_id = $row2->type_id;
$qry = "INSERT INTO watussi_tmp_evenement_unique_jour(date_id, nb, type_id) VALUES('$date_id', '$nb', '$type_id')";
$dbh->query($qry);
}
}
/*
.---------------------------------------------------------------------------.
| EVENEMENT / JOUR |
'---------------------------------------------------------------------------'
*/
echo heure_minute_seconde() . ' - EVENEMENT / JOUR' . '<br />';
$qry = 'TRUNCATE TABLE watussi_tmp_evenement_jour';
$dbh->query($qry);
$qry = 'SELECT date_id FROM watussi_date WHERE date >= NOW() - INTERVAL 90 DAY ORDER BY date;';
$res = $dbh->query($qry);
while($row = $res->fetch(PDO::FETCH_OBJ)){
$date_id = $row->date_id;
$qry = "SELECT COUNT(url_id) AS nb, type_id FROM watussi_log WHERE watussi_log.date_id = $date_id GROUP BY type_id";
$res2 = $dbh->query($qry);
while($row2 = $res2->fetch(PDO::FETCH_OBJ)){
$nb = $row2->nb;
$type_id = $row2->type_id;
$qry = "INSERT INTO watussi_tmp_evenement_jour(date_id, nb, type_id) VALUES('$date_id', '$nb', '$type_id')";
$dbh->query($qry);
}
}
/*
.---------------------------------------------------------------------------.
| EVENEMENT UNIQUE / 30 JOURS |
'---------------------------------------------------------------------------'
*/
echo heure_minute_seconde() . ' - EVENEMENT UNIQUE / 30 JOURS' . '<br />';
$qry = 'TRUNCATE TABLE watussi_tmp_evenement_unique_30j';
$dbh->query($qry);
$qry = 'SELECT date_id, date FROM watussi_date WHERE date >= NOW() - INTERVAL 90 DAY ORDER BY date;';
$res = $dbh->query($qry);
while($row = $res->fetch(PDO::FETCH_OBJ)){
$date = $row->date;
$date_id = $row->date_id;
$qry = "SELECT COUNT(DISTINCT(url_id)) AS nb, type_id FROM watussi_log WHERE watussi_log.date_id IN (SELECT date_id FROM watussi_date WHERE date >= '$date' - INTERVAL 30 DAY AND date <= '$date') GROUP BY type_id";
$res2 = $dbh->query($qry);
while($row2 = $res2->fetch(PDO::FETCH_OBJ)){
$nb = $row2->nb;
$type_id = $row2->type_id;
$qry = "INSERT INTO watussi_tmp_evenement_unique_30j(date_id, nb, type_id) VALUES('$date_id', '$nb', '$type_id')";
$dbh->query($qry);
}
}
/*
.---------------------------------------------------------------------------.
| EVENEMENT / 30 JOURS |
'---------------------------------------------------------------------------'
*/
echo heure_minute_seconde() . ' - EVENEMENT / 30 JOURS' . '<br />';
$qry = 'TRUNCATE TABLE watussi_tmp_evenement_30j';
$dbh->query($qry);
$qry = 'SELECT date_id, date FROM watussi_date WHERE date >= NOW() - INTERVAL 90 DAY ORDER BY date;';
$res = $dbh->query($qry);
while($row = $res->fetch(PDO::FETCH_OBJ)){
$date = $row->date;
$date_id = $row->date_id;
$qry = "SELECT COUNT(url_id) AS nb, type_id FROM watussi_log WHERE watussi_log.date_id IN (SELECT date_id FROM watussi_date WHERE date >= '$date' - INTERVAL 30 DAY AND date <= '$date') GROUP BY type_id";
$res2 = $dbh->query($qry);
while($row2 = $res2->fetch(PDO::FETCH_OBJ)){
$nb = $row2->nb;
$type_id = $row2->type_id;
$qry = "INSERT INTO watussi_tmp_evenement_30j(date_id, nb, type_id) VALUES('$date_id', '$nb', '$type_id')";
$dbh->query($qry);
}
}
/*
.---------------------------------------------------------------------------.
| CRAWL GLOBAL / HEURE |
'---------------------------------------------------------------------------'
*/
echo heure_minute_seconde() . ' - EVENEMENT GLOBAL / HEURE' . '<br />';
$qry = 'TRUNCATE TABLE watussi_tmp_evenement_global_heure';
$dbh->query($qry);
$qry = 'SELECT heure, type_id, COUNT(*) AS nb FROM watussi_log WHERE date_id IN (SELECT date_id FROM watussi_date WHERE date >= NOW() - INTERVAL 90 DAY) GROUP BY heure, type_id;';
$res = $dbh->query($qry);
while($row = $res->fetch(PDO::FETCH_OBJ)){
$heure = $row->heure;
$type_id = $row->type_id;
$nb = $row->nb;
$qry = "INSERT INTO watussi_tmp_evenement_global_heure(heure, nb, type_id) VALUES('$heure', '$nb', '$type_id');";
$dbh->query($qry);
}
/*
.---------------------------------------------------------------------------.
| CRAWL / RES CODE |
'---------------------------------------------------------------------------'
*/
echo heure_minute_seconde() . ' - EVENEMENT / RES CODE' . '<br />';
$qry = 'TRUNCATE TABLE watussi_tmp_evenement_res_code';
$dbh->query($qry);
$qry = 'SELECT date_id, type_id, res_code, COUNT(*) AS nb FROM watussi_log WHERE date_id IN (SELECT date_id FROM watussi_date WHERE date >= NOW() - INTERVAL 90 DAY) GROUP BY date_id, type_id, res_code;';
$res = $dbh->query($qry);
while($row = $res->fetch(PDO::FETCH_OBJ)){
$date_id = $row->date_id;
$type_id = $row->type_id;
$res_code = $row->res_code;
$nb = $row->nb;
$qry = "INSERT INTO watussi_tmp_evenement_res_code(date_id, nb, type_id, res_code) VALUES('$date_id', '$nb', '$type_id', '$res_code');";
$dbh->query($qry);
}
/*
.---------------------------------------------------------------------------.
| NOUVELLES PAGES / JOUR |
'---------------------------------------------------------------------------'
*/
echo heure_minute_seconde() . ' - NOUVELLES PAGES / JOUR' . '<br />';
$qry = 'TRUNCATE TABLE watussi_tmp_nouvelles_pages';
$dbh->query($qry);
$qry = 'SELECT first_crawl, COUNT(*) AS nb FROM watussi_url WHERE first_crawl IN (SELECT date_id FROM watussi_date WHERE date >= NOW() - INTERVAL 90 DAY) GROUP BY first_crawl;';
$res = $dbh->query($qry);
while($row = $res->fetch(PDO::FETCH_OBJ)){
$first_crawl = $row->first_crawl;
$nb = $row->nb;
$qry = "INSERT INTO watussi_tmp_nouvelles_pages(date_id, nb) VALUES('$first_crawl', '$nb');";
$dbh->query($qry);
}
/*
.---------------------------------------------------------------------------.
| PAGES ACTIVES / JOUR |
'---------------------------------------------------------------------------'
*/
echo heure_minute_seconde() . ' - PAGES ACTIVES / JOUR' . '<br />';
$qry = 'TRUNCATE TABLE watussi_tmp_pa_jour';
$dbh->query($qry);
$qry = 'SELECT date_id, COUNT(DISTINCT(url_id)) AS nb FROM watussi_log WHERE type_id = 1 AND date_id IN (SELECT date_id FROM watussi_date WHERE date >= NOW() - INTERVAL 90 DAY) GROUP BY date_id;';
$res = $dbh->query($qry);
while($row = $res->fetch(PDO::FETCH_OBJ)){
$date_id = $row->date_id;
$nb = $row->nb;
$qry = "INSERT INTO watussi_tmp_pa_jour(date_id, nb) VALUES('$date_id', '$nb');";
$dbh->query($qry);
}
/*
.---------------------------------------------------------------------------.
| PAGES ACTIVES / 30 JOURS |
'---------------------------------------------------------------------------'
*/
echo heure_minute_seconde() . ' - PAGES ACTIVES / 30 JOURS' . '<br />';
$qry = 'TRUNCATE TABLE watussi_tmp_pa_30j';
$dbh->query($qry);
$qry = 'SELECT date_id, date FROM watussi_date WHERE date >= NOW() - INTERVAL 90 DAY ORDER BY date;';
$res = $dbh->query($qry);
while($row = $res->fetch(PDO::FETCH_OBJ)){
$date_id = $row->date_id;
$date = $row->date;
$qry = "SELECT COUNT(DISTINCT(url_id)) AS nb FROM watussi_log WHERE type_id = 1 AND date_id IN (SELECT date_id FROM watussi_date WHERE date <= '$date' AND date >= '$date' - INTERVAL 30 DAY);";
$res2 = $dbh->query($qry);
while($row2 = $res2->fetch(PDO::FETCH_OBJ)){
$nb = $row2->nb;
$qry = "INSERT INTO watussi_tmp_pa_30j(date_id, nb) VALUES('$date_id', '$nb');";
$dbh->query($qry);
}
}
/*
.---------------------------------------------------------------------------.
| VOLUME ACTIVE / NON ACTIVE |
'---------------------------------------------------------------------------'
*/
echo heure_minute_seconde() . ' - ACTIVE / NON ACTIVE' . '<br />';
$qry = 'TRUNCATE TABLE watussi_tmp_active_nonactive';
$dbh->query($qry);
$qry = 'SELECT active, COUNT(*) AS nb FROM watussi_url GROUP BY active;';
$res = $dbh->query($qry);
$active = $non_active = 0;
while($row = $res->fetch(PDO::FETCH_OBJ)){
$tmp = $row->active;
$nb = $row->nb;
if($tmp == 1){
$active = $nb;
}
else{
$non_active = $nb;
}
}
$qry = "INSERT INTO watussi_tmp_active_nonactive(active, non_active) VALUES('$active', '$non_active');";
$dbh->query($qry);
/*
.---------------------------------------------------------------------------.
| PPC |
'---------------------------------------------------------------------------'
*/
echo heure_minute_seconde() . ' - PPC' . '<br />';
$qry = 'TRUNCATE TABLE watussi_tmp_ppc';
$dbh->query($qry);
$qry = 'SELECT date_id, date FROM watussi_date ORDER BY date;';
$res = $dbh->query($qry);
while($row = $res->fetch(PDO::FETCH_OBJ)){
$date = $row->date;
$date_id = $row->date_id;
$qry = "SELECT COUNT(DISTINCT(url_id)) AS nb FROM watussi_log WHERE date_id IN (SELECT date_id FROM watussi_date WHERE date <= '$date')";
$res2 = $dbh->query($qry);
$row2 = $res2->fetch(PDO::FETCH_OBJ);
$nb = $row2->nb;
$qry = "INSERT INTO watussi_tmp_ppc(date_id, nb) VALUES('$date_id', '$nb');";
$dbh->query($qry);
}
/*
.---------------------------------------------------------------------------.
| TEMPS EXECUTION MOYEN |
'---------------------------------------------------------------------------'
*/
echo heure_minute_seconde() . ' - TEMPS EXECUTION MOYEN' . '<br />';
$qry = 'TRUNCATE TABLE watussi_tmp_response_time';
$dbh->query($qry);
$qry = "SELECT date_id, AVG(response_time) AS response_time FROM watussi_log WHERE type_id = 0 AND date_id IN (SELECT date_id FROM watussi_date WHERE date >= '$date' - INTERVAL 90 DAY) GROUP BY date_id;";
$res = $dbh->query($qry);
while($row = $res->fetch(PDO::FETCH_OBJ)){
$date_id = $row->date_id;
$response_time = $row->response_time;
$qry = "INSERT INTO watussi_tmp_response_time(date_id, response_time) VALUES('$date_id', '$response_time')";
$dbh->query($qry);
}
/*
.---------------------------------------------------------------------------.
| CRAWL UTILE / INUTILE |
'---------------------------------------------------------------------------'
*/
echo heure_minute_seconde() . ' - CRAWL UTILE / INUTILE' . '<br />';
$qry = 'TRUNCATE TABLE watussi_tmp_crawl_utile_inutile';
$dbh->query($qry);
$qry = "SELECT active, date_id, COUNT(*) AS nb FROM watussi_log, watussi_url WHERE type_id = 0 AND watussi_url.url_id = watussi_log.url_id AND date_id IN (SELECT date_id FROM watussi_date WHERE date >= NOW() - INTERVAL 90 DAY) GROUP BY date_id, active;";
$res = $dbh->query($qry);
while($row = $res->fetch(PDO::FETCH_OBJ)){
$utile = $row->active;
$date_id = $row->date_id;
$nb = $row->nb;
$qry = "INSERT INTO watussi_tmp_crawl_utile_inutile(date_id, utile, nb) VALUES('$date_id', '$utile', '$nb');";
$dbh->query($qry);
}
/*
.---------------------------------------------------------------------------.
| REPARTITION LAST RES CODE |
'---------------------------------------------------------------------------'
*/
echo heure_minute_seconde() . ' - REPARTITION DES RES CODE' . '<br />';
$qry = 'TRUNCATE TABLE watussi_tmp_rescode';
$dbh->query($qry);
$qry = 'SELECT last_res_code, COUNT(*) AS nb FROM watussi_url GROUP BY last_res_code;';
$res = $dbh->query($qry);
while($row = $res->fetch(PDO::FETCH_OBJ)){
$nb = $row->nb;
$res_code = $row->last_res_code;
$qry = "INSERT INTO watussi_tmp_rescode(res_code, nb) VALUES('$res_code', '$nb');";
$dbh->query($qry);
}
echo heure_minute_seconde() . ' - FIN' . '<br />';
$timeend = microtime(true);
$time = $timeend - $timestart;
$page_load_time = number_format($time, 3);
echo "<br /><br />Exécuté en " . $page_load_time . " s.";
$dbh = null; ?>