Commit 0927604f authored by David Monllaó's avatar David Monllaó
Browse files

MDL-59987 analytics: Add no students indicator to no teaching

Sneaking in a bug fix ;) (thanks in advance)
parent 23ab0d77
......@@ -483,7 +483,8 @@ class manager {
$target = self::get_target('\core\analytics\target\no_teaching');
$timesplittingmethod = '\core\analytics\time_splitting\single_range';
$noteacher = self::get_indicator('\core_course\analytics\indicator\no_teacher');
$indicators = array($noteacher->get_id() => $noteacher);
$nostudent = self::get_indicator('\core_course\analytics\indicator\no_student');
$indicators = array($noteacher->get_id() => $noteacher, $nostudent->get_id() => $nostudent);
if (!\core_analytics\model::exists($target, $indicators)) {
\core_analytics\model::create($target, $indicators, $timesplittingmethod);
}
......
......@@ -794,7 +794,9 @@ class model {
}
}
$this->save_predictions($records);
if (!empty($records)) {
$this->save_predictions($records);
}
return $samplecontexts;
}
......
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* No student indicator.
*
* @package core_course
* @copyright 2017 David Monllao {@link http://www.davidmonllao.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core_course\analytics\indicator;
defined('MOODLE_INTERNAL') || die();
/**
* No student indicator.
*
* @package core_course
* @copyright 2016 David Monllao {@link http://www.davidmonllao.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class no_student extends \core_analytics\local\indicator\binary {
/**
* Student role ids.
*
* @var array|null
*/
protected $studentroleids = null;
/**
* Returns the name.
*
* If there is a corresponding '_help' string this will be shown as well.
*
* @return \lang_string
*/
public static function get_name() : \lang_string {
return new \lang_string('indicator:nostudent', 'moodle');
}
/**
* required_sample_data
*
* @return string[]
*/
public static function required_sample_data() {
// We require course because, although calculate_sample only reads context, we need the context to be course
// or below.
return array('context', 'course');
}
/**
* Reversed because the indicator is in 'negative' and the max returned value means student present.
*
* @param float $value
* @param string $subtype
* @return string
*/
public function get_display_value($value, $subtype = false) {
// No subtypes for binary values by default.
if ($value == -1) {
return get_string('yes');
} else if ($value == 1) {
return get_string('no');
}
}
/**
* calculate_sample
*
* @param int $sampleid
* @param string $sampleorigin
* @param int|false $notusedstarttime
* @param int|false $notusedendtime
* @return float
*/
public function calculate_sample($sampleid, $sampleorigin, $notusedstarttime = false, $notusedendtime = false) {
$context = $this->retrieve('context', $sampleid);
if (is_null($this->studentroleids)) {
$this->studentroleids = array_keys(get_archetype_roles('student'));
}
foreach ($this->studentroleids as $role) {
// We look for roles, not enrolments as a student assigned at category level is supposed to be a
// course student.
$students = get_role_users($role, $context, false, 'u.id', 'u.id');
if ($students) {
return self::get_max_value();
}
}
return self::get_min_value();
}
}
......@@ -1035,6 +1035,8 @@ $string['indicator:completeduserprofile'] = 'User profile is completed';
$string['indicator:completeduserprofile_help'] = 'This indicator represents that the student has completed their user profile.';
$string['indicator:completionenabled'] = 'Completion enabled';
$string['indicator:completionenabled_help'] = 'This indicator represents that completion tracking has been enabled.';
$string['indicator:nostudent'] = 'There are no students';
$string['indicator:nostudent_help'] = 'This indicator reflects that this course has no students.';
$string['indicator:noteacher'] = 'There are no teachers';
$string['indicator:noteacher_help'] = 'This indicator reflects that this course has no teachers.';
$string['indicator:potentialcognitive'] = 'Potential cognitive depth';
......@@ -1904,7 +1906,7 @@ $string['tags'] = 'Tags';
$string['target:coursedropout'] = 'Students at risk of dropping out';
$string['target:coursedropout_help'] = 'This target describes whether the student is considered at risk of dropping out.';
$string['target:noteachingactivity'] = 'No teaching';
$string['target:noteachingactivity_help'] = 'This target describes whether or not this teacher is likely to engage in any activity in the course.';
$string['target:noteachingactivity_help'] = 'This target describes whether courses that start during the following week will have teaching activity.';
$string['targetlabelstudentdropoutyes'] = 'Student at risk of dropping out';
$string['targetlabelstudentdropoutno'] = 'Not at risk';
$string['targetlabelteachingyes'] = 'Users with teaching capabilities have access to the course';
......
......@@ -168,8 +168,10 @@ class no_teaching extends \core_analytics\local\target\binary {
protected function calculate_sample($sampleid, \core_analytics\analysable $analysable, $starttime = false, $endtime = false) {
$noteachersindicator = $this->retrieve('\core_course\analytics\indicator\no_teacher', $sampleid);
if ($noteachersindicator == \core_course\analytics\indicator\no_teacher::get_min_value()) {
// No teachers :( we flag this as 1.
$nostudentsindicator = $this->retrieve('\core_course\analytics\indicator\no_student', $sampleid);
if ($noteachersindicator == \core_course\analytics\indicator\no_teacher::get_min_value() ||
$nostudentsindicator == \core_course\analytics\indicator\no_student::get_min_value()) {
// No teachers or no students :(.
return 1;
}
return 0;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment