|
|
@@ -2,7 +2,7 @@
|
|
|
|
|
|
/**
|
|
|
* 近 7 天老师组卷 + 学情分析套数(exam_analysis_results 按 paper_id 去重,一套卷计 1)。
|
|
|
- * 按老师:参与学生·组卷 = papers.student_id 去重;参与学生·学情 = exam_analysis_results.student_id 去重(均按本/上周期)。
|
|
|
+ * 按老师:学生数 = 组卷(papers.student_id) ∪ 学情(exam_analysis_results.student_id) 在本/上周期内合并去重;老师列含 teacher_id,如 龚 (433)。
|
|
|
* 用法:
|
|
|
* php scripts/report_teacher_weekly_stats.php
|
|
|
* php scripts/report_teacher_weekly_stats.php > storage/app/reports/teacher-weekly-stats-$(date +%Y-%m-%d)_$(date +%H%M%S).md
|
|
|
@@ -176,65 +176,35 @@ foreach ($analysisByTeacherPrev as $r) {
|
|
|
$analysisMapPrev[(string) $r->teacher_id] = (int) $r->paper_set_count;
|
|
|
}
|
|
|
|
|
|
-/** 组卷参与学生:papers.student_id 在本/上周期内按老师去重 */
|
|
|
-$studentAsmCurRows = $db::table('papers')
|
|
|
- ->whereNotNull('teacher_id')
|
|
|
- ->where('teacher_id', '!=', '')
|
|
|
- ->whereNotNull('student_id')
|
|
|
- ->where('student_id', '!=', '')
|
|
|
- ->where('created_at', '>=', $startCurrent)
|
|
|
- ->groupBy('teacher_id')
|
|
|
- ->selectRaw('teacher_id, COUNT(DISTINCT student_id) AS c')
|
|
|
- ->get();
|
|
|
-$studentAsmPrevRows = $db::table('papers')
|
|
|
- ->whereNotNull('teacher_id')
|
|
|
- ->where('teacher_id', '!=', '')
|
|
|
- ->whereNotNull('student_id')
|
|
|
- ->where('student_id', '!=', '')
|
|
|
- ->where('created_at', '>=', $startPrev)
|
|
|
- ->where('created_at', '<', $endPrev)
|
|
|
- ->groupBy('teacher_id')
|
|
|
- ->selectRaw('teacher_id, COUNT(DISTINCT student_id) AS c')
|
|
|
- ->get();
|
|
|
-
|
|
|
-/** 学情参与学生:exam_analysis_results.student_id 在本/上周期内按 papers.teacher_id 去重 */
|
|
|
-$studentAnalysisCurRows = $db::table('exam_analysis_results as ear')
|
|
|
- ->join('papers as p', 'p.paper_id', '=', 'ear.paper_id')
|
|
|
- ->whereNotNull('p.teacher_id')
|
|
|
- ->where('p.teacher_id', '!=', '')
|
|
|
- ->whereNotNull('ear.student_id')
|
|
|
- ->where('ear.student_id', '!=', '')
|
|
|
- ->where('ear.created_at', '>=', $startCurrent)
|
|
|
- ->groupBy('p.teacher_id')
|
|
|
- ->selectRaw('p.teacher_id AS teacher_id, COUNT(DISTINCT ear.student_id) AS c')
|
|
|
- ->get();
|
|
|
-$studentAnalysisPrevRows = $db::table('exam_analysis_results as ear')
|
|
|
- ->join('papers as p', 'p.paper_id', '=', 'ear.paper_id')
|
|
|
- ->whereNotNull('p.teacher_id')
|
|
|
- ->where('p.teacher_id', '!=', '')
|
|
|
- ->whereNotNull('ear.student_id')
|
|
|
- ->where('ear.student_id', '!=', '')
|
|
|
- ->where('ear.created_at', '>=', $startPrev)
|
|
|
- ->where('ear.created_at', '<', $endPrev)
|
|
|
- ->groupBy('p.teacher_id')
|
|
|
- ->selectRaw('p.teacher_id AS teacher_id, COUNT(DISTINCT ear.student_id) AS c')
|
|
|
- ->get();
|
|
|
-
|
|
|
-$studentAsmCurMap = [];
|
|
|
-foreach ($studentAsmCurRows as $row) {
|
|
|
- $studentAsmCurMap[(string) $row->teacher_id] = (int) $row->c;
|
|
|
-}
|
|
|
-$studentAsmPrevMap = [];
|
|
|
-foreach ($studentAsmPrevRows as $row) {
|
|
|
- $studentAsmPrevMap[(string) $row->teacher_id] = (int) $row->c;
|
|
|
+/** 学生数:组卷 ∪ 学情,student_id 合并去重(按老师、时间窗) */
|
|
|
+$studentUnionSql = <<<'SQL'
|
|
|
+SELECT u.teacher_id, COUNT(DISTINCT u.student_id) AS c
|
|
|
+FROM (
|
|
|
+ SELECT teacher_id, student_id FROM papers
|
|
|
+ WHERE teacher_id IS NOT NULL AND teacher_id != ''
|
|
|
+ AND student_id IS NOT NULL AND student_id != ''
|
|
|
+ AND created_at >= ? AND created_at < ?
|
|
|
+ UNION
|
|
|
+ SELECT p.teacher_id, ear.student_id
|
|
|
+ FROM exam_analysis_results ear
|
|
|
+ INNER JOIN papers p ON p.paper_id = ear.paper_id
|
|
|
+ WHERE p.teacher_id IS NOT NULL AND p.teacher_id != ''
|
|
|
+ AND ear.student_id IS NOT NULL AND ear.student_id != ''
|
|
|
+ AND ear.created_at >= ? AND ear.created_at < ?
|
|
|
+) u
|
|
|
+GROUP BY u.teacher_id
|
|
|
+SQL;
|
|
|
+
|
|
|
+$studentUnionCurRows = $db::select($studentUnionSql, [$startCurrent, $endCurrent, $startCurrent, $endCurrent]);
|
|
|
+$studentUnionPrevRows = $db::select($studentUnionSql, [$startPrev, $endPrev, $startPrev, $endPrev]);
|
|
|
+
|
|
|
+$studentUnionCurMap = [];
|
|
|
+foreach ($studentUnionCurRows as $row) {
|
|
|
+ $studentUnionCurMap[(string) $row->teacher_id] = (int) $row->c;
|
|
|
}
|
|
|
-$studentAnalysisCurMap = [];
|
|
|
-foreach ($studentAnalysisCurRows as $row) {
|
|
|
- $studentAnalysisCurMap[(string) $row->teacher_id] = (int) $row->c;
|
|
|
-}
|
|
|
-$studentAnalysisPrevMap = [];
|
|
|
-foreach ($studentAnalysisPrevRows as $row) {
|
|
|
- $studentAnalysisPrevMap[(string) $row->teacher_id] = (int) $row->c;
|
|
|
+$studentUnionPrevMap = [];
|
|
|
+foreach ($studentUnionPrevRows as $row) {
|
|
|
+ $studentUnionPrevMap[(string) $row->teacher_id] = (int) $row->c;
|
|
|
}
|
|
|
|
|
|
$names = \Illuminate\Support\Facades\DB::table('teachers')->pluck('name', 'teacher_id');
|
|
|
@@ -455,40 +425,38 @@ echo "### 按老师\n\n";
|
|
|
|
|
|
echo '<table class="weekly-teacher-table">';
|
|
|
echo '<colgroup>';
|
|
|
-echo '<col style="width:4%" /><col style="width:5%" /><col style="width:7%" />';
|
|
|
+echo '<col style="width:4%" /><col style="width:11%" />';
|
|
|
echo '<col style="width:7%" /><col style="width:7%" /><col style="width:8%" />';
|
|
|
echo '<col class="col-an" style="width:9%" /><col class="col-an" style="width:9%" /><col style="width:8%" />';
|
|
|
-echo '<col class="col-stu" style="width:9%" /><col class="col-stu" style="width:9%" />';
|
|
|
+echo '<col class="col-stu" style="width:10%" />';
|
|
|
echo '</colgroup>';
|
|
|
echo '<thead><tr>';
|
|
|
-echo '<th>排名</th><th>老师</th><th>teacher_id</th><th>组卷·本</th><th>组卷·上</th><th>组卷·环比</th><th>学情·本</th><th>学情·上</th><th>学情·环比</th>';
|
|
|
-echo '<th>参与学生·组卷</th><th>参与学生·学情</th>';
|
|
|
+echo '<th>排名</th><th>老师</th><th>组卷·本</th><th>组卷·上</th><th>组卷·环比</th><th>学情·本</th><th>学情·上</th><th>学情·环比</th><th>学生数</th>';
|
|
|
echo "</tr></thead>\n<tbody>\n";
|
|
|
|
|
|
$i = 1;
|
|
|
foreach ($rows as $r) {
|
|
|
- $nm = htmlspecialchars((string) $r['name'], ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8');
|
|
|
+ $tidKey = (string) $r['teacher_id'];
|
|
|
+ $nmRaw = (string) $r['name'];
|
|
|
+ $nmEsc = htmlspecialchars($nmRaw, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8');
|
|
|
+ $tidEsc = htmlspecialchars($tidKey, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8');
|
|
|
+ $nameWithId = $nmEsc.' <span class="teacher-id">('.$tidEsc.')</span>';
|
|
|
$pc = $r['papers'];
|
|
|
$pp = $r['papers_prev'];
|
|
|
$ac = $r['analysis_sets'];
|
|
|
$ap = $r['analysis_sets_prev'];
|
|
|
- $tidKey = (string) $r['teacher_id'];
|
|
|
- $stuAsmC = (int) ($studentAsmCurMap[$tidKey] ?? 0);
|
|
|
- $stuAsmP = (int) ($studentAsmPrevMap[$tidKey] ?? 0);
|
|
|
- $stuAnC = (int) ($studentAnalysisCurMap[$tidKey] ?? 0);
|
|
|
- $stuAnP = (int) ($studentAnalysisPrevMap[$tidKey] ?? 0);
|
|
|
+ $stuC = (int) ($studentUnionCurMap[$tidKey] ?? 0);
|
|
|
+ $stuP = (int) ($studentUnionPrevMap[$tidKey] ?? 0);
|
|
|
echo '<tr>';
|
|
|
echo '<td style="text-align:right">'.((string) $i++).'</td>';
|
|
|
- echo '<td class="td-name">'.$nm.'</td>';
|
|
|
- echo '<td>'.htmlspecialchars((string) $r['teacher_id'], ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8').'</td>';
|
|
|
+ echo '<td class="td-name">'.$nameWithId.'</td>';
|
|
|
echo '<td style="text-align:right">'.((string) $pc).'</td>';
|
|
|
echo '<td style="text-align:right">'.((string) $pp).'</td>';
|
|
|
echo '<td>'.$compareCellHtml($pc, $pp).'</td>';
|
|
|
echo '<td style="text-align:right" class="td-an">'.((string) $ac).'</td>';
|
|
|
echo '<td style="text-align:right" class="td-an">'.((string) $ap).'</td>';
|
|
|
echo '<td>'.$compareCellHtml($ac, $ap).'</td>';
|
|
|
- echo '<td style="text-align:right" class="td-stu" title="本周期/上周期,学生去重">'.$stuAsmC.' / '.$stuAsmP.'</td>';
|
|
|
- echo '<td style="text-align:right" class="td-stu" title="本周期/上周期,学生去重">'.$stuAnC.' / '.$stuAnP.'</td>';
|
|
|
+ echo '<td style="text-align:right" class="td-stu" title="组卷∪学情,学生合并去重;本/上">'.$stuC.' / '.$stuP.'</td>';
|
|
|
echo "</tr>\n";
|
|
|
}
|
|
|
echo "</tbody></table>\n";
|