$defaultmodeloutputdir = rtrim($CFG->dataroot, '/') . DIRECTORY_SEPARATOR . 'models';
$settings->add(new admin_setting_configdirectory('analytics/modeloutputdir', new lang_string('modeloutputdir', 'analytics'),
new lang_string('modeloutputdirinfo', 'analytics'), $defaultmodeloutputdir));
- $studentdefaultroles = [];
- $teacherdefaultroles = [];
-
- // Student and teacher roles.
- $allroles = role_fix_names(get_all_roles());
- $rolechoices = [];
- foreach ($allroles as $role) {
- $rolechoices[$role->id] = $role->localname;
-
- if ($role->shortname == 'student') {
- $studentdefaultroles[] = $role->id;
- } else if ($role->shortname == 'teacher') {
- $teacherdefaultroles[] = $role->id;
- } else if ($role->shortname == 'editingteacher') {
- $teacherdefaultroles[] = $role->id;
- }
- }
-
- $settings->add(new admin_setting_configmultiselect('analytics/teacherroles', new lang_string('teacherroles', 'analytics'),
- '', $teacherdefaultroles, $rolechoices));
-
- $settings->add(new admin_setting_configmultiselect('analytics/studentroles', new lang_string('studentroles', 'analytics'),
- '', $studentdefaultroles, $rolechoices));
-
}
}
protected static $instances = array();
- protected $studentroles = [];
- protected $teacherroles = [];
+ protected static $studentroles = [];
+ protected static $teacherroles = [];
protected $course = null;
protected $coursecontext = null;
* Course manager constructor.
*
* Use self::instance() instead to get cached copies of the course. Instances obtained
- * through this constructor will not be cached either.
+ * through this constructor will not be cached.
*
* Loads course students and teachers.
*
- * Let's try to keep this computationally inexpensive.
- *
* @param int|stdClass $course Course id
- * @param array $studentroles
- * @param array $teacherroles
* @return void
*/
public function __construct($course) {
$this->coursecontext = \context_course::instance($this->course->id);
- $studentroles = get_config('analytics', 'studentroles');
- $teacherroles = get_config('analytics', 'teacherroles');
-
- if (empty($studentroles) || empty($teacherroles)) {
- // Unexpected, site settings should be set with default values.
- throw new \moodle_exception('errornoroles', 'analytics');
+ if (empty(self::$studentroles)) {
+ self::$studentroles = array_keys(get_archetype_roles('student'));
+ }
+ if (empty(self::$teacherroles)) {
+ self::$teacherroles = array_keys(get_archetype_roles('editingteacher') + get_archetype_roles('teacher'));
}
-
- $this->studentroles = explode(',', $studentroles);
- $this->teacherroles = explode(',', $teacherroles);
$this->now = time();
// Get the course users, including users assigned to student and teacher roles at an higher context.
- $this->studentids = $this->get_user_ids($this->studentroles);
- $this->teacherids = $this->get_user_ids($this->teacherroles);
+ $this->studentids = $this->get_user_ids(self::$studentroles);
+ $this->teacherids = $this->get_user_ids(self::$teacherroles);
}
/**
- * instance
+ * Returns an analytics course instance.
*
* @param int|stdClass $course Course id
- * @return void
+ * @return \core_analytics\course
*/
public static function instance($course) {
// Default to all system courses.
if (!empty($this->options['filter'])) {
- $courseids = $this->options['filter'];
+ $it = $this->options['filter'];
} else {
// Iterate through all potentially valid courses.
- $courseids = $DB->get_fieldset_select('course', 'id', 'id != :frontpage', array('frontpage' => SITEID), 'sortorder ASC');
+ $it = $DB->get_recordset_select('course', 'id != :frontpage', array('frontpage' => SITEID), 'sortorder ASC');
}
$analysables = array();
- foreach ($courseids as $courseid) {
- $analysable = new \core_analytics\course($courseid);
+ foreach ($it as $course) {
+ $analysable = \core_analytics\course::instance($course);
$analysables[$analysable->get_id()] = $analysable;
}
* @return \core_analytics\analysable
*/
public function get_sample_analysable($sampleid) {
- return new \core_analytics\course($sampleid);
+ return \core_analytics\course::instance($sampleid);
}
protected function provided_sample_data() {
$files = $this->process_analysable($analysable, $includetarget);
// Copy to range files as there is just one analysable.
- // TODO Not abstracted as we should ideally directly store it as range-scope file.
foreach ($files as $timesplittingid => $file) {
if ($this->options['evaluation'] === true) {
}
// We use merge but it is just a copy
- // TODO use copy or move if there are performance issues.
$files[$timesplittingid] = \core_analytics\dataset_manager::merge_datasets(array($file), $this->modelid,
$timesplittingid, $this->options['evaluation'], $includetarget);
}
}
public function get_sample_analysable($sampleid) {
- $course = enrol_get_course_by_user_enrolment_id($ueid);
- return \core_analytics\course($course);
+ $course = enrol_get_course_by_user_enrolment_id($sampleid);
+ return \core_analytics\course::instance($course);
}
protected function provided_sample_data() {
$this->getDataGenerator()->enrol_user($this->both->id, $this->course->id, $this->editingteacherroleid);
$this->getDataGenerator()->enrol_user($this->editingteacher->id, $this->course->id, $this->editingteacherroleid);
$this->getDataGenerator()->enrol_user($this->teacher->id, $this->course->id, $this->teacherroleid);
-
-
- set_config('studentroles', $this->studentroleid, 'analytics');
- set_config('teacherroles', $this->editingteacherroleid . ',' . $this->teacherroleid, 'analytics');
}
/**
$string['predictionsprocessor_help'] = 'Prediction processors are the machine learning backends that process the datasets generated by calculating models\' indicators and targets.';
$string['processingsitecontents'] = 'Processing site contents';
$string['processingsitecontents'] = 'Processing site contents';
-$string['studentroles'] = 'Student roles';
$string['successfullyanalysed'] = 'Successfully analysed';
-$string['teacherroles'] = 'Teacher roles';
$string['timesplitting:deciles'] = 'Deciles';
$string['timesplitting:decilesaccum'] = 'Deciles accumulative';
$string['timesplitting:nosplitting'] = 'No time splitting';