Merge branch 'MDL-65177_master' of git://github.com/dmonllao/moodle

This commit is contained in:
Eloy Lafuente (stronk7) 2019-04-10 17:47:56 +02:00
commit 83b2cbad02
8 changed files with 187 additions and 61 deletions

View File

@ -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,6 +65,8 @@ class edit_model extends \moodleform {
$mform->addRule('target', get_string('required'), 'required', null, 'client');
}
// Indicators.
if (!$this->_customdata['staticmodel']) {
$indicators = array();
foreach ($this->_customdata['indicators'] as $classname => $indicator) {
$optionname = \tool_analytics\output\helper::class_to_option($classname);
@ -75,16 +78,19 @@ class edit_model extends \moodleform {
$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');
// Predictions processor.
if (!$this->_customdata['staticmodel']) {
$defaultprocessor = \core_analytics\manager::get_predictions_processor_name(
\core_analytics\manager::get_predictions_processor()
);
@ -100,6 +106,7 @@ class edit_model extends \moodleform {
$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,6 +137,7 @@ class edit_model extends \moodleform {
}
}
if (!$this->_customdata['staticmodel']) {
if (empty($data['indicators'])) {
$errors['indicators'] = get_string('errornoindicators', 'analytics');
} else {
@ -140,6 +148,7 @@ class edit_model extends \moodleform {
}
}
}
}
if (!empty($data['enabled']) && empty($data['timesplitting'])) {
$errors['enabled'] = get_string('errorcantenablenotimesplitting', 'tool_analytics');

View File

@ -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);
}
// Enable / disable.
if ($model->is_enabled() || !empty($modeldata->timesplitting)) {
@ -299,6 +297,8 @@ class models_list implements \renderable, \templatable {
$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';
@ -307,6 +307,7 @@ class models_list implements \renderable, \templatable {
get_string('delete', 'tool_analytics')), get_string('delete', 'tool_analytics'),
['data-action-id' => $actionid]);
$actionsmenu->add($icon);
}
$modeldata->actions = $actionsmenu->export_for_template($output);

View File

@ -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);

View File

@ -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';

View File

@ -103,21 +103,19 @@ switch ($action) {
case 'delete':
confirm_sesskey();
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()) {
$timesplitting = \tool_analytics\output\helper::option_to_class($data->timesplitting);
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);
}
$timesplitting = \tool_analytics\output\helper::option_to_class($data->timesplitting);
$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);
}

View File

@ -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';

View 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');
}
}

View 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');
}
}