From e4d5467f055ece8cc9dfdc02dd836bcc187034a5 Mon Sep 17 00:00:00 2001 From: colly_wyx <wangyixiong_007@163.com> Date: Wed, 13 Jun 2018 10:15:57 +0800 Subject: [PATCH] 替换铃音 --- Yfs/Domain/DataDaily.php | 27 ++++++++++++++++++++------- 1 files changed, 20 insertions(+), 7 deletions(-) diff --git a/Yfs/Domain/DataDaily.php b/Yfs/Domain/DataDaily.php index 11d97e9..8586c3b 100644 --- a/Yfs/Domain/DataDaily.php +++ b/Yfs/Domain/DataDaily.php @@ -8,6 +8,7 @@ //DI()->redis = new Redis_Lite(DI()->config->get('app.redis.servers')); $this->model = new Model_DataDaily(); $this->data_three_hourly_model = new Model_DataThreeHourly(); + $this->data_hourly_model = new Model_DataHourly(); } /** @@ -56,17 +57,29 @@ */ public function getUserDataAvg($user_id, $start_time, $end_time){ - // if($start_time == $end_time){ - // $result = $this->model->get(array('date' => $start_time)); - // } - // else{ - $result = $this->model->aggregate( + // if($start_time == $end_time){ + // $result = $this->data_hourly_model->get(array('date' => $start_time)); + // if($result){ + // $sum = 0; + // for($i = 1; $i <= 8; $i++){ + // $sum += $result['time_slot_'.$i]; + // } + + // $result[0]['day_avg'] = $sum/8; + // } + // else{ + // $result[0]['day_avg'] = 0; + // } + + // } + // else{ + $result = $this->data_hourly_model->aggregate( array( array( '$match' => array('date' => array('$gte' => $start_time, '$lte' => $end_time), 'user_id' => $user_id) ), array( - '$group' => array('_id' => '$user_id', 'day_avg' => array('$avg' => '$day_avg')) + '$group' => array('_id' => '$user_id', 'day_avg' => array('$avg' => '$value')) ), array( '$project' => array('_id' => 0, 'day_avg' => 1) @@ -75,7 +88,7 @@ ); //} - return isset($result[0]['day_avg'])?$result[0]['day_avg']:0; + return isset($result[0]['day_avg'])?floatval(substr($result[0]['day_avg'], 0, 5)):0; } /** -- Gitblit v1.8.0