统计数据修正

master
zhengyongxing 5 years ago
parent 118f706440
commit 08b2ba432a

@ -1384,10 +1384,14 @@ class StatController extends ThinkController
$return = $model->where(['time'=>array('between',[$todaystart-86400,$todaystart-1])])->sum('new_device'); $return = $model->where(['time'=>array('between',[$todaystart-86400,$todaystart-1])])->sum('new_device');
// $return = $device->total_device(['create_time'=>array('between',[$todaystart-86400,$todaystart-1])]); // $return = $device->total_device(['create_time'=>array('between',[$todaystart-86400,$todaystart-1])]);
} else if($type == 3) { } else if($type == 3) {
$return = $model->where(['time'=>array('between',[$todaystart-86400*7,$todaystart-1])])->sum('active_device'); // $return = $model->where(['time'=>array('between',[$todaystart-86400*7,$todaystart-1])])->sum('active_device');
$return = $this->getActiveDeviceNum(['time'=>['between',[$todaystart-86400*7,$todaystart-1]]]);
// $return = $device->total_device(['create_time'=>array('between',[$todaystart-86400*7,$todaystart-1])],1); // $return = $device->total_device(['create_time'=>array('between',[$todaystart-86400*7,$todaystart-1])],1);
} else if($type == 4) { } else if($type == 4) {
$return = $model->where(['time'=>array('between',[$todaystart-86400*30,$todaystart-1])])->sum('active_device'); // $return = $model->where(['time'=>array('between',[$todaystart-86400*30,$todaystart-1])])->sum('active_device');
$return = $this->getActiveDeviceNum(['time'=>array('between',[$todaystart-86400*30,$todaystart-1])]);
// $return = $device->total_device(['create_time'=>array('between',[$todaystart-86400*30,$todaystart-1])],1); // $return = $device->total_device(['create_time'=>array('between',[$todaystart-86400*30,$todaystart-1])],1);
} else if ($type == 5) { } else if ($type == 5) {
$return = second_to_duration(($model->where(['time'=>$todaystart])->sum('duration7'))); $return = second_to_duration(($model->where(['time'=>$todaystart])->sum('duration7')));
@ -1397,7 +1401,35 @@ class StatController extends ThinkController
$this->ajaxReturn($return?$return:0) ; $this->ajaxReturn($return?$return:0) ;
} }
public function getActiveDeviceNum($map) {
$modelData = M('device_statistics','tab_')
->field("model")
->where($map)
->select();
$modelNew = 0;
$unique_code = [];
foreach($modelData as $key => $value) {
$resolveData = json_decode($value['model'],true);
// dump($resolveData);
foreach($resolveData as $k => $v) {
// if (!isset($modelNew[$v['model']][$v['version']])) {
// $modelNew = 1;
// $unique_code[$v['unique_code']] = 1;
// }
// else
if(!$unique_code[$v['unique_code']]){
$modelNew++;
$unique_code[$v['unique_code']] = 1;
// array_push($unique_code,$v['unique_code']);
}
}
}
return $modelNew;
}
/* /*
* 折线图 * 折线图
* @param integer $start 开始时间 * @param integer $start 开始时间
@ -1634,6 +1666,13 @@ class StatController extends ThinkController
} }
} }
if ($start != $end) {
$table['sum']['active'] = $this->getActiveDeviceNum(['time'=>array('between',[$starttime,$endtime])]);
$table['average']['active'] = number_format($table['sum']['active']/(((($endtime+1)-$starttime)/86400)),2,'.','');
// var_dump($endtime-$starttime);die();
}
@file_put_contents(dirname(__FILE__).'/device_data_foldline.txt',json_encode($export)); @file_put_contents(dirname(__FILE__).'/device_data_foldline.txt',json_encode($export));

@ -91,7 +91,7 @@ class TimingController extends AdminController {
// $duration = $this->duration(['create_time'=>array('between',[$startTime-86400*7,$startTime-1]),'version'=>2]); // $duration = $this->duration(['create_time'=>array('between',[$startTime-86400*7,$startTime-1]),'version'=>2]);
// $data['duration7'] = ($duration/M('device_record','tab_')->table('(' . $newSql . ') as a')->where(['create_time'=>array('between',[$startTime-86400*7,$startTime-1])])->order('create_time')->count())/7; // $data['duration7'] = ($duration/M('device_record','tab_')->table('(' . $newSql . ') as a')->where(['create_time'=>array('between',[$startTime-86400*7,$startTime-1])])->order('create_time')->count())/7;
$data['duration7'] = 0; $data['duration7'] = 0;
echo 4;
$getStatistics = M('device_statistics','tab_')->where(['time'=>$startTime,'version'=>2])->find(); $getStatistics = M('device_statistics','tab_')->where(['time'=>$startTime,'version'=>2])->find();
echo "\n"; echo "\n";
if (!$getStatistics) { if (!$getStatistics) {
@ -100,6 +100,57 @@ class TimingController extends AdminController {
M('device_statistics','tab_')->where(['time'=>$startTime,'version'=>2])->save($data); M('device_statistics','tab_')->where(['time'=>$startTime,'version'=>2])->save($data);
} }
}
}
public function caculateTodayDevice() {
$start = 1569686400;
$end = time();
if (I('time')) {
$start = strtotime(I('time'));
$end = $start+1;
}
if (I('start')) {
$start = strtotime(I('start'));
}
ini_set('memory_limit','1024M');
// $device = D('DeviceRecord');
// echo 1;
for($startTime = $start;$startTime<$end;$startTime=$startTime+86400) {
echo date("Y-m-d",$startTime).' 安卓 ';
//当日新增设备
$newSql = M('device_record','tab_')->field('min(create_time) as create_time,model,unique_code,id')->where(['version'=>1])->group('unique_code')->select(false);
$data['new_device'] = M('device_record','tab_')->table('(' . $newSql . ') as a')->where(['create_time'=>array('between',[$startTime,$startTime+86399])])->order('create_time')->count();
echo $data['new_device'].' ';
$getStatistics = M('device_statistics','tab_')->where(['time'=>$startTime,'version'=>1])->find();
echo "\n";
if (!$getStatistics) {
M('device_statistics','tab_')->add($data);
} else {
M('device_statistics','tab_')->where(['time'=>$startTime,'version'=>1])->save($data);
}
echo date("Y-m-d",$startTime).' 苹果 ';
//当日新增设备
$newSql = M('device_record','tab_')->field('min(create_time) as create_time,model,unique_code,id')->where(['version'=>2])->group('unique_code')->select(false);
$data['new_device'] = M('device_record','tab_')->table('(' . $newSql . ') as a')->where(['create_time'=>array('between',[$startTime,$startTime+86399])])->order('create_time')->count();
echo $data['new_device'].' ';
$getStatistics = M('device_statistics','tab_')->where(['time'=>$startTime,'version'=>2])->find();
echo "\n";
if (!$getStatistics) {
M('device_statistics','tab_')->add($data);
} else {
M('device_statistics','tab_')->where(['time'=>$startTime,'version'=>2])->save($data);
}
} }

Loading…
Cancel
Save