|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 获取用户某个时间段内的平均值 | 
|---|
|  |  |  | * @param  [type] $user_id    [description] | 
|---|
|  |  |  | * @param  [type] $start_time [description] | 
|---|
|  |  |  | * @param  [type] $end_time   [description] | 
|---|
|  |  |  | * @return [type]             [description] | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | 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( | 
|---|
|  |  |  | array( | 
|---|
|  |  |  | array( | 
|---|
|  |  |  | '$match' => array('date' => array('$gte' => $start_time, '$lte' => $end_time), 'user_id' => $user_id) | 
|---|
|  |  |  | ), | 
|---|
|  |  |  | array( | 
|---|
|  |  |  | '$group' => array('_id' => '$user_id', 'avg' => array('$avg' => '$day_avg')) | 
|---|
|  |  |  | ), | 
|---|
|  |  |  | array( | 
|---|
|  |  |  | '$project' => array('_id' => 0, 'avg' => 1) | 
|---|
|  |  |  | ) | 
|---|
|  |  |  | ) | 
|---|
|  |  |  | ); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return $result[0]['avg']; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 验证时间 | 
|---|
|  |  |  | * @param  [type] $start_time [description] | 
|---|
|  |  |  | * @param  [type] $end_time   [description] | 
|---|