mirror of
https://github.com/moodle/moodle.git
synced 2025-01-19 06:18:28 +01:00
Merge branch 'MDL-65177_master' of git://github.com/dmonllao/moodle
This commit is contained in:
commit
83b2cbad02
@ -45,13 +45,14 @@ class edit_model extends \moodleform {
|
||||
|
||||
$mform = $this->_form;
|
||||
|
||||
if ($this->_customdata['trainedmodel']) {
|
||||
if ($this->_customdata['trainedmodel'] && $this->_customdata['staticmodel'] === false) {
|
||||
$message = get_string('edittrainedwarning', 'tool_analytics');
|
||||
$mform->addElement('html', $OUTPUT->notification($message, \core\output\notification::NOTIFY_WARNING));
|
||||
}
|
||||
|
||||
$mform->addElement('advcheckbox', 'enabled', get_string('enabled', 'tool_analytics'));
|
||||
|
||||
// Target.
|
||||
if (!empty($this->_customdata['targets'])) {
|
||||
$targets = array('' => '');
|
||||
foreach ($this->_customdata['targets'] as $classname => $target) {
|
||||
@ -64,42 +65,48 @@ class edit_model extends \moodleform {
|
||||
$mform->addRule('target', get_string('required'), 'required', null, 'client');
|
||||
}
|
||||
|
||||
$indicators = array();
|
||||
foreach ($this->_customdata['indicators'] as $classname => $indicator) {
|
||||
$optionname = \tool_analytics\output\helper::class_to_option($classname);
|
||||
$indicators[$optionname] = $indicator->get_name();
|
||||
// Indicators.
|
||||
if (!$this->_customdata['staticmodel']) {
|
||||
$indicators = array();
|
||||
foreach ($this->_customdata['indicators'] as $classname => $indicator) {
|
||||
$optionname = \tool_analytics\output\helper::class_to_option($classname);
|
||||
$indicators[$optionname] = $indicator->get_name();
|
||||
}
|
||||
$options = array(
|
||||
'multiple' => true
|
||||
);
|
||||
$mform->addElement('autocomplete', 'indicators', get_string('indicators', 'tool_analytics'), $indicators, $options);
|
||||
$mform->setType('indicators', PARAM_ALPHANUMEXT);
|
||||
$mform->addHelpButton('indicators', 'indicators', 'tool_analytics');
|
||||
}
|
||||
$options = array(
|
||||
'multiple' => true
|
||||
);
|
||||
$mform->addElement('autocomplete', 'indicators', get_string('indicators', 'tool_analytics'), $indicators, $options);
|
||||
$mform->setType('indicators', PARAM_ALPHANUMEXT);
|
||||
$mform->addHelpButton('indicators', 'indicators', 'tool_analytics');
|
||||
|
||||
// Time-splitting methods.
|
||||
$timesplittings = array('' => '');
|
||||
foreach ($this->_customdata['timesplittings'] as $classname => $timesplitting) {
|
||||
$optionname = \tool_analytics\output\helper::class_to_option($classname);
|
||||
$timesplittings[$optionname] = $timesplitting->get_name();
|
||||
}
|
||||
|
||||
$mform->addElement('select', 'timesplitting', get_string('timesplittingmethod', 'analytics'), $timesplittings);
|
||||
$mform->addHelpButton('timesplitting', 'timesplittingmethod', 'analytics');
|
||||
|
||||
$defaultprocessor = \core_analytics\manager::get_predictions_processor_name(
|
||||
\core_analytics\manager::get_predictions_processor()
|
||||
);
|
||||
$predictionprocessors = ['' => get_string('defaultpredictoroption', 'analytics', $defaultprocessor)];
|
||||
foreach ($this->_customdata['predictionprocessors'] as $classname => $predictionsprocessor) {
|
||||
if ($predictionsprocessor->is_ready() !== true) {
|
||||
continue;
|
||||
// Predictions processor.
|
||||
if (!$this->_customdata['staticmodel']) {
|
||||
$defaultprocessor = \core_analytics\manager::get_predictions_processor_name(
|
||||
\core_analytics\manager::get_predictions_processor()
|
||||
);
|
||||
$predictionprocessors = ['' => get_string('defaultpredictoroption', 'analytics', $defaultprocessor)];
|
||||
foreach ($this->_customdata['predictionprocessors'] as $classname => $predictionsprocessor) {
|
||||
if ($predictionsprocessor->is_ready() !== true) {
|
||||
continue;
|
||||
}
|
||||
$optionname = \tool_analytics\output\helper::class_to_option($classname);
|
||||
$predictionprocessors[$optionname] = \core_analytics\manager::get_predictions_processor_name($predictionsprocessor);
|
||||
}
|
||||
$optionname = \tool_analytics\output\helper::class_to_option($classname);
|
||||
$predictionprocessors[$optionname] = \core_analytics\manager::get_predictions_processor_name($predictionsprocessor);
|
||||
}
|
||||
|
||||
$mform->addElement('select', 'predictionsprocessor', get_string('predictionsprocessor', 'analytics'),
|
||||
$predictionprocessors);
|
||||
$mform->addHelpButton('predictionsprocessor', 'predictionsprocessor', 'analytics');
|
||||
$mform->addElement('select', 'predictionsprocessor', get_string('predictionsprocessor', 'analytics'),
|
||||
$predictionprocessors);
|
||||
$mform->addHelpButton('predictionsprocessor', 'predictionsprocessor', 'analytics');
|
||||
}
|
||||
|
||||
if (!empty($this->_customdata['id'])) {
|
||||
$mform->addElement('hidden', 'id', $this->_customdata['id']);
|
||||
@ -130,13 +137,15 @@ class edit_model extends \moodleform {
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($data['indicators'])) {
|
||||
$errors['indicators'] = get_string('errornoindicators', 'analytics');
|
||||
} else {
|
||||
foreach ($data['indicators'] as $indicator) {
|
||||
$realindicatorname = \tool_analytics\output\helper::option_to_class($indicator);
|
||||
if (\core_analytics\manager::is_valid($realindicatorname, '\core_analytics\local\indicator\base') === false) {
|
||||
$errors['indicators'] = get_string('errorinvalidindicator', 'analytics', $realindicatorname);
|
||||
if (!$this->_customdata['staticmodel']) {
|
||||
if (empty($data['indicators'])) {
|
||||
$errors['indicators'] = get_string('errornoindicators', 'analytics');
|
||||
} else {
|
||||
foreach ($data['indicators'] as $indicator) {
|
||||
$realindicatorname = \tool_analytics\output\helper::option_to_class($indicator);
|
||||
if (\core_analytics\manager::is_valid($realindicatorname, '\core_analytics\local\indicator\base') === false) {
|
||||
$errors['indicators'] = get_string('errorinvalidindicator', 'analytics', $realindicatorname);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -229,12 +229,10 @@ class models_list implements \renderable, \templatable {
|
||||
}
|
||||
|
||||
// Edit model.
|
||||
if (!$model->is_static()) {
|
||||
$urlparams['action'] = 'edit';
|
||||
$url = new \moodle_url('model.php', $urlparams);
|
||||
$icon = new \action_menu_link_secondary($url, new \pix_icon('t/edit', get_string('edit')), get_string('edit'));
|
||||
$actionsmenu->add($icon);
|
||||
}
|
||||
$urlparams['action'] = 'edit';
|
||||
$url = new \moodle_url('model.php', $urlparams);
|
||||
$icon = new \action_menu_link_secondary($url, new \pix_icon('t/edit', get_string('edit')), get_string('edit'));
|
||||
$actionsmenu->add($icon);
|
||||
|
||||
// Enable / disable.
|
||||
if ($model->is_enabled() || !empty($modeldata->timesplitting)) {
|
||||
@ -299,14 +297,17 @@ class models_list implements \renderable, \templatable {
|
||||
$actionsmenu->add($icon);
|
||||
}
|
||||
|
||||
$actionid = 'delete-' . $model->get_id();
|
||||
$PAGE->requires->js_call_amd('tool_analytics/model', 'confirmAction', [$actionid, 'delete']);
|
||||
$urlparams['action'] = 'delete';
|
||||
$url = new \moodle_url('model.php', $urlparams);
|
||||
$icon = new \action_menu_link_secondary($url, new \pix_icon('t/delete',
|
||||
get_string('delete', 'tool_analytics')), get_string('delete', 'tool_analytics'),
|
||||
['data-action-id' => $actionid]);
|
||||
$actionsmenu->add($icon);
|
||||
// Delete model.
|
||||
if (!$model->is_static()) {
|
||||
$actionid = 'delete-' . $model->get_id();
|
||||
$PAGE->requires->js_call_amd('tool_analytics/model', 'confirmAction', [$actionid, 'delete']);
|
||||
$urlparams['action'] = 'delete';
|
||||
$url = new \moodle_url('model.php', $urlparams);
|
||||
$icon = new \action_menu_link_secondary($url, new \pix_icon('t/delete',
|
||||
get_string('delete', 'tool_analytics')), get_string('delete', 'tool_analytics'),
|
||||
['data-action-id' => $actionid]);
|
||||
$actionsmenu->add($icon);
|
||||
}
|
||||
|
||||
$modeldata->actions = $actionsmenu->export_for_template($output);
|
||||
|
||||
|
@ -40,9 +40,10 @@ $targets = array_filter(\core_analytics\manager::get_all_targets(), function($ta
|
||||
|
||||
$customdata = array(
|
||||
'trainedmodel' => false,
|
||||
'staticmodel' => false,
|
||||
'targets' => $targets,
|
||||
'indicators' => \core_analytics\manager::get_all_indicators(),
|
||||
'timesplittings' => \core_analytics\manager::get_enabled_time_splitting_methods(),
|
||||
'timesplittings' => \core_analytics\manager::get_all_time_splittings(),
|
||||
'predictionprocessors' => \core_analytics\manager::get_all_prediction_processors(),
|
||||
);
|
||||
$mform = new \tool_analytics\output\form\edit_model(null, $customdata);
|
||||
|
@ -48,7 +48,6 @@ $string['errorcantenablenotimesplitting'] = 'You need to select a time-splitting
|
||||
$string['errornoenabledandtrainedmodels'] = 'There are no enabled and trained models to predict.';
|
||||
$string['errornoenabledmodels'] = 'There are no enabled models to train.';
|
||||
$string['errornoexport'] = 'Only trained models can be exported';
|
||||
$string['errornostaticedit'] = 'Models based on assumptions cannot be edited.';
|
||||
$string['errornostaticevaluated'] = 'Models based on assumptions cannot be evaluated. They are always 100% correct according to how they were defined.';
|
||||
$string['errornostaticlog'] = 'Models based on assumptions cannot be evaluated because there is no performance log.';
|
||||
$string['erroronlycli'] = 'Execution only allowed via command line';
|
||||
|
@ -103,21 +103,19 @@ switch ($action) {
|
||||
case 'delete':
|
||||
confirm_sesskey();
|
||||
|
||||
$model->delete();
|
||||
if (!$model->is_static()) {
|
||||
$model->delete();
|
||||
}
|
||||
redirect($returnurl);
|
||||
break;
|
||||
|
||||
case 'edit':
|
||||
confirm_sesskey();
|
||||
|
||||
if ($model->is_static()) {
|
||||
echo $OUTPUT->header();
|
||||
throw new moodle_exception('errornostaticedit', 'tool_analytics');
|
||||
}
|
||||
|
||||
$customdata = array(
|
||||
'id' => $model->get_id(),
|
||||
'trainedmodel' => $model->is_trained(),
|
||||
'staticmodel' => $model->is_static(),
|
||||
'indicators' => $model->get_potential_indicators(),
|
||||
'timesplittings' => \core_analytics\manager::get_all_time_splittings(),
|
||||
'predictionprocessors' => \core_analytics\manager::get_all_prediction_processors()
|
||||
@ -129,14 +127,22 @@ switch ($action) {
|
||||
|
||||
} else if ($data = $mform->get_data()) {
|
||||
|
||||
// Converting option names to class names.
|
||||
$indicators = array();
|
||||
foreach ($data->indicators as $indicator) {
|
||||
$indicatorclass = \tool_analytics\output\helper::option_to_class($indicator);
|
||||
$indicators[] = \core_analytics\manager::get_indicator($indicatorclass);
|
||||
}
|
||||
$timesplitting = \tool_analytics\output\helper::option_to_class($data->timesplitting);
|
||||
$predictionsprocessor = \tool_analytics\output\helper::option_to_class($data->predictionsprocessor);
|
||||
|
||||
if (!$model->is_static()) {
|
||||
// Converting option names to class names.
|
||||
$indicators = array();
|
||||
foreach ($data->indicators as $indicator) {
|
||||
$indicatorclass = \tool_analytics\output\helper::option_to_class($indicator);
|
||||
$indicators[] = \core_analytics\manager::get_indicator($indicatorclass);
|
||||
}
|
||||
$predictionsprocessor = \tool_analytics\output\helper::option_to_class($data->predictionsprocessor);
|
||||
} else {
|
||||
// These fields can not be modified.
|
||||
$indicators = false;
|
||||
$predictionsprocessor = false;
|
||||
}
|
||||
|
||||
$model->update($data->enabled, $indicators, $timesplitting, $predictionsprocessor);
|
||||
redirect($returnurl);
|
||||
}
|
||||
|
@ -2022,6 +2022,10 @@ $string['timesplitting:quartersaccum'] = 'Quarters accumulative';
|
||||
$string['timesplitting:quartersaccum_help'] = 'This time-splitting method divides the course into quarters (4 equal parts), with each prediction being based on the data of all previous quarters.';
|
||||
$string['timesplitting:singlerange'] = 'Single range';
|
||||
$string['timesplitting:singlerange_help'] = 'This time-splitting method considers the entire course as a single span.';
|
||||
$string['timesplitting:upcoming3days'] = 'Upcoming 3 days';
|
||||
$string['timesplitting:upcoming3days_help'] = 'This time-splitting method generates predictions every 3 days. The indicators calculations will be based on the upcoming 3 days.';
|
||||
$string['timesplitting:upcomingfortnight'] = 'Upcoming fortnight';
|
||||
$string['timesplitting:upcomingfortnight_help'] = 'This time-splitting method generates predictions every fortnight. The indicators calculations will be based on the upcoming fortnight.';
|
||||
$string['timesplitting:upcomingweek'] = 'Upcoming week';
|
||||
$string['timesplitting:upcomingweek_help'] = 'This time-splitting method generates predictions every week. The indicators calculations will be based on the upcoming week.';
|
||||
$string['thanks'] = 'Thanks';
|
||||
|
53
lib/classes/analytics/time_splitting/upcoming_3_days.php
Normal file
53
lib/classes/analytics/time_splitting/upcoming_3_days.php
Normal file
@ -0,0 +1,53 @@
|
||||
<?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/>.
|
||||
|
||||
/**
|
||||
* Time splitting method that generates insights every three days and calculates indicators using upcoming dates.
|
||||
*
|
||||
* @package core_analytics
|
||||
* @copyright 2019 David Monllao {@link http://www.davidmonllao.com}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
namespace core\analytics\time_splitting;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
/**
|
||||
* Time splitting method that generates insights every three days and calculates indicators using upcoming dates.
|
||||
*
|
||||
* @package core_analytics
|
||||
* @copyright 2019 David Monllao {@link http://www.davidmonllao.com}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class upcoming_3_days extends \core_analytics\local\time_splitting\upcoming_periodic {
|
||||
|
||||
/**
|
||||
* The time splitting method name.
|
||||
* @return \lang_string
|
||||
*/
|
||||
public static function get_name() : \lang_string {
|
||||
return new \lang_string('timesplitting:upcoming3days');
|
||||
}
|
||||
|
||||
/**
|
||||
* Once every three days.
|
||||
* @return \DateInterval
|
||||
*/
|
||||
public function periodicity() {
|
||||
return new \DateInterval('P3D');
|
||||
}
|
||||
}
|
53
lib/classes/analytics/time_splitting/upcoming_fortnight.php
Normal file
53
lib/classes/analytics/time_splitting/upcoming_fortnight.php
Normal file
@ -0,0 +1,53 @@
|
||||
<?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/>.
|
||||
|
||||
/**
|
||||
* Time splitting method that generates insights every fortnight and calculates indicators using upcoming dates.
|
||||
*
|
||||
* @package core_analytics
|
||||
* @copyright 2019 David Monllao {@link http://www.davidmonllao.com}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
namespace core\analytics\time_splitting;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
/**
|
||||
* Time splitting method that generates insights every fortnight and calculates indicators using upcoming dates.
|
||||
*
|
||||
* @package core_analytics
|
||||
* @copyright 2019 David Monllao {@link http://www.davidmonllao.com}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class upcoming_fortnight extends \core_analytics\local\time_splitting\upcoming_periodic {
|
||||
|
||||
/**
|
||||
* The time splitting method name.
|
||||
* @return \lang_string
|
||||
*/
|
||||
public static function get_name() : \lang_string {
|
||||
return new \lang_string('timesplitting:upcomingfortnight');
|
||||
}
|
||||
|
||||
/**
|
||||
* Every two weeks.
|
||||
* @return \DateInterval
|
||||
*/
|
||||
public function periodicity() {
|
||||
return new \DateInterval('P2W');
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user