Skip to content

Commit

Permalink
Merge branch 'MDL-59657_master' of git://github.com/dmonllao/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
danpoltawski authored and David Monllao committed Sep 7, 2017
2 parents 076d95c + f19719c commit 2d64ffe
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 6 deletions.
4 changes: 4 additions & 0 deletions admin/settings/analytics.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,5 +97,9 @@
}
$settings->add(new admin_setting_configdirectory('analytics/modeloutputdir', new lang_string('modeloutputdir', 'analytics'),
new lang_string('modeloutputdirinfo', 'analytics'), $defaultmodeloutputdir));

// Disable web interface evaluation and get predictions.
$settings->add(new admin_setting_configcheckbox('analytics/onlycli', new lang_string('onlycli', 'analytics'),
new lang_string('onlycliinfo', 'analytics'), 1));
}
}
25 changes: 20 additions & 5 deletions admin/tool/analytics/classes/output/models_list.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ public function export_for_template(\renderer_base $output) {

$data = new \stdClass();

$onlycli = get_config('analytics', 'onlycli');
if ($onlycli === false) {
// Default applied if no config found.
$onlycli = 1;
}

$data->models = array();
foreach ($this->models as $model) {
$modeldata = $model->export();
Expand Down Expand Up @@ -182,15 +188,15 @@ public function export_for_template(\renderer_base $output) {
$actionsmenu->add($icon);

// Evaluate machine-learning-based models.
if ($model->get_indicators() && !$model->is_static()) {
if (!$onlycli && $model->get_indicators() && !$model->is_static()) {
$url = new \moodle_url('model.php', array('action' => 'evaluate', 'id' => $model->get_id()));
$icon = new \action_menu_link_secondary($url, new \pix_icon('i/calc', get_string('evaluate', 'tool_analytics')),
get_string('evaluate', 'tool_analytics'));
$actionsmenu->add($icon);
}

// Get predictions.
if ($modeldata->enabled && !empty($modeldata->timesplitting)) {
if (!$onlycli && $modeldata->enabled && !empty($modeldata->timesplitting)) {
$url = new \moodle_url('model.php', array('action' => 'getpredictions', 'id' => $model->get_id()));
$icon = new \action_menu_link_secondary($url, new \pix_icon('i/notifications',
get_string('getpredictions', 'tool_analytics')), get_string('getpredictions', 'tool_analytics'));
Expand Down Expand Up @@ -218,9 +224,18 @@ public function export_for_template(\renderer_base $output) {
$data->models[] = $modeldata;
}

$data->warnings = array(
(object)array('message' => get_string('bettercli', 'tool_analytics'), 'closebutton' => true)
);
if (!$onlycli) {
$data->warnings = array(
(object)array('message' => get_string('bettercli', 'tool_analytics'), 'closebutton' => true)
);
} else {
$url = new \moodle_url('/admin/settings.php', array('section' => 'analyticssettings'),
'id_s_analytics_onlycli');
$data->infos = array(
(object)array('message' => get_string('clievaluationandpredictions', 'tool_analytics', $url->out()),
'closebutton' => true)
);
}

return $data;
}
Expand Down
2 changes: 2 additions & 0 deletions admin/tool/analytics/lang/en/tool_analytics.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
$string['cantguessstartdate'] = 'Can\'t guess the start date';
$string['cantguessenddate'] = 'Can\'t guess the end date';
$string['clienablemodel'] = 'You can enable the model by selecting a time splitting method by its id. Note that you can also enable it later using the web interface (\'none\' to exit)';
$string['clievaluationandpredictions'] = 'A cron task iterates through enabled models and gets predictions. Models evaluation via command line is disabled. You can allow these processes to be executed manually via web interface by enabling <a href="{$a}">\'onlycli\' analytics setting</a>';
$string['editmodel'] = 'Edit "{$a}" model';
$string['edittrainedwarning'] = 'This model has already been trained, note that changing its indicators or its time splitting method will delete its previous predictions and start generating the new ones';
$string['enabled'] = 'Enabled';
Expand All @@ -40,6 +41,7 @@
$string['errornostaticedit'] = 'Models based on assumptions can not be edited';
$string['errornostaticevaluated'] = 'Models based on assumptions can not be evaluated, they are always 100% correct according to how they were defined';
$string['errornostaticlog'] = 'Models based on assumptions can not be evaluated, there is no preformance log';
$string['erroronlycli'] = 'Execution only allowed via command line';
$string['errortrainingdataexport'] = 'The model training data could not be exported';
$string['evaluate'] = 'Evaluate';
$string['evaluatemodel'] = 'Evaluate model';
Expand Down
14 changes: 14 additions & 0 deletions admin/tool/analytics/model.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@
$PAGE->set_title($title);
$PAGE->set_heading($title);

$onlycli = get_config('analytics', 'onlycli');
if ($onlycli === false) {
// Default applied if no config found.
$onlycli = 1;
}

switch ($action) {

case 'enable':
Expand Down Expand Up @@ -131,6 +137,10 @@
throw new moodle_exception('errornostaticevaluate', 'tool_analytics');
}

if ($onlycli) {
throw new moodle_exception('erroronlycli', 'tool_analytics');
}

// Web interface is used by people who can not use CLI nor code stuff, always use
// cached stuff as they will change the model through the web interface as well
// which invalidates the previously analysed stuff.
Expand All @@ -142,6 +152,10 @@
case 'getpredictions':
echo $OUTPUT->header();

if ($onlycli) {
throw new moodle_exception('erroronlycli', 'tool_analytics');
}

$trainresults = $model->train();
$trainlogs = $model->get_analyser()->get_logs();

Expand Down
4 changes: 4 additions & 0 deletions admin/tool/analytics/templates/models_list.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@
{{#warnings}}
{{> core/notification_warning}}
{{/warnings}}
{{#infos}}
{{> core/notification_info}}
{{/infos}}

<div class="box">
<table class="generaltable fullwidth">
<caption>{{#str}}modelslist, tool_analytics{{/str}}</caption>
Expand Down
2 changes: 2 additions & 0 deletions lang/en/analytics.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@
$string['notrainingbasedassumptions'] = 'Models based on assumptions do not need training';
$string['novaliddata'] = 'No valid data available';
$string['novalidsamples'] = 'No valid samples available';
$string['onlycli'] = 'Analytics processes execution via command line only';
$string['onlycliinfo'] = 'Analytics processes like evaluating models, training machine learning algorithms or getting predictions can take some time, they will run as cron tasks and they can be forced via command line. Disable this setting if you want your site managers to be able to run these processes manually via web interface';
$string['predictionsprocessor'] = 'Predictions processor';
$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';
Expand Down
2 changes: 1 addition & 1 deletion version.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

defined('MOODLE_INTERNAL') || die();

$version = 2017090100.00; // YYYYMMDD = weekly release date of this DEV branch.
$version = 2017090400.00; // YYYYMMDD = weekly release date of this DEV branch.
// RR = release increments - 00 in DEV branches.
// .XX = incremental changes.

Expand Down

0 comments on commit 2d64ffe

Please sign in to comment.