# 学习统计功能 #
## 阅读练习量, 答题量, 答题情况的统计代码
*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)
- 说明
- 开发任务
- 星课-真光
- 课表
- Excel Down
- 调课
- 课表修改
- 课表代码分析
- 课堂
- 课堂:应用商店通信管理协议
- 教师账号强制绑定手机或邮箱
- 强制绑定手机和修改密码的规则
- 学堂
- 课程学习:讨论功能
- 后台:课程讨论管理
- 课程直播接口
- 学习统计功能(旧版)
- 学习统计功能(新版)
- 同步课程统计功能
- 同步课程编辑-新增视频
- 第三方接口
- 学科网
- 安徽第三方
- 大赛
- 管控系统
- 日志管理
- 设备日志
- 平板接口
- 渝教
- 教学总结
- 空白目录
- Yii 1.1
- 学堂架构
- Yii 1.1一些方法的解读
- MVCS结构
- 基础使用语法
- 创建1个新模块
- 关联模型
- CDbCriteria
- 学生-课堂记录
- 学生端页面展示
- 教师端页面展示
- 编辑课程文档
- SQL
- 课堂项目运行入口
- 上传资源示意图
- 行为
- PHPStorm
- 源码阅读
- 会诊答卷页面
- 考点练习
- 资源首页
- 同步课程
- 同步课程:章节信息
- 升学复习
- 统计图-范例
- 模块
- 非法词
- 服务层
- MongoDB类
- 学堂作答记录从Mongo新集合获取数据
- MongoYii
- 错题集
- 小技巧
- 完善资料
- 邮件发送
- K12
- JSpang视频课程
- MongoDB
- 创业
- 项目
- 包包