-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdateVerticalDaily.php
53 lines (42 loc) · 1.25 KB
/
updateVerticalDaily.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
<?php
require dirname(__FILE__) . '/Time.php';
$date = strtotime("-1 day", Util_Time::getToday());
$stat_start = strtotime("2009-02-27 00:00:00");
while ($date >= $stat_start) {
if (Db::findOne('analytics.vertical.day', array('date' => new MongoDate($date)))) {
// we've got the stats we need
return;
}
$verticals = Util_Site::getVerticals(false, false, true);
$totals = array_combine(
array_map_attribute($verticals, 'name'),
array_fill(0, count($verticals), 0)
);
// main vertical
$totals[null] = 0;
// killed verticals
$totals['other'] = 0;
$five_min = Db::find('analytics.vertical.fivemin', array(
'date' => array(
'$gte' => new MongoDate($date),
'$lt' => new MongoDate(strtotime("+1 day", $date))
)
));
foreach ($five_min as $stat) {
$vertical = $stat[$this->_searchFieldName];
$vertical = $this->convertVerticalAlias($vertical);
if (!isset($totals[$vertical]))
$totals['other'] += $stat['n'];
else
$totals[$vertical] += $stat['n'];
}
foreach ($totals as $k => $v) {
Db::save('analytics.vertical.day', array(
'date' => new MongoDate($date),
'vertical' => $k,
'n' => $v
));
}
$date = strtotime("-1 day", $date);
}
?>