MDL-58859 analytics: Fix migration to core bugs and pre-migration issues
authorDavid Monllao <david.monllao@gmail.com>
Thu, 1 Jun 2017 10:42:23 +0000 (12:42 +0200)
committerDavid Monllao <davidm@moodle.com>
Mon, 24 Jul 2017 06:36:17 +0000 (08:36 +0200)
Part of MDL-57791 epic.

15 files changed:
admin/tool/models/classes/analytics/target/course_dropout.php [moved from admin/tool/models/classes/local/target/course_dropout.php with 97% similarity]
admin/tool/models/db/install.php
admin/tool/models/lang/en/tool_models.php
analytics/classes/local/target/base.php
analytics/classes/model.php
analytics/classes/prediction_action.php
lang/en/analytics.php
report/insights/action.php
report/insights/classes/output/predictions_list.php
report/insights/insights.php
report/insights/lang/en/report_insights.php
report/insights/lib.php
report/insights/prediction.php
report/insights/templates/prediction_details.mustache
report/insights/templates/predictions_list.mustache

@@ -22,7 +22,7 @@
  * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  */
 
-namespace tool_models\local\target;
+namespace tool_models\analytics\target;
 
 defined('MOODLE_INTERNAL') || die();
 
@@ -106,12 +106,13 @@ class course_dropout extends \core_analytics\local\target\binary {
             return get_string('nocoursesections', 'tool_models');
         }
 
+        if ($course->get_end() == 0) {
+            // We require time end to be set.
+            return get_string('nocourseendtime', 'tool_models');
+        }
+
         // Ongoing courses data can not be used to train.
         if ($fortraining && !$course->is_finished()) {
-            if ($course->get_end() === 0) {
-                // More specific error.
-                return get_string('nocourseendtime', 'tool_models');
-            }
             return get_string('coursenotyetfinished', 'tool_models');
         }
 
