diff --git a/admin/settings/analytics.php b/admin/settings/analytics.php index 17724a35b416..0925130f2299 100644 --- a/admin/settings/analytics.php +++ b/admin/settings/analytics.php @@ -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)); } } diff --git a/admin/tool/analytics/classes/output/models_list.php b/admin/tool/analytics/classes/output/models_list.php index b074ae381544..b05e102099c8 100644 --- a/admin/tool/analytics/classes/output/models_list.php +++ b/admin/tool/analytics/classes/output/models_list.php @@ -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(); @@ -182,7 +188,7 @@ 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')); @@ -190,7 +196,7 @@ public function export_for_template(\renderer_base $output) { } // 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')); @@ -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; } diff --git a/admin/tool/analytics/lang/en/tool_analytics.php b/admin/tool/analytics/lang/en/tool_analytics.php index 4922a512486d..7ab2785c0f36 100644 --- a/admin/tool/analytics/lang/en/tool_analytics.php +++ b/admin/tool/analytics/lang/en/tool_analytics.php @@ -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'; @@ -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'; diff --git a/admin/tool/analytics/model.php b/admin/tool/analytics/model.php index daf62cf5ba81..b2268f166fe4 100644 --- a/admin/tool/analytics/model.php +++ b/admin/tool/analytics/model.php @@ -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': @@ -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. @@ -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(); diff --git a/admin/tool/analytics/templates/models_list.mustache b/admin/tool/analytics/templates/models_list.mustache index 49e4a91c9fa1..9330c5446d4d 100644 --- a/admin/tool/analytics/templates/models_list.mustache +++ b/admin/tool/analytics/templates/models_list.mustache @@ -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> diff --git a/lang/en/analytics.php b/lang/en/analytics.php index 2af347e131f8..8d5dc4fe453d 100644 --- a/lang/en/analytics.php +++ b/lang/en/analytics.php @@ -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'; diff --git a/version.php b/version.php index 65f22077d861..d47bbf4c3d40 100644 --- a/version.php +++ b/version.php @@ -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.