From f19719c198a0b12220a893fe08863b10eae934ad Mon Sep 17 00:00:00 2001 From: David Monllao Date: Mon, 28 Aug 2017 20:57:41 +0200 Subject: [PATCH] MDL-59657 analytics: Option to restrict heavy processes to CLI Default to only CLI. --- admin/settings/analytics.php | 4 +++ .../analytics/classes/output/models_list.php | 25 +++++++++++++++---- .../tool/analytics/lang/en/tool_analytics.php | 2 ++ admin/tool/analytics/model.php | 14 +++++++++++ .../analytics/templates/models_list.mustache | 4 +++ lang/en/analytics.php | 2 ++ version.php | 2 +- 7 files changed, 47 insertions(+), 6 deletions(-) diff --git a/admin/settings/analytics.php b/admin/settings/analytics.php index 17724a35b41..0925130f229 100644 --- a/admin/settings/analytics.php +++ b/admin/settings/analytics.php @@ -97,5 +97,9 @@ if ($hassiteconfig) { } $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 c068b18426b..ebfc4877b9e 100644 --- a/admin/tool/analytics/classes/output/models_list.php +++ b/admin/tool/analytics/classes/output/models_list.php @@ -62,6 +62,12 @@ class models_list implements \renderable, \templatable { $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(); @@ -180,7 +186,7 @@ class models_list implements \renderable, \templatable { $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')); @@ -188,7 +194,7 @@ class models_list implements \renderable, \templatable { } // 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')); @@ -216,9 +222,18 @@ class models_list implements \renderable, \templatable { $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 4922a512486..7ab2785c0f3 100644 --- a/admin/tool/analytics/lang/en/tool_analytics.php +++ b/admin/tool/analytics/lang/en/tool_analytics.php @@ -30,6 +30,7 @@ $string['bettercli'] = 'Evaluating models and generating predictions may involve $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 \'onlycli\' analytics setting'; $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['errornoexport'] = 'Only trained models can be exported'; $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 daf62cf5ba8..b2268f166fe 100644 --- a/admin/tool/analytics/model.php +++ b/admin/tool/analytics/model.php @@ -71,6 +71,12 @@ $PAGE->set_pagelayout('report'); $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 @@ switch ($action) { 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 @@ switch ($action) { 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 49e4a91c9fa..9330c5446d4 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}} +
diff --git a/lang/en/analytics.php b/lang/en/analytics.php index 81fa1bc7055..4b0f8f240c4 100644 --- a/lang/en/analytics.php +++ b/lang/en/analytics.php @@ -73,6 +73,8 @@ $string['noranges'] = 'No predictions yet'; $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 fa899055d9f..08db18ea318 100644 --- a/version.php +++ b/version.php @@ -29,7 +29,7 @@ defined('MOODLE_INTERNAL') || die(); -$version = 2017082400.00; // YYYYMMDD = weekly release date of this DEV branch. +$version = 2017082400.01; // YYYYMMDD = weekly release date of this DEV branch. // RR = release increments - 00 in DEV branches. // .XX = incremental changes.
{{#str}}modelslist, tool_analytics{{/str}}