colly_wyx
2018-04-28 4b9bdbdab8d33a9197e12cac65477018e8bdc20e
优化了平均值
1 files modified
22 ■■■■ changed files
Yfs/Domain/DataDaily.php 22 ●●●● patch | view | raw | blame | history
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;
    }