From 118f706440cb507c029a2875eac6e514eb431a55 Mon Sep 17 00:00:00 2001 From: zhengyongxing Date: Thu, 21 Nov 2019 10:54:15 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E8=84=9A=E6=9C=AC=E5=8E=BB=E9=99=A4?= =?UTF-8?q?=E9=83=A8=E5=88=86=E8=BE=93=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Application/Admin/Controller/TimingController.class.php | 4 ---- 1 file changed, 4 deletions(-) diff --git a/Application/Admin/Controller/TimingController.class.php b/Application/Admin/Controller/TimingController.class.php index 4fef0fa9c..92158ccb7 100644 --- a/Application/Admin/Controller/TimingController.class.php +++ b/Application/Admin/Controller/TimingController.class.php @@ -81,14 +81,10 @@ class TimingController extends AdminController { echo $data['active_device'].' '; $data['time'] = $startTime; $data['version'] = 2; - echo 0; $data['today_new_device'] =json_encode($this->news_on_time(['create_time'=>['between',[$startTime,$startTime+86399]]],'news',5,'time,version','time',2)); // echo M('device_record','tab_')->_sql();die(); - echo 1; $data['today_active_device'] =json_encode($this->active_on_time(['create_time'=>['between',[$startTime,$startTime+86399]],'version'=>2],'active',5,'time,version')); - echo 2; $data['today_model_device'] = json_encode($this->model(['create_time'=>['between',[$startTime,$startTime+86399]],'version'=>2])); - echo 3; $data['model'] = json_encode($this->modelDevice(['create_time'=>['between',[$startTime,$startTime+86399]],'version'=>2])); From 08b2ba432a69821ec53795245759dcc8f73edba0 Mon Sep 17 00:00:00 2001 From: zhengyongxing Date: Thu, 21 Nov 2019 15:09:23 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E7=BB=9F=E8=AE=A1=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Admin/Controller/StatController.class.php | 43 ++++++++++++++- .../Controller/TimingController.class.php | 53 ++++++++++++++++++- 2 files changed, 93 insertions(+), 3 deletions(-) diff --git a/Application/Admin/Controller/StatController.class.php b/Application/Admin/Controller/StatController.class.php index 46d416787..196aea1f8 100644 --- a/Application/Admin/Controller/StatController.class.php +++ b/Application/Admin/Controller/StatController.class.php @@ -1384,10 +1384,14 @@ class StatController extends ThinkController $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])]); } 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); } 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); } else if ($type == 5) { $return = second_to_duration(($model->where(['time'=>$todaystart])->sum('duration7'))); @@ -1397,7 +1401,35 @@ class StatController extends ThinkController $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 开始时间 @@ -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)); diff --git a/Application/Admin/Controller/TimingController.class.php b/Application/Admin/Controller/TimingController.class.php index 92158ccb7..473541f30 100644 --- a/Application/Admin/Controller/TimingController.class.php +++ b/Application/Admin/Controller/TimingController.class.php @@ -91,7 +91,7 @@ class TimingController extends AdminController { // $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'] = 0; - echo 4; + $getStatistics = M('device_statistics','tab_')->where(['time'=>$startTime,'version'=>2])->find(); echo "\n"; if (!$getStatistics) { @@ -100,6 +100,57 @@ class TimingController extends AdminController { 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); + } }