Browse Source

Fix grade calculation bug

2021092200_STABLE
Sesostris Vieira 3 years ago
parent
commit
aeb059c69d
  1. 14
      classes/task/grade_participation_task.php
  2. 1
      grade.php
  3. 8
      lib.php

14
classes/task/grade_participation_task.php

@ -44,17 +44,17 @@ class grade_participation_task extends \core\task\scheduled_task {
$palestras = $DB->get_records_sql(" $palestras = $DB->get_records_sql("
select p.id, p.course, p.name, p.startdate, p.duration, p.checkinterval select p.id, p.course, p.name, p.startdate, p.duration, p.checkinterval
from {palestra} p from {palestra} p
inner join {palestra_presence} pp on pp.palestraid = p.id
inner join {course} c on c.id = p.course inner join {course} c on c.id = p.course
where where
(p.needsupdate = 1) and (p.needsupdate = 1) and
(c.visible = 1) and (c.visible = 1) and
((c.startdate <= ?) and (c.enddate = 0 or c.enddate >= ?)) ((c.startdate <= ?) and (c.enddate = 0 or c.enddate >= ?)) and
and ((p.startdate + (p.duration*60)) < ?) (select count(*)
group by p.id, p.course, p.name, p.startdate, p.duration, p.checkinterval from {palestra_presence} pp
having max(pp.lastcheck) < ? - p.checkinterval*60 where pp.palestraid = p.id and
(pp.lastcheck+(p.duration*60)) < ?
", [$now, $now, $now, $now]); ) > 0
", [$now, $now, $now]);
mtrace(count($palestras)." palestras to grade..."); mtrace(count($palestras)." palestras to grade...");

1
grade.php

@ -26,6 +26,7 @@
require_once(__DIR__ . '/../../config.php'); require_once(__DIR__ . '/../../config.php');
require_once("lib.php"); require_once("lib.php");
require_once($CFG->libdir."/gradelib.php");
$id = required_param('id', PARAM_INT); $id = required_param('id', PARAM_INT);
$userid = optional_param('userid', 0, PARAM_INT); $userid = optional_param('userid', 0, PARAM_INT);

8
lib.php

@ -207,10 +207,12 @@ function palestra_update_grades($palestra, $userid=0, $nullifnone=true) {
global $CFG, $DB; global $CFG, $DB;
require_once($CFG->libdir.'/gradelib.php'); require_once($CFG->libdir.'/gradelib.php');
$now = time();
if ($userid) { if ($userid) {
$presences = $DB->get_records("palestra_presence", array("palestraid"=>$palestra->id, "userid"=>$userid), 'userid, starttime, lastcheck'); $presences = $DB->get_records("palestra_presence", array("palestraid"=>$palestra->id, "userid"=>$userid), 'id, userid, starttime, lastcheck');
} else { } else {
$presences = $DB->get_records("palestra_presence", array("palestraid"=>$palestra->id), 'userid, starttime, lastcheck'); $presences = $DB->get_records_select("palestra_presence", "palestraid=? and lastcheck+? < ?", [$palestra->id, $palestra->duration*60, $now], 'userid, starttime', 'id, userid, starttime, lastcheck');
} }
$audiences = array(); $audiences = array();
@ -231,7 +233,9 @@ function palestra_update_grades($palestra, $userid=0, $nullifnone=true) {
continue; continue;
} }
if ($presence->starttime < ($start + $minimal)) { if ($presence->starttime < ($start + $minimal)) {
if ($end < $presence->lastcheck) {
$end = $presence->lastcheck; $end = $presence->lastcheck;
}
} else { } else {
$audiences[$user] = (isset($audiences[$user])?$audiences[$user]:0) + (max($end - $start, $minimal)/60); $audiences[$user] = (isset($audiences[$user])?$audiences[$user]:0) + (max($end - $start, $minimal)/60);
$start = $presence->starttime; $start = $presence->starttime;

Loading…
Cancel
Save