From 556cb98d1638b9d9a07ec6ca28b2729fc2b0560d Mon Sep 17 00:00:00 2001 From: Ankit Agarwal Date: Mon, 13 Nov 2017 15:47:58 +0530 Subject: [PATCH] MDL-59574 tool_analytics: Add model listing to evaluate_model cli script --- admin/tool/analytics/classes/clihelper.php | 55 +++++++++++++++++++ admin/tool/analytics/cli/evaluate_model.php | 6 +- .../tool/analytics/lang/en/tool_analytics.php | 2 + 3 files changed, 61 insertions(+), 2 deletions(-) create mode 100644 admin/tool/analytics/classes/clihelper.php diff --git a/admin/tool/analytics/classes/clihelper.php b/admin/tool/analytics/classes/clihelper.php new file mode 100644 index 00000000000..c46e6fc8239 --- /dev/null +++ b/admin/tool/analytics/classes/clihelper.php @@ -0,0 +1,55 @@ +. + +/** + * Helper class that contains helper functions for cli scripts. + * + * @package tool_analytics + * @copyright 2017 onwards Ankit Agarwal + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +namespace tool_analytics; + +defined('MOODLE_INTERNAL') || die(); + +/** + * Helper class that contains helper functions for cli scripts. + * + * @package tool_analytics + * @copyright 2017 onwards Ankit Agarwal + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class clihelper { + + /** + * List all models in the system. To be used from cli scripts. + * + * @return void + */ + public static function list_models() { + cli_heading("List of models"); + echo str_pad(get_string('modelid', 'tool_analytics'), 15, ' ') . ' ' . str_pad(get_string('name'), 50, ' ') . + ' ' . str_pad(get_string('status'), 15, ' ') . "\n"; + $models = \core_analytics\manager::get_all_models(); + foreach ($models as $model) { + $modelid = $model->get_id(); + $isenabled = $model->is_enabled() ? get_string('enabled', 'tool_analytics') : get_string('disabled', 'tool_analytics'); + $name = $model->get_target()->get_name(); + echo str_pad($modelid, 15, ' ') . ' ' . str_pad($name, 50, ' ') . ' ' . str_pad($isenabled, 15, ' ') . "\n"; + } + } +} \ No newline at end of file diff --git a/admin/tool/analytics/cli/evaluate_model.php b/admin/tool/analytics/cli/evaluate_model.php index 5319f0d8a27..25d182fa038 100644 --- a/admin/tool/analytics/cli/evaluate_model.php +++ b/admin/tool/analytics/cli/evaluate_model.php @@ -31,6 +31,7 @@ $help = "Evaluates the provided model. Options: --modelid Model id +--list List models --non-interactive Not interactive questions --timesplitting Restrict the evaluation to 1 single time splitting method (Optional) --filter Analyser dependant. e.g. A courseid would evaluate the model using a single course (Optional) @@ -47,6 +48,7 @@ list($options, $unrecognized) = cli_get_params( array( 'help' => false, 'modelid' => false, + 'list' => false, 'timesplitting' => false, 'reuse-prev-analysed' => true, 'non-interactive' => false, @@ -62,8 +64,8 @@ if ($options['help']) { exit(0); } -if ($options['modelid'] === false) { - echo $help; +if ($options['list'] || $options['modelid'] === false) { + \tool_analytics\clihelper::list_models(); exit(0); } diff --git a/admin/tool/analytics/lang/en/tool_analytics.php b/admin/tool/analytics/lang/en/tool_analytics.php index f5c1014e8a3..68ca3475f6d 100644 --- a/admin/tool/analytics/lang/en/tool_analytics.php +++ b/admin/tool/analytics/lang/en/tool_analytics.php @@ -34,6 +34,7 @@ $string['clearmodelpredictions'] = 'Are you sure you want to clear all "{$a}" pr $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 scheduled task iterates through enabled models and gets predictions. Models evaluation via the web interface is disabled. You can allow these processes to be executed manually via the web interface by disabling the \'onlycli\' analytics setting.'; $string['clievaluationandpredictionsnoadmin'] = 'A scheduled task iterates through enabled models and gets predictions. Models evaluation via the web interface is disabled. It may be enabled by a site administrator.'; +$string['disabled'] = 'Disabled'; $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 new predictions.'; $string['enabled'] = 'Enabled'; @@ -66,6 +67,7 @@ $string['invalidanalysablestable'] = 'Invalid site analysable elements table'; $string['invalidprediction'] = 'Invalid to get predictions'; $string['invalidtraining'] = 'Invalid to train the model'; $string['loginfo'] = 'Log extra info'; +$string['modelid'] = 'Model id'; $string['modelinvalidanalysables'] = 'Invalid analysable elements for "{$a}" model'; $string['modelresults'] = '{$a} results'; $string['modeltimesplitting'] = 'Time splitting';