Fix: alle heutigen Leistungen zaehlen (Ben) + Live-Session started_at bei Modulwechsel (Clara)
- live.php: ON DUPLICATE KEY UPDATE-Reihenfolge korrigiert (started_at VOR module_id), sonst wird der Modulwechsel nie erkannt -> Balken behielt alten Startzeitpunkt (Clara EU-Werkstatt seit 14:30). - results.php view=today: liefert todayScores (Pro-Schueler-Aggregat aus student_results, zuverlaessig). - teacher.html HEUTE-Triage: fertige Laeufe aus student_results + laufende aus Summary zusammengefuehrt; Totalversagen heute (<40) -> Foerdern. Ben (klima 36) erscheint jetzt korrekt in Foerdern. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -54,9 +54,12 @@ if ($method === 'POST') {
|
||||
VALUES (?, ?, ?, ?, NOW(), NOW())
|
||||
ON DUPLICATE KEY UPDATE
|
||||
class_id = VALUES(class_id),
|
||||
-- started_at ZUERST prüfen: MySQL wertet die Zuweisungen links→rechts
|
||||
-- aus, daher muss dieser Check VOR module_id stehen, sonst ist
|
||||
-- module_id schon der neue Wert und der Modulwechsel wird nie erkannt.
|
||||
started_at = IF(module_id <> VALUES(module_id) OR last_seen < NOW() - INTERVAL 30 SECOND, NOW(), started_at),
|
||||
module_id = VALUES(module_id),
|
||||
state_json = VALUES(state_json),
|
||||
started_at = IF(module_id <> VALUES(module_id) OR last_seen < NOW() - INTERVAL 30 SECOND, NOW(), started_at),
|
||||
last_seen = NOW()',
|
||||
[$studentId, $classId, $moduleId, $stateJson]
|
||||
);
|
||||
|
||||
+21
-1
@@ -309,7 +309,27 @@ if ($view === 'today') {
|
||||
];
|
||||
}
|
||||
|
||||
Response::ok(['date'=>$today, 'topToday'=>array_slice($todayRuns, 0, 6), 'progress'=>$progress]);
|
||||
// Pro-Schüler-Aggregat der HEUTIGEN Läufe (aus student_results — zuverlässig
|
||||
// mit student_id, unabhängig vom assessments/student_sessions-Join). Basis für
|
||||
// die HEUTE-Empfehlung, damit ALLE heutigen Leistungen zählen (nicht nur die,
|
||||
// die es in die assessments-Tabelle geschafft haben).
|
||||
$todayScores = []; // sid => ['plays'=>n, 'avgScore'=>0-100, 'minScore'=>..]
|
||||
foreach ($rows as $r) {
|
||||
if (substr($r['completed_at'], 0, 10) !== $today) continue;
|
||||
$sid = (int)$r['student_id'];
|
||||
$sc = max(0, min(100, (float)$r['score']));
|
||||
if (!isset($todayScores[$sid])) $todayScores[$sid] = ['plays'=>0, '_sum'=>0.0, 'minScore'=>100];
|
||||
$todayScores[$sid]['plays']++;
|
||||
$todayScores[$sid]['_sum'] += $sc;
|
||||
if ($sc < $todayScores[$sid]['minScore']) $todayScores[$sid]['minScore'] = (int)round($sc);
|
||||
}
|
||||
foreach ($todayScores as $sid => &$t) {
|
||||
$t['avgScore'] = (int)round($t['_sum'] / max(1, $t['plays']));
|
||||
unset($t['_sum']);
|
||||
}
|
||||
unset($t);
|
||||
|
||||
Response::ok(['date'=>$today, 'topToday'=>array_slice($todayRuns, 0, 6), 'progress'=>$progress, 'todayScores'=>$todayScores]);
|
||||
}
|
||||
|
||||
// =============================================================================
|
||||
|
||||
Reference in New Issue
Block a user