You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
57 lines
1.9 KiB
57 lines
1.9 KiB
<?php
|
|
/**
|
|
* 汇总用户行为数据日增量
|
|
* @package crontab
|
|
*/
|
|
|
|
include_once(dirname(dirname(dirname(__FILE__))) . "/library/publicBase.php");
|
|
|
|
class spiderBehaviorDelta {
|
|
public function __construct() {
|
|
//删除半年前的数据
|
|
$obj = new mWeiboBehavior();
|
|
$six_month_ago = date('Y-m-d', strtotime('-6 month'));
|
|
$obj->deleteExpireBehaviorDelta($six_month_ago);
|
|
|
|
//统计今日增量
|
|
$today = date('Y-m-d');
|
|
$today_data = $obj->getBehaviorByDate($today);
|
|
$today_data = array_column($today_data, null, 'wid');
|
|
|
|
$yesterday = date('Y-m-d', strtotime('-1 day'));
|
|
$yesterday_data = $obj->getBehaviorByDate($yesterday);
|
|
$yesterday_data = array_column($yesterday_data, null, 'wid');
|
|
|
|
if (empty($yesterday_data)) return true;
|
|
|
|
foreach ($today_data as $k => $v) {
|
|
$yesterday_reposts_count = 0;
|
|
$yesterday_comments_count = 0;
|
|
$yesterday_attitudes_count = 0;
|
|
|
|
if (isset($yesterday_data[$k])) {
|
|
$yesterday_reposts_count = $yesterday_data[$k]['reposts_count'];
|
|
$yesterday_comments_count = $yesterday_data[$k]['comments_count'];
|
|
$yesterday_attitudes_count = $yesterday_data[$k]['attitudes_count'];
|
|
}
|
|
|
|
$delta = array(
|
|
'uid' => $v['uid'],
|
|
'wid' => $v['wid'],
|
|
'reposts_delta' => $v['reposts_count'] - $yesterday_reposts_count,
|
|
'comments_delta' => $v['comments_count'] - $yesterday_comments_count,
|
|
'attitudes_delta' => $v['attitudes_count'] - $yesterday_attitudes_count,
|
|
'date' => $v['date'],
|
|
);
|
|
|
|
$res = $obj->saveBehaviorDelta($delta);
|
|
if (!$res) {
|
|
$this->writeLog('spider', 'insert_error.log', json_encode($delta));
|
|
}
|
|
}
|
|
|
|
return true;
|
|
}
|
|
}
|
|
|
|
new spiderBehaviorDelta();
|
|
|