Skip to content

Commit

Permalink
MDL-59574 tool_analytics: Add model listing to evaluate_model cli script
Browse files Browse the repository at this point in the history
  • Loading branch information
ankitagarwal committed Nov 28, 2017
1 parent 0164f50 commit 556cb98
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 2 deletions.
55 changes: 55 additions & 0 deletions admin/tool/analytics/classes/clihelper.php
@@ -0,0 +1,55 @@
<?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/>.

/**
* 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";
}
}
}
6 changes: 4 additions & 2 deletions admin/tool/analytics/cli/evaluate_model.php
Expand Up @@ -31,6 +31,7 @@
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)
Expand All @@ -47,6 +48,7 @@
array(
'help' => false,
'modelid' => false,
'list' => false,
'timesplitting' => false,
'reuse-prev-analysed' => true,
'non-interactive' => false,
Expand All @@ -62,8 +64,8 @@
exit(0);
}

if ($options['modelid'] === false) {
echo $help;
if ($options['list'] || $options['modelid'] === false) {
\tool_analytics\clihelper::list_models();
exit(0);
}

Expand Down
2 changes: 2 additions & 0 deletions admin/tool/analytics/lang/en/tool_analytics.php
Expand Up @@ -34,6 +34,7 @@
$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 <a href="{$a}">\'onlycli\'</a> 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';
Expand Down Expand Up @@ -66,6 +67,7 @@
$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';
Expand Down

0 comments on commit 556cb98

Please sign in to comment.