Skip to content

Commit

Permalink
MDL-58859 analytics: Fix migration to core bugs and pre-migration issues
Browse files Browse the repository at this point in the history
Part of MDL-57791 epic.
  • Loading branch information
dmonllao authored and David Monllao committed Jul 24, 2017
1 parent 52c0a11 commit 6ec2ae0
Show file tree
Hide file tree
Showing 15 changed files with 33 additions and 37 deletions.
Expand Up @@ -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();

Expand Down Expand Up @@ -106,12 +106,13 @@ public function is_valid_analysable(\core_analytics\analysable $course, $fortrai
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');
}

Expand Down
2 changes: 1 addition & 1 deletion admin/tool/models/db/install.php
Expand Up @@ -32,7 +32,7 @@
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.
Expand Down
9 changes: 2 additions & 7 deletions admin/tool/models/lang/en/tool_models.php
Expand Up @@ -47,14 +47,14 @@
$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';
$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)';
Expand All @@ -65,16 +65,11 @@
$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';
Expand Down
2 changes: 1 addition & 1 deletion analytics/classes/local/target/base.php
Expand Up @@ -133,7 +133,7 @@ public function generate_insights($modelid, $samplecontexts) {
foreach ($users as $user) {

$message = new \core\message\message();
$message->component = 'analytics';
$message->component = 'moodle';
$message->name = 'insights';

$message->userfrom = get_admin();
Expand Down
2 changes: 1 addition & 1 deletion analytics/classes/model.php
Expand Up @@ -673,7 +673,7 @@ public function predictions_exist(\context $context) {

// 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);
}

Expand Down
2 changes: 1 addition & 1 deletion analytics/classes/prediction_action.php
Expand Up @@ -53,7 +53,7 @@ public function __construct($actionname, \core_analytics\prediction $prediction,

// 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);
Expand Down
1 change: 0 additions & 1 deletion lang/en/analytics.php
Expand Up @@ -97,7 +97,6 @@
$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';
Expand Down
4 changes: 2 additions & 2 deletions report/insights/action.php
Expand Up @@ -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);
Expand Down Expand Up @@ -62,7 +62,7 @@
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');
Expand Down
2 changes: 1 addition & 1 deletion report/insights/classes/output/predictions_list.php
Expand Up @@ -71,7 +71,7 @@ public function export_for_template(\renderer_base $output) {

$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);
}

Expand Down
6 changes: 3 additions & 3 deletions report/insights/insights.php
Expand Up @@ -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);
Expand Down Expand Up @@ -75,7 +75,7 @@
$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)) {
Expand All @@ -88,7 +88,7 @@

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();
4 changes: 4 additions & 0 deletions report/insights/lang/en/report_insights.php
Expand Up @@ -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...';
9 changes: 3 additions & 6 deletions report/insights/lib.php
Expand Up @@ -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);
Expand All @@ -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);
}
}
}
10 changes: 5 additions & 5 deletions report/insights/prediction.php
Expand Up @@ -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);

Expand All @@ -46,7 +46,7 @@
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');
Expand All @@ -60,9 +60,9 @@
$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);
Expand All @@ -73,7 +73,7 @@

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();
4 changes: 2 additions & 2 deletions report/insights/templates/prediction_details.mustache
Expand Up @@ -29,10 +29,10 @@
* 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>
Expand Down
2 changes: 1 addition & 1 deletion report/insights/templates/predictions_list.mustache
Expand Up @@ -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}}
Expand Down

0 comments on commit 6ec2ae0

Please sign in to comment.