/**
* TODO:命令行下获取文件总记录数*
* @param string $date
* @param int $appid
* @param string $op
* @return array
*/
public function total_lineFile($date, $appid, $op)
{
$this->_openFile($date, $appid, $op);
$file = escapeshellarg($this->_getFile($date, $appid, $op)); // 对命令行参数进行安全转义
$line = `wc -l $file`;
if(preg_match("/(\d{1,})/", $line , $ret)){
$data['count']=$ret[1];
}else{
$data['count']=0;
}
$data['diffTime'] = doubleval(microtime(true)) - doubleval($this->startTime);
$data['memory'] = doubleval((doubleval(memory_get_usage(true)) - doubleval(self::$startMemory))/1024/1024) . ' M';
return $data;
}
/**
* TODO:统计{$data}.{$op}.log记录数
* @param string $date
* @param int $appid
* @param string $op
* @param array $condition
* @return array
*/
public function countFile($date , $appid , $op ,$condition=array())
{
$data['count'] = 0;
$hander = self::_openFile($date , $appid , $op );
if($hander)
{
while (!feof($hander))
{
$tmp = fgets($hander , $this->length);
$tmp = self::_parseData($tmp);
if(empty($tmp)) continue;
if($condition && is_array($condition) )
{
foreach ($condition as $key=>$val){
if(isset($tmp['data'][$key]) && $tmp['data'][$key] && in_array($tmp['data'][$key], $condition[$key])){
unset($key , $val);
$data['count']++;
}
}
}
else
$data['count']++;
unset($tmp);
}
fseek($hander , SEEK_END);
}
$data['diffTime'] = doubleval(microtime(true)) - doubleval($this->startTime);
$data['memory'] = doubleval((doubleval(memory_get_usage(true)) - doubleval(self::$startMemory))/1024/1024) . ' M';
return $data;
}
/**
* TODO:统计用户数
* @param string $date
* @param int $appid
* @param string $op
* @param bool $midflag :默认为false 则 mid返回空数组;如设为true,则mid数组不为空
* * @param bool $jsonFlag:默认为true, 则保留jsondata字段;设为false,则去掉jsondata字段
* @param array $condition
* @return : array:形如({"mid":[],"count":2181,"diffTime":0.0397667884827,"memory":"3.75 M"})
*/
public function countFileMID($date , $appid , $op , $midflag=false , $jsonFlag=false, $condition=array())
{
$count = self::total_lineFile($date , $appid , $op );
$index = ceil($count['count'] / $this->limit);
$result = array('mid'=>array() , 'count'=>0 , 'diffTime'=>0 , 'memory'=>0);