<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                企業??AI智能體構建引擎,智能編排和調試,一鍵部署,支持知識庫和私有化部署方案 廣告
                # MongoYii # ## 文檔 官方文檔:http://sammaye.github.io/MongoYii/ github:https://github.com/Sammaye/MongoYii ## 安裝 *D:\wamp\www\xue.test\xuetang\protected\config\common.php* ``` define("MONGO_HOST","10.8.8.14"); define("MONGO_PORT","27017"); define("MONGO_DB","weike"); define("MONGO_USER","mch"); define("MONGO_PWD","mch"); ... 'components'=>array( 'mongodb' => array( 'class' => 'EMongoClient', 'server' => 'mongodb://'.MONGO_HOST.':'.MONGO_PORT, 'db' => MONGO_DB, 'options' => array( 'connect' => true , //'username' => MONGO_USER, // 'password' => MONGO_PWD , ) ), ), ... 'import'=>array( ... 'application.extensions.MongoYii.*', 'application.extensions.MongoYii.validators.*', 'application.extensions.MongoYii.behaviors.*', 'application.extensions.MongoYii.util.*' , 'application.models.mongo.*', ... ), ``` ## 統計代碼示例 聚合管道文檔參考:http://www.mongoing.com/docs/aggregation.html *D:\wamp\www\xue.test\xuetang\protected\service\service2\V2StatisticsService.php* ``` /** * 統計每個用戶類型登錄數據 * @param array $args * @return array * @author wuzhc 2018-08-06 */ public function statLoginEachUserType($args) { /** @var EMongoClient $mongodb */ $mongodb = Yii::app()->mongodb; $collection = $mongodb->selectCollection(WK::XT_LOGIN_LOG); $res = $collection->aggregate(array( array( '$match' => array( 'date' => array( '$gte' => $args['begin'], '$lte' => $args['end'] ) ) ), array( '$group' => array( '_id' => '$userType', 'total' => array( '$sum' => 1 ) ) ), array( '$project' => array( '_id' => 0, 'userType' => '$_id', 'total' => '$total' ) ) )); return isset($res['result']) ? $res['result'] : array(); } /** * 統計每個地區登錄數據 * @param array $args * @return array * @author wuzhc 2018-08-06 */ public function statLoginEachArea($args) { if ($args['areaID']) { /** @var Area $area */ $area = Area::model()->findByPk($args['areaID']); $level = $area->fdLevel; } else { $level = 0; } /** @var EMongoClient $mongodb */ $mongodb = Yii::app()->mongodb; $collection = $mongodb->selectCollection(WK::XT_LOGIN_LOG); $match['date'] = array('$gte' => $args['begin'], '$lte' => $args['end']); if ($level == 1) { $match['provinceID'] = (int)$args['areaID']; } elseif ($level == 2) { $match['cityID'] = (int)$args['areaID']; } $match['userType'] = array(WK::TEACHER_TYPE_ID, WK::STUDENT_TYPE_ID, WK::PARENT_TYPE_ID); $res = $collection->aggregate(array( array( '$match' => $match ), array( '$group' => array( '_id' => array( 'areaID' => $level == 0 ? '$provinceID' : ($level == 1 ? '$cityID' : '$regionID'), 'userType' => '$userType' ), 'total' => array( '$sum' => 1 ) ) ), array( '$project' => array( '_id' => 0, 'total' => '$total', 'areaID' => '$_id.areaID', 'userType' => '$_id.userType', ) ) )); return isset($res['result']) ? $res['result'] : array(); } /** * 統計每天登錄數據 * @param array $args * @return array * @author wuzhc 2018-08-06 */ public function statLoginEachDay($args) { /** @var EMongoClient $mongodb */ $mongodb = Yii::app()->mongodb; $collection = $mongodb->selectCollection(WK::XT_LOGIN_LOG); $res = $collection->aggregate(array( array( '$match' => array( 'date' => array( '$gte' => $args['begin'], '$lte' => $args['end'] ) ) ), array( '$group' => array( '_id' => array( 'day' => '$day', 'userType' => '$userType' ), 'total' => array( '$sum' => 1 ) ) ), array( '$project' => array( '_id' => 0, 'userType' => '$_id.userType', 'day' => '$_id.day', 'total' => '$total' ) ) )); $data = array(); $records = isset($res['result']) ? $res['result'] : array(); foreach ($records as $r) { $day = $r['day']; if (!$day) { continue; } if (!isset($data[$day])) { $data[$day]['total'] = 0; $data[$day]['day'] = $day; $data[$day]['data'] = array(); } $data[$day]['total'] += $r['total']; $data[$day]['data'][] = array( 'total' => $r['total'], 'userType' => $r['userType'], ); } return $data; } /** * 統計每個用戶類型注冊數據 * @return array * @author wuzhc 2018-08-06 */ public function statRegisterEachUserType($args) { /** @var EMongoClient $mongodb */ $mongodb = Yii::app()->mongodb; $collection = $mongodb->selectCollection(WK::XT_REGISTER_LOG); $res = $collection->aggregate(array( array( '$match' => array( 'date' => array( '$gte' => $args['begin'], '$lte' => $args['end'] ) ) ), array( '$group' => array( '_id' => '$userType', 'total' => array( '$sum' => 1 ) ) ), array( '$project' => array( '_id' => 0, 'userType' => '$_id', 'total' => '$total' ) ) )); return isset($res['result']) ? $res['result'] : array(); } /** * 統計每個地區注冊數據 * @return array * @author wuzhc 2018-08-06 */ public function statRegisterEachArea($args) { if ($args['areaID']) { /** @var Area $area */ $area = Area::model()->findByPk($args['areaID']); $level = $area->fdLevel; } else { $level = 0; } /** @var EMongoClient $mongodb */ $mongodb = Yii::app()->mongodb; $collection = $mongodb->selectCollection(WK::XT_REGISTER_LOG); $match['date'] = array('$gte' => $args['begin'], '$lte' => $args['end']); if ($level == 1) { $match['provinceID'] = (int)$args['areaID']; } elseif ($level == 2) { $match['cityID'] = (int)$args['areaID']; } $res = $collection->aggregate(array( array( '$match' => $match ), array( '$group' => array( '_id' => array( 'areaID' => $level == 0 ? '$provinceID' : ($level == 1 ? '$cityID' : '$regionID'), 'userType' => '$userType' ), 'total' => array( '$sum' => 1 ) ) ), array( '$project' => array( '_id' => 0, 'total' => '$total', 'areaID' => '$_id.areaID', 'userType' => '$_id.userType', ) ) )); return isset($res['result']) ? $res['result'] : array(); } /** * 統計每天注冊數據 * @return array * @author wuzhc 2018-08-06 */ public function statRegisterEachDay($args) { /** @var EMongoClient $mongodb */ $mongodb = Yii::app()->mongodb; $collection = $mongodb->selectCollection(WK::XT_REGISTER_LOG); $res = $collection->aggregate(array( array( '$match' => array( 'date' => array( '$gte' => $args['begin'], '$lte' => $args['end'] ) ) ), array( '$group' => array( '_id' => array( 'day' => '$day', 'userType' => '$userType' ), 'total' => array( '$sum' => 1 ) ) ), array( '$project' => array( '_id' => 0, 'day' => '$_id.day', 'total' => '$total', 'userType' => '$_id.userType' ) ) )); $data = array(); $records = isset($res['result']) ? $res['result'] : array(); foreach ($records as $r) { $day = $r['day']; if (!$day) { continue; } if (!isset($data[$day])) { $data[$day]['total'] = 0; $data[$day]['day'] = $day; $data[$day]['data'] = array(); } $data[$day]['total'] += $r['total']; $data[$day]['data'][] = array( 'total' => $r['total'], 'userType' => $r['userType'], ); } return $data; } /** * 用戶答卷記錄統計 * @param $args * @return array */ public function getUsersExamRecordStat($args) { /** @var EMongoClient $mongo */ $mongo = Yii::app()->mongodb; $collection = $mongo->selectCollection(WK::XT_EXAM_RECORD_COLLECTION); // 參數 if (!is_array($args['uid'])) { $args['uid'] = (array)$args['uid']; } if ($args['uid']) { array_walk($args['uid'], function(&$uid){$uid = (int)$uid;}); } $args['begin'] = $args['begin'] ? new MongoDate($args['begin']/1000+8*60*60) : new MongoDate(strtotime('-1 year')); $args['end'] = $args['end'] ? new MongoDate($args['end']/1000+8*60*60) : new MongoDate(time()+8*60*60); $res = $collection->aggregate(array( array( '$match' => array( 'uid' => array('$in' => $args['uid']), 'end' => array( '$gte' => $args['begin'], '$lte' => $args['end'] ) ) ), array( '$group' => array( '_id' => array('uid' => '$uid'), 'total' => array('$sum' => 1), 'rate' => array('$avg' => '$score_rate'), ) ), array( '$project' => array( 'rate' => '$rate', 'total' => '$total', 'uid' => '$_id.uid', '_id' => 0 ) ) )); $map = array(); if ($res['result']) { foreach ($res['result'] as $r) { $map[$r['uid']] = $r; } } return $map; } /** * 獲取用戶答題情況統計 * @param $args * @return array */ public function getUsersExerRecordStat($args) { /** @var EMongoClient $mongo */ $mongo = Yii::app()->mongodb; $collection = $mongo->selectCollection(WK::XT_EXER_RECORD_COLLECTION); // 參數 if (!is_array($args['uid'])) { $args['uid'] = (array)$args['uid']; } if ($args['uid']) { array_walk($args['uid'], function(&$uid){$uid = (int)$uid;}); } $args['begin'] = $args['begin'] ? new MongoDate($args['begin']/1000+8*60*60) : new MongoDate(strtotime('-1 year')); $args['end'] = $args['end'] ? new MongoDate($args['end']/1000+8*60*60) : new MongoDate(time()+8*60*60); $res = $collection->aggregate(array( array( '$match' => array( 'uid' => array('$in' => $args['uid']), 'date' => array( '$gte' => $args['begin'], '$lte' => $args['end'] ) ) ), array( '$group' => array( '_id' => array('uid' => '$uid'), 'total' => array('$sum' => 1), ) ), array( '$project' => array( 'total' => '$total', 'uid' => '$_id.uid', '_id' => 0 ) ) )); $map = array(); if ($res['result']) { foreach ($res['result'] as $r) { $map[$r['uid']] = $r; } } return $map; } /** * 統計每天答題場景數據 * @param $args * @return array */ public function statSceneAnswerEachDay($args) { /** @var EMongoClient $mongo */ $mongo = Yii::app()->mongodb; $collection = $mongo->selectCollection(WK::XT_EXAM_RECORD_COLLECTION); $res = $collection->aggregate(array( array( '$match' => array( 'date' => array( '$gte' => $args['begin'], '$lte' => $args['end'] ) ) ), array( '$project' => array( 'day' => array( '$dateToString' => array( 'format' => '%Y-%m-%d', 'date' => '$date' )), 'scene' => '$scene' ) ), array( '$group' => array( '_id' => array( 'day' => '$day', 'scene' => '$scene' ), 'total' => array('$sum' => 1) ) ), array( '$project' => array( '_id' => 0, 'day' => '$_id.day', 'sceneID' => '$_id.scene', 'total' => '$total', ) ) )); return (array)$res['result']; } /** * 統計每個學段答題場景數據 * @param $args * @return array */ public function statSceneAnswerEachSchType($args) { /** @var EMongoClient $mongo */ $mongo = Yii::app()->mongodb; $collection = $mongo->selectCollection(WK::XT_EXAM_RECORD_COLLECTION); $res = $collection->aggregate(array( array( '$match' => array( 'date' => array( '$gte' => $args['begin'], '$lte' => $args['end'] ) ) ), array( '$group' => array( '_id' => array( 'schooltype' => '$schooltype', 'scene' => '$scene' ), 'total' => array('$sum' => 1) ) ), array( '$project' => array( '_id' => 0, 'schoolTypeID' => '$_id.schooltype', 'sceneID' => '$_id.scene', 'total' => '$total', ) ) )); return (array)$res['result']; } ```
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看