Skip to content

Commit

Permalink
Merge branch 'MDL-65177_master' of git://github.com/dmonllao/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
stronk7 committed Apr 10, 2019
2 parents 30a09fc + 5bbdc42 commit 83b2cba
Show file tree
Hide file tree
Showing 8 changed files with 187 additions and 61 deletions.
73 changes: 41 additions & 32 deletions admin/tool/analytics/classes/output/form/edit_model.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,14 @@ public function definition() {

$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) {
Expand All @@ -64,42 +65,48 @@ public function definition() {
$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']);
Expand Down Expand Up @@ -130,13 +137,15 @@ public function validation($data, $files) {
}
}

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);
}
}
}
}
Expand Down
29 changes: 15 additions & 14 deletions admin/tool/analytics/classes/output/models_list.php
Original file line number Diff line number Diff line change
Expand Up @@ -229,12 +229,10 @@ public function export_for_template(\renderer_base $output) {
}

// 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)) {
Expand Down Expand Up @@ -299,14 +297,17 @@ public function export_for_template(\renderer_base $output) {
$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);

Expand Down
3 changes: 2 additions & 1 deletion admin/tool/analytics/createmodel.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,10 @@

$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);
Expand Down
1 change: 0 additions & 1 deletion admin/tool/analytics/lang/en/tool_analytics.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
$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';
Expand Down
32 changes: 19 additions & 13 deletions admin/tool/analytics/model.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,21 +103,19 @@
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()
Expand All @@ -129,14 +127,22 @@

} 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);
}
Expand Down
4 changes: 4 additions & 0 deletions lang/en/moodle.php
Original file line number Diff line number Diff line change
Expand Up @@ -2022,6 +2022,10 @@
$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';
Expand Down
53 changes: 53 additions & 0 deletions lib/classes/analytics/time_splitting/upcoming_3_days.php
Original file line number Diff line number Diff line change
@@ -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 changes: 53 additions & 0 deletions lib/classes/analytics/time_splitting/upcoming_fortnight.php
Original file line number Diff line number Diff line change
@@ -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');
}
}

0 comments on commit 83b2cba

Please sign in to comment.