Переглянути джерело

feat(report): 老师表增加参与学生(组卷/学情)去重列(本/上)

Made-with: Cursor
yemeishu 1 місяць тому
батько
коміт
33e1a4cf26

+ 75 - 4
scripts/report_teacher_weekly_stats.php

@@ -1,7 +1,8 @@
 <?php
 
 /**
- * 近 7 天老师组卷 + 学情分析套数(exam_analysis_results 按 paper_id 去重,一套卷计 1)
+ * 近 7 天老师组卷 + 学情分析套数(exam_analysis_results 按 paper_id 去重,一套卷计 1)。
+ * 按老师:参与学生·组卷 = papers.student_id 去重;参与学生·学情 = exam_analysis_results.student_id 去重(均按本/上周期)。
  * 用法:
  *   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
@@ -175,6 +176,67 @@ 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;
+}
+$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;
+}
+
 $names = \Illuminate\Support\Facades\DB::table('teachers')->pluck('name', 'teacher_id');
 $nameStrMap = [];
 foreach ($names as $tid => $nm) {
@@ -393,12 +455,14 @@ echo "### 按老师\n\n";
 
 echo '<table class="weekly-teacher-table">';
 echo '<colgroup>';
-echo '<col style="width:5%" /><col style="width:6%" /><col style="width:8%" />';
-echo '<col style="width:8%" /><col style="width:8%" /><col style="width:10%" />';
-echo '<col class="col-an" style="width:11%" /><col class="col-an" style="width:11%" /><col style="width:9%" />';
+echo '<col style="width:4%" /><col style="width:5%" /><col style="width:7%" />';
+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 '</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 "</tr></thead>\n<tbody>\n";
 
 $i = 1;
@@ -408,6 +472,11 @@ foreach ($rows as $r) {
     $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);
     echo '<tr>';
     echo '<td style="text-align:right">'.((string) $i++).'</td>';
     echo '<td class="td-name">'.$nm.'</td>';
@@ -418,6 +487,8 @@ foreach ($rows as $r) {
     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 "</tr>\n";
 }
 echo "</tbody></table>\n";

+ 2 - 0
scripts/report_teacher_weekly_stats_pdf.php

@@ -51,6 +51,8 @@ th { background: #f3f4f6; font-weight: 600; }
 .weekly-teacher-table col.col-an { width: 11%; }
 .weekly-teacher-table .td-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 0; }
 .weekly-teacher-table .td-an { font-variant-numeric: tabular-nums; }
+.weekly-teacher-table col.col-stu { width: 9%; }
+.weekly-teacher-table .td-stu { font-variant-numeric: tabular-nums; font-size: 8.5pt; }
 </style>
 CSS;