index 894c5e1..9ce7ee9 100644 (file)
@@ -32,7 +32,7 @@ defined('MOODLE_INTERNAL') || die();
 function xmldb_tool_models_install() {
 
     // TODO All of them for the moment, we will define a limited set of them once in core.
-    $target = \core_analytics\manager::get_target('\tool_models\local\target\course_dropout');
+    $target = \core_analytics\manager::get_target('\tool_models\analytics\target\course_dropout');
     $indicators = \core_analytics\manager::get_all_indicators();
 
     // We need the model to be created in order to know all its potential indicators and set them.
index 5c5cf62..df0975b 100644 (file)
@@ -47,7 +47,6 @@ $string['executionresultscli'] = 'Results using {$a->name} (id: {$a->id}) course
 $string['executionresults'] = 'Results using {$a->name} course duration splitting';
 $string['extrainfo'] = 'Info';
 $string['generalerror'] = 'Evaluation error. Status code {$a}';
-
 $string['goodmodel'] = 'This is a good model and it can be used to predict, enable it and execute it to start getting predictions.';
 $string['indicators'] = 'Indicators';
 $string['info'] = 'Info';
@@ -55,6 +54,7 @@ $string['labelstudentdropoutyes'] = 'Student at risk of dropping out';
 $string['labelstudentdropoutno'] = 'Not at risk';
 $string['loginfo'] = 'Log extra info';
 $string['lowaccuracy'] = 'The model accuracy is low';
+$string['modelresults'] = '{$a} results';
 $string['modelslist'] = 'Models list';
 $string['modeltimesplitting'] = 'Time splitting';
 $string['nocompletiondetection'] = 'No method available to detect course completion (no completion nor competencies nor course grade pass)';
@@ -65,16 +65,11 @@ $string['nocoursestudents'] = 'No students';
 $string['nodatatoevaluate'] = 'There is no data to evaluate the model';
 $string['nodatatopredict'] = 'There is no data to use for predictions';
 $string['notdefined'] = 'Not yet defined';
-$string['prediction'] = 'Prediction';
+$string['pluginname'] = 'Analytic models';
 $string['predictionresults'] = 'Prediction results';
-$string['predictions'] = 'Predictions';
 $string['predictmodels'] = 'Predict models';
 $string['predictorresultsin'] = 'Predictor logged information in {$a} directory';
-$string['predictiondetails'] = 'Prediction details';
 $string['predictionprocessfinished'] = 'Prediction process finished';
-
-$string['pluginname'] = 'Analytic models';
-$string['modelresults'] = '{$a} results';
 $string['samestartdate'] = 'Current start date is good';
 $string['sameenddate'] = 'Current end date is good';
 $string['target'] = 'Target';
index 05a273c..2df019b 100644 (file)
@@ -133,7 +133,7 @@ abstract class base extends \core_analytics\calculable {
             foreach ($users as $user) {
 
                 $message = new \core\message\message();
-                $message->component = 'analytics';
+                $message->component = 'moodle';
                 $message->name = 'insights';
 
                 $message->userfrom = get_admin();
index 4ff9629..91dd9d2 100644 (file)
@@ -673,7 +673,7 @@ class model {
 
         // Filters out previous predictions keeping only the last time range one.
         $select = "modelid = :modelid AND contextid = :contextid";
-        $params = array($this->model->id, $context->id);
+        $params = array('modelid' => $this->model->id, 'contextid' => $context->id);
         return $DB->record_exists_select('analytics_predictions', $select, $params);
     }
 
index 41ece10..6a6e9ca 100644 (file)
@@ -53,7 +53,7 @@ class prediction_action {
 
         // We want to track how effective are our suggested actions, we pass users through a script that will log these actions.
         $params = array('action' => $actionname, 'predictionid' => $prediction->get_prediction_data()->id, 'forwardurl' => $actionurl->out(false));
-        $url = new \moodle_url('/reports/insights/action.php', $params);
+        $url = new \moodle_url('/report/insights/action.php', $params);
 
         if ($primary === false) {
             $this->actionlink = new \action_menu_link_secondary($url, $icon, $text);
index 92052c1..330db37 100644 (file)
@@ -97,7 +97,6 @@ $string['indicator:userforumstracking'] = 'User is tracking forums';
 $string['insightmessagesubject'] = 'New insight for "{$a->contextname}": {$a->insightname}';
 $string['insightinfo'] = '{$a->insightname} - {$a->contextname}';
 $string['insightinfomessage'] = 'There are some insights you may find useful. Check out {$a}';
-$string['insights'] = 'Insights';
 $string['invalidtimesplitting'] = 'Model with id {$a} needs a time splitting method before it can be used to train';
 $string['invalidanalysablefortimesplitting'] = 'It can not be analysed using {$a} time splitting method';
 $string['messageprovider:insights'] = 'Insights generated by prediction models';
index a079a96..34913a2 100644 (file)
@@ -22,7 +22,7 @@
  * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  */
 
-require_once(__DIR__ . '/../../../config.php');
+require_once(__DIR__ . '/../../config.php');
 
 $predictionid = required_param('predictionid', PARAM_INT);
 $actionname = required_param('action', PARAM_ALPHANUMEXT);
@@ -62,7 +62,7 @@ if (!isset($actions[$actionname])) {
     throw new \moodle_exception('errorunknownaction', 'report_insights');
 }
 
-$modelready = $model->$model->is_enabled() && $model->is_trained() && $model->predictions_exist($context);
+$modelready = $model->is_enabled() && $model->is_trained() && $model->predictions_exist($context);
 if (!$modelready && !has_capability('moodle/analytics:managemodels', $context)) {
 
     $PAGE->set_pagelayout('report');
index 80fd1c6..67975e4 100644 (file)
@@ -71,7 +71,7 @@ class predictions_list implements \renderable, \templatable {
 
         $data->predictions = array();
         foreach ($predictions as $prediction) {
-            $predictionrenderable = new \core_analytics\output\prediction($prediction, $this->model);
+            $predictionrenderable = new \report_insights\output\prediction($prediction, $this->model);
             $data->predictions[] = $predictionrenderable->export_for_template($output);
         }
 
index 085fb1b..2c46eb6 100644 (file)
@@ -22,7 +22,7 @@
  * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  */
 
-require_once(__DIR__ . '/../../../config.php');
+require_once(__DIR__ . '/../../config.php');
 
 $contextid = required_param('contextid', PARAM_INT);
 $modelid = optional_param('modelid', false, PARAM_INT);
@@ -75,7 +75,7 @@ $model = new \core_analytics\model($modelid);
 $insightinfo = new stdClass();
 $insightinfo->contextname = $context->get_context_name();
 $insightinfo->insightname = $model->get_target()->get_name();
-$title = get_string('insightinfo', 'report_insights', $insightinfo);
+$title = get_string('insightinfo', 'analytics', $insightinfo);
 
 
 if (!$model->is_enabled() && !has_capability('moodle/analytics:managemodels', $context)) {
@@ -88,7 +88,7 @@ $PAGE->set_heading($title);
 
 echo $OUTPUT->header();
 
-$renderable = new \core_analytics\output\predictions_list($model, $context, $othermodels);
+$renderable = new \report_insights\output\predictions_list($model, $context, $othermodels);
 echo $renderer->render($renderable);
 
 echo $OUTPUT->footer();
index 4976a36..bd651a7 100644 (file)
@@ -25,5 +25,9 @@
 
 $string['disabledmodel'] = 'Sorry, this model has been disabled by the administrator';
 $string['errorpredictionnotfound'] = 'Prediction not found';
+$string['insights'] = 'Insights';
 $string['pluginname'] = 'Insights';
+$string['prediction'] = 'Prediction';
+$string['predictiondetails'] = 'Prediction details';
+$string['predictions'] = 'Predictions';
 $string['selectotherinsights'] = 'Select other insights...';
index a4a032c..bb789a3 100644 (file)
@@ -37,8 +37,8 @@ function report_insights_extend_navigation_course($navigation, $course, $context
     if (has_capability('moodle/analytics:listinsights', $context)) {
 
         $cache = \cache::make('core', 'modelswithpredictions');
-        $models = $cache->get($context->id);
-        if ($models === false) {
+        $modelids = $cache->get($context->id);
+        if ($modelids === false) {
             // Fill the cache.
             $models = \core_analytics\manager::get_all_models(true, true, $context);
             $modelids = array_keys($models);
@@ -49,10 +49,7 @@ function report_insights_extend_navigation_course($navigation, $course, $context
             $url = new moodle_url('/report/insights/insights.php', array('contextid' => $context->id));
             $settingsnode = navigation_node::create(get_string('insights', 'report_insights'), $url, navigation_node::TYPE_SETTING,
                 null, null, new pix_icon('i/settings', ''));
-            $reportnode = $navigation->get('coursereports');
-            if (isset($settingsnode) && !empty($reportnode)) {
-                $reportnode->add_node($settingsnode);
-            }
+            $navigation->add_node($settingsnode);
         }
     }
 }
index aad934e..b6707f6 100644 (file)
@@ -22,7 +22,7 @@
  * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  */
 
-require_once(__DIR__ . '/../../../config.php');
+require_once(__DIR__ . '/../../config.php');
 
 $predictionid = required_param('id', PARAM_INT);
 
@@ -46,7 +46,7 @@ if ($context->contextlevel === CONTEXT_MODULE) {
 require_capability('moodle/analytics:listinsights', $context);
 
 $params = array('id' => $predictionobj->id);
-$url = new \moodle_url('/reports/insights/prediction.php', $params);
+$url = new \moodle_url('/report/insights/prediction.php', $params);
 
 $PAGE->set_url($url);
 $PAGE->set_pagelayout('report');
@@ -60,9 +60,9 @@ $prediction = new \core_analytics\prediction($predictionobj, $sampledata);
 $insightinfo = new stdClass();
 $insightinfo->contextname = $context->get_context_name();
 $insightinfo->insightname = $model->get_target()->get_name();
-$title = get_string('insightinfo', 'report_insights', $insightinfo);
+$title = get_string('insightinfo', 'analytics', $insightinfo);
 
-$modelready = $model->$model->is_enabled() && $model->is_trained() && $model->predictions_exist($context);
+$modelready = $model->is_enabled() && $model->is_trained() && $model->predictions_exist($context);
 if (!$modelready && !has_capability('moodle/analytics:managemodels', $context)) {
     echo $renderer->render_model_disabled($insightinfo);
     exit(0);
@@ -73,7 +73,7 @@ $PAGE->set_heading($title);
 
 echo $OUTPUT->header();
 
-$renderable = new \core_analytics\output\prediction($prediction, $model);
+$renderable = new \report_insights\output\prediction($prediction, $model);
 echo $renderer->render($renderable);
 
 echo $OUTPUT->footer();
index f5182aa..9bcd97b 100644 (file)
     * none
 }}
 
-<h2>{{#str}}prediction, analytics{{/str}}</h2>
+<h2>{{#str}}prediction, report_insights{{/str}}</h2>
 {{> report_insights/prediction}}
 
-<h3>{{#str}} predictiondetails, analytics {{/str}}</h3>
+<h3>{{#str}} predictiondetails, report_insights {{/str}}</h3>
 <div class="container prediction-calculations m-t-2">
     {{#calculations}}
         <div class="{{style}}">{{name}} - {{displayvalue}}</div>
index fa2a083..1ab370f 100644 (file)
@@ -39,7 +39,7 @@
     </div>
 {{/modelselector}}
 
-<h3>{{#str}} predictions, analytics {{/str}}</h3>
+<h3>{{#str}} predictions, report_insights {{/str}}</h3>
 <div class="predictions-list">
     {{#predictions}}
         {{> report_insights/prediction}}