合规国际互联网加速 OSASE为企业客户提供高速稳定SD-WAN国际加速解决方案。 广告
# 学习统计功能 # ## 阅读练习量, 答题量, 答题情况的统计代码 *D:\wamp\www\xue.test\xuetang\protected\modules\croom\controllers\ManageController.php* ``` /** * 学生作答统计 * @author wuzhc 2018-08-13 */ public function actionGetStudentsAnswerStat() { $end = RequestUtils::getNormalRequest('end'); $begin = RequestUtils::getNormalRequest('begin'); $groupID = RequestUtils::getNormalRequest('groupID', 0); $studentIDs = array(); if ($groupID) { // 小组学生 /** @var wkxtGroup $group */ $group = wkxtGroup::model()->findByPk($groupID); if (!$group || ($group->fdUserID != Yii::app()->user->id) || ($group->fdStatus == 1)) { ResponseUtils::json(null, 1, '小组不存在或已删除'); } $students = wkxtGroupRecord::model()->findAll('fdGroupID=:gid', [':gid'=>$groupID]); if ($students) { $studentIDs = array_map(function($s){return $s->fdUserID;}, $students); } } else { // 所有学生 $recommends = wkeRecommend::model()->findAll('fdreferrerID=:uid',array('uid'=>Yii::app()->user->id)); if ($recommends) { $studentIDs = array_map(function($r){return $r->fdUserID;}, $recommends); } } if (empty($studentIDs)) { ResponseUtils::json(array('data' => [])); } // 练习记录 $examRecords = V2StatisticsService::factory()->getUsersExamRecordStat([ 'end' => $end, 'begin' => $begin, 'uid' => $studentIDs, ]); // 过滤没有答题的学生,减少mongo查询 $availableUIDs = []; foreach ($examRecords as $uid => $record) { if ($record['total']) { $availableUIDs[] = $uid; } } // 答题记录 $exerRecords = []; if ($availableUIDs) { $exerRecords = V2StatisticsService::factory()->getUsersExerRecordStat([ 'end' => $end, 'begin' => $begin, 'uid' => $availableUIDs, ]); } $data = array(); $sortColumn = array(); $users = User::model()->findAllByPk($studentIDs); /** @var User $user */ foreach ($users as $user) { $examRecordNum = isset($examRecords[$user->id]) ? $examRecords[$user->id]['total'] : 0; $exerRecordNum = isset($exerRecords[$user->id]) ? $exerRecords[$user->id]['total'] : 0; $examScoreRate = isset($examRecords[$user->id]) ? round($examRecords[$user->id]['rate'], 1) : 0; $temp = array(); $temp['userID'] = (int)$user->id; $temp['nickName'] = V2UserService::factory()->getShowName($user, 'xuetang'); $temp['realName'] = $user->fdRealName?:"-"; $temp['examRecordNum'] = (int)$examRecordNum; $temp['exerRecordNum'] = (int)$exerRecordNum; $temp['exerScoreRate'] = $examScoreRate; // 改为试卷平均得分率 @link https://tower.im/teams/46865/todos/30318/ $sortColumn[] = (int)$exerRecordNum; $data[] = $temp; } array_multisort($sortColumn, SORT_DESC, $data); ResponseUtils::json(array('data' => $data)); } ``` ## 学习统计:掌握考点情况数据统计 ### 01 ![](./img/M/01.png) ### 02 ![](./img/M/02.png) ### 03 http://t.wmxuetang.com/index.php?r=croom/manage/myExerTagStatistics&begin=1548086400000&end=1550678399999&userID=474598 ``` SELECT id,fdScore,fdExamID FROM `wkwke`.`tbAnswerExam` `t` WHERE ((fdCreate > '2019-01-22') AND (fdCreate < '2019-02-21')) AND (fdUserID=474598) ORDER BY id desc ``` ![](./img/M/03.png) ### 04 13次练习,135条练习记录 ``` SELECT DISTINCT fdExerciseID FROM `tbAnswerExercise` WHERE fdAnswerExamID IN (2553098,2550460,2549690,2549478,2549378,2549331,2547714,2537550,2534888,2534871,2534860,2534109,2484237); SELECT fdExerciseID FROM `tbAnswerExercise` WHERE fdAnswerExamID IN (2553098,2550460,2549690,2549478,2549378,2549331,2547714,2537550,2534888,2534871,2534860,2534109,2484237) ORDER BY fdExerciseID; ``` 其中有101行关联了试题ID,练习81题(部分题目重复练习)。 ![](./img/M/04.png) ### 05 关联知识点 ``` SELECT fdTagID, fdExerciseID FROM `tbTagExerForCroom` WHERE fdExerciseID IN (851,851,862,881,894,894,909,1008,1009,1027,14059,14076,14135,14141,14142,19079,24026,24026,141815,141827,141828,149871,150691,151176,855866,855957,862323,887691,887692,887693,887694,887695,887696,887697,912144,968334,1073367,1483617,1483618,1483619,1483620,1483621,1483622,1483623,1483624,1483625,1483626,1483627,1483628,1483629,1483630,1483631,1483631,1483632,1483632,1483633,1483633,1483634,1483634,1483635,1483635,1483635,1483636,1483636,1483637,1483638,1483638,1483639,1483640,1483641,1483641,1483642,1483642,1483737,1483738,1483739,1483740,1483741,1483742,1483743,1483744,1483745,1483746,1483747,1483748,1483753,1483753,1483754,1483754,1483755,1483755,1483756,1483756,1483756,1483757,1483757,1483757,1483862,1483863,1483864,1483865); ``` 29 条关联了考点ID; 22个正确关联;7个关联了0。 备注:注意 `tbTagExerForCroom.fdAppID` 应用ID。查询时会出现2条记录。 ![](./img/M/05.png)