123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245 |
- <?php
- namespace Cas\Controller\CmdLine;
- use Cas\Dao\LotteryPvUvLog;
- use KIF\Core\Config;
- use Cas\Dao\LotteryUserParticipateLog;
- /**
- * 分析前一天 /log/Pass_log 访问日志
- *
- * php index.php -cCmdLine_RunLog -aRun
- */
- class RunLog extends Controller {
- public function doDefault() {
- }
-
- /**
- * 跑出前一天的活动的 IP PV UV
- * php /export/manager/v2/v2_cas/www/index.php -cIndex -asetuser
- */
- public function doRun() {
- $objDLotteryPvUvLog = new LotteryPvUvLog ();
-
- # 获取昨天目录下 所有的
- $Y = date('Y',strtotime('-1 day today'));
- $m = date('m',strtotime('-1 day today'));
- $dir =Config::getInstance ()->get ( 'Log_Path' ).DIRECTORY_SEPARATOR.$Y.DIRECTORY_SEPARATOR.$m.DIRECTORY_SEPARATOR;
-
- $list = scandir($dir);
- $thisList = array();
- $name = 'Pass_log_'.date('Y_m_d',strtotime('-1 day today'));
- foreach($list as $data){
- if(strpos($data, $name) !== false){
- $thisList[$data] = $dir.$data;
- }
- }
- $allData = array();
- $eventsArr = array();
- $tmpEventsIp = array();
- $tmpEventsUV = array();
- foreach($thisList as $thisDir){
- $string = file_get_contents($thisDir);
- $d = explode("\n", $string);
- foreach($d as $key=> $s){
- if($s){
- $arr = unserialize($s);
-
- if(isset($eventsArr[$arr['event_id']]['pv'])){
- $eventsArr[$arr['event_id']]['pv'] ++;
- }else{
- $eventsArr[$arr['event_id']]['pv'] = 1;
- }
-
- $tmpEventsIp[$arr['event_id']][$arr['ip']] = $arr['ip'];
-
- $tmpEventsUV[$arr['event_id']][$arr['ip'].$arr['user_agent']] = $arr['ip'].$arr['user_agent'];
-
- $allData[] = $arr;
- }
- }
- }
-
-
-
- # PV
- # IP
- foreach($tmpEventsIp as $events_id => $ips){
- $eventsArr[$events_id]['ip'] = count($ips);
- }
-
- # UV
- foreach($tmpEventsUV as $events_id => $vps){
- $eventsArr[$events_id]['uv'] = count($vps);
- }
- # 用户参与数
- $objLotteryLog = new LotteryUserParticipateLog();
-
- foreach($eventsArr as $events_id => $data){
- $info = array();
- $time = strtotime('-1 day today');
- /*
- $start = $this->maketime(date('Y-m-d 00:00:00', $time));
- $end = $time;
- # 参与人数
- $info ['user_num'] = $objLotteryLog->getUserParticipateLogNumGroupByUidDate ($events_id, $start, $end);
- */
- $info ['events_id'] = $events_id ;
- $info ['pv_num'] = $data['pv'] ;
- $info ['uv_num'] = $data['uv'] ;
- $info ['ip_num'] = $data['ip'] ;
- $info ['date'] = $time;
-
- $objDLotteryPvUvLog->add ( $info ,LotteryPvUvLog::PARAM_CREATE_ACTION_ONDUPLICATE);
-
- }
-
-
-
- }
- /**
- * 跑出今天的 IP PV UV
- * php /export/manager/v2/v2_cas/www/index.php -cIndex -asetuser
- */
- public function doToday() {
- $objDLotteryPvUvLog = new LotteryPvUvLog ();
-
- # 获取今天目录下
- $Y = date('Y');
- $m = date('m');
- $dir =Config::getInstance ()->get ( 'Log_Path' ).DIRECTORY_SEPARATOR.$Y.DIRECTORY_SEPARATOR.$m.DIRECTORY_SEPARATOR;
-
- $list = scandir($dir);
- $thisList = array();
- $name = 'Pass_log_'.date('Y_m_d');
- foreach($list as $data){
- if(strpos($data, $name) !== false){
- $thisList[$data] = $dir.$data;
- }
- }
- $allData = array();
- $eventsArr = array();
- $tmpEventsIp = array();
- $tmpEventsUV = array();
- foreach($thisList as $thisDir){
- $string = file_get_contents($thisDir);
- $d = explode("\n", $string);
- foreach($d as $key=> $s){
- if($s){
- $arr = unserialize($s);
-
- if(isset($eventsArr[$arr['event_id']]['pv'])){
- $eventsArr[$arr['event_id']]['pv'] ++;
- }else{
- $eventsArr[$arr['event_id']]['pv'] = 1;
- }
-
- $tmpEventsIp[$arr['event_id']][$arr['ip']] = $arr['ip'];
-
- $tmpEventsUV[$arr['event_id']][$arr['ip'].$arr['user_agent']] = $arr['ip'].$arr['user_agent'];
-
- $allData[] = $arr;
- }
- }
- }
-
-
-
- # PV
- # IP
- foreach($tmpEventsIp as $events_id => $ips){
- $eventsArr[$events_id]['ip'] = count($ips);
- }
-
- # UV
- foreach($tmpEventsUV as $events_id => $vps){
- $eventsArr[$events_id]['uv'] = count($vps);
- }
- # 用户参与数
- $objLotteryLog = new LotteryUserParticipateLog();
-
- foreach($eventsArr as $events_id => $data){
- $info = array();
- $time = date();
- $start = $this->maketime(date('Y-m-d 00:00:00', $time));
- $end = $time;
- # 参与人数
- $info ['user_num'] = $objLotteryLog->getUserParticipateLogNumGroupByUidDate ($events_id, $start, $end);
- $info ['events_id'] = $events_id ;
- $info ['pv_num'] = $data['pv'] ;
- $info ['uv_num'] = $data['uv'] ;
- $info ['ip_num'] = $data['ip'] ;
- $info ['date'] = $time;
-
- $objDLotteryPvUvLog->add ( $info ,LotteryPvUvLog::PARAM_CREATE_ACTION_ONDUPLICATE);
-
- }
-
-
-
- }
- public function maketime($v)
- {
- if (!$v) {
- return '';
- }
- if (is_numeric($v)) {
- return $v;
- }
- if (is_array($v)) {
- $v = $v[1];
- }
- if (strstr($v, ' ')) {
- $t = explode(' ', $v);
- $v = $t[0];
- $s = explode(':', $t[1]);
- } else {
- $s = array(0, 0, 0);
- }
- if (!isset($s[1])) {
- $s[1] = 0;
- }
- if (!isset($s[2])) {
- $s[2] = 0;
- }
- if (strstr($v, '-')) {
- $t = explode('-', $v);
- } elseif (strstr($v, '/')) {
- $u = explode('/', $v);
- $t[0] = $u[2];
- $t[1] = $u[0];
- $t[2] = $u[1];
- }
- if (!isset($t)) {
- $t = array(0, 0, 0);
- }
- if (!isset($t[1])) {
- $t[1] = 0;
- }
- if (!isset($t[2])) {
- $t[2] = 0;
- }
- $v = mktime($s[0], $s[1], $s[2], $t[1], $t[2], $t[0]);
- return $v;
- }
- }
|