From 4b9bdbdab8d33a9197e12cac65477018e8bdc20e Mon Sep 17 00:00:00 2001
From: colly_wyx <wangyixiong_007@163.com>
Date: Sat, 28 Apr 2018 17:08:52 +0800
Subject: [PATCH] 优化了平均值

---
 Yfs/Domain/DataDaily.php |   22 +++++++++++++++++-----
 1 files changed, 17 insertions(+), 5 deletions(-)

diff --git a/Yfs/Domain/DataDaily.php b/Yfs/Domain/DataDaily.php
index 11d97e9..de8fc57 100644
--- a/Yfs/Domain/DataDaily.php
+++ b/Yfs/Domain/DataDaily.php
@@ -56,10 +56,22 @@
      */
     public function getUserDataAvg($user_id, $start_time, $end_time){
        
-        // if($start_time == $end_time){
-        //     $result = $this->model->get(array('date' => $start_time));
-        // }
-        // else{
+         if($start_time == $end_time){
+             $result = $this->data_three_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->model->aggregate(
                 array(
                     array(
@@ -73,7 +85,7 @@
                     )
                 )   
             );
-        //}
+        }
 
         return isset($result[0]['day_avg'])?$result[0]['day_avg']:0;
     }

--
Gitblit v1.8.0