MDL-58859 analytics: Fix migration to core bugs and pre-migration issues

Part of MDL-57791 epic.
This commit is contained in:
David Monllao 2017-06-01 12:42:23 +02:00 committed by David Monllao
parent 52c0a11022
commit 6ec2ae0f87
15 changed files with 33 additions and 37 deletions

View File

@ -22,7 +22,7 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @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(); defined('MOODLE_INTERNAL') || die();
@ -106,12 +106,13 @@ class course_dropout extends \core_analytics\local\target\binary {
return get_string('nocoursesections', 'tool_models'); 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. // Ongoing courses data can not be used to train.
if ($fortraining && !$course->is_finished()) { 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'); return get_string('coursenotyetfinished', 'tool_models');
} }

View File

@ -32,7 +32,7 @@ defined('MOODLE_INTERNAL') || die();
function xmldb_tool_models_install() { function xmldb_tool_models_install() {
// TODO All of them for the moment, we will define a limited set of them once in core. // 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(); $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. // We need the model to be created in order to know all its potential indicators and set them.

View 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['executionresults'] = 'Results using {$a->name} course duration splitting';
$string['extrainfo'] = 'Info'; $string['extrainfo'] = 'Info';
$string['generalerror'] = 'Evaluation error. Status code {$a}'; $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['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['indicators'] = 'Indicators';
$string['info'] = 'Info'; $string['info'] = 'Info';
@ -55,6 +54,7 @@ $string['labelstudentdropoutyes'] = 'Student at risk of dropping out';
$string['labelstudentdropoutno'] = 'Not at risk'; $string['labelstudentdropoutno'] = 'Not at risk';
$string['loginfo'] = 'Log extra info'; $string['loginfo'] = 'Log extra info';
$string['lowaccuracy'] = 'The model accuracy is low'; $string['lowaccuracy'] = 'The model accuracy is low';
$string['modelresults'] = '{$a} results';
$string['modelslist'] = 'Models list'; $string['modelslist'] = 'Models list';
$string['modeltimesplitting'] = 'Time splitting'; $string['modeltimesplitting'] = 'Time splitting';
$string['nocompletiondetection'] = 'No method available to detect course completion (no completion nor competencies nor course grade pass)'; $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['nodatatoevaluate'] = 'There is no data to evaluate the model';
$string['nodatatopredict'] = 'There is no data to use for predictions'; $string['nodatatopredict'] = 'There is no data to use for predictions';
$string['notdefined'] = 'Not yet defined'; $string['notdefined'] = 'Not yet defined';
$string['prediction'] = 'Prediction'; $string['pluginname'] = 'Analytic models';
$string['predictionresults'] = 'Prediction results'; $string['predictionresults'] = 'Prediction results';
$string['predictions'] = 'Predictions';
$string['predictmodels'] = 'Predict models'; $string['predictmodels'] = 'Predict models';
$string['predictorresultsin'] = 'Predictor logged information in {$a} directory'; $string['predictorresultsin'] = 'Predictor logged information in {$a} directory';
$string['predictiondetails'] = 'Prediction details';
$string['predictionprocessfinished'] = 'Prediction process finished'; $string['predictionprocessfinished'] = 'Prediction process finished';
$string['pluginname'] = 'Analytic models';
$string['modelresults'] = '{$a} results';
$string['samestartdate'] = 'Current start date is good'; $string['samestartdate'] = 'Current start date is good';
$string['sameenddate'] = 'Current end date is good'; $string['sameenddate'] = 'Current end date is good';
$string['target'] = 'Target'; $string['target'] = 'Target';

View File

@ -133,7 +133,7 @@ abstract class base extends \core_analytics\calculable {
foreach ($users as $user) { foreach ($users as $user) {
$message = new \core\message\message(); $message = new \core\message\message();
$message->component = 'analytics'; $message->component = 'moodle';
$message->name = 'insights'; $message->name = 'insights';
$message->userfrom = get_admin(); $message->userfrom = get_admin();

View File

@ -673,7 +673,7 @@ class model {
// Filters out previous predictions keeping only the last time range one. // Filters out previous predictions keeping only the last time range one.
$select = "modelid = :modelid AND contextid = :contextid"; $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); return $DB->record_exists_select('analytics_predictions', $select, $params);
} }

View 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. // 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)); $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) { if ($primary === false) {
$this->actionlink = new \action_menu_link_secondary($url, $icon, $text); $this->actionlink = new \action_menu_link_secondary($url, $icon, $text);

View File

@ -97,7 +97,6 @@ $string['indicator:userforumstracking'] = 'User is tracking forums';
$string['insightmessagesubject'] = 'New insight for "{$a->contextname}": {$a->insightname}'; $string['insightmessagesubject'] = 'New insight for "{$a->contextname}": {$a->insightname}';
$string['insightinfo'] = '{$a->insightname} - {$a->contextname}'; $string['insightinfo'] = '{$a->insightname} - {$a->contextname}';
$string['insightinfomessage'] = 'There are some insights you may find useful. Check out {$a}'; $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['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['invalidanalysablefortimesplitting'] = 'It can not be analysed using {$a} time splitting method';
$string['messageprovider:insights'] = 'Insights generated by prediction models'; $string['messageprovider:insights'] = 'Insights generated by prediction models';

View File

@ -22,7 +22,7 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @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); $predictionid = required_param('predictionid', PARAM_INT);
$actionname = required_param('action', PARAM_ALPHANUMEXT); $actionname = required_param('action', PARAM_ALPHANUMEXT);
@ -62,7 +62,7 @@ if (!isset($actions[$actionname])) {
throw new \moodle_exception('errorunknownaction', 'report_insights'); 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)) { if (!$modelready && !has_capability('moodle/analytics:managemodels', $context)) {
$PAGE->set_pagelayout('report'); $PAGE->set_pagelayout('report');

View File

@ -71,7 +71,7 @@ class predictions_list implements \renderable, \templatable {
$data->predictions = array(); $data->predictions = array();
foreach ($predictions as $prediction) { 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); $data->predictions[] = $predictionrenderable->export_for_template($output);
} }

View File

@ -22,7 +22,7 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @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); $contextid = required_param('contextid', PARAM_INT);
$modelid = optional_param('modelid', false, PARAM_INT); $modelid = optional_param('modelid', false, PARAM_INT);
@ -75,7 +75,7 @@ $model = new \core_analytics\model($modelid);
$insightinfo = new stdClass(); $insightinfo = new stdClass();
$insightinfo->contextname = $context->get_context_name(); $insightinfo->contextname = $context->get_context_name();
$insightinfo->insightname = $model->get_target()->get_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)) { if (!$model->is_enabled() && !has_capability('moodle/analytics:managemodels', $context)) {
@ -88,7 +88,7 @@ $PAGE->set_heading($title);
echo $OUTPUT->header(); 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 $renderer->render($renderable);
echo $OUTPUT->footer(); echo $OUTPUT->footer();

View File

@ -25,5 +25,9 @@
$string['disabledmodel'] = 'Sorry, this model has been disabled by the administrator'; $string['disabledmodel'] = 'Sorry, this model has been disabled by the administrator';
$string['errorpredictionnotfound'] = 'Prediction not found'; $string['errorpredictionnotfound'] = 'Prediction not found';
$string['insights'] = 'Insights';
$string['pluginname'] = 'Insights'; $string['pluginname'] = 'Insights';
$string['prediction'] = 'Prediction';
$string['predictiondetails'] = 'Prediction details';
$string['predictions'] = 'Predictions';
$string['selectotherinsights'] = 'Select other insights...'; $string['selectotherinsights'] = 'Select other insights...';

View File

@ -37,8 +37,8 @@ function report_insights_extend_navigation_course($navigation, $course, $context
if (has_capability('moodle/analytics:listinsights', $context)) { if (has_capability('moodle/analytics:listinsights', $context)) {
$cache = \cache::make('core', 'modelswithpredictions'); $cache = \cache::make('core', 'modelswithpredictions');
$models = $cache->get($context->id); $modelids = $cache->get($context->id);
if ($models === false) { if ($modelids === false) {
// Fill the cache. // Fill the cache.
$models = \core_analytics\manager::get_all_models(true, true, $context); $models = \core_analytics\manager::get_all_models(true, true, $context);
$modelids = array_keys($models); $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)); $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, $settingsnode = navigation_node::create(get_string('insights', 'report_insights'), $url, navigation_node::TYPE_SETTING,
null, null, new pix_icon('i/settings', '')); null, null, new pix_icon('i/settings', ''));
$reportnode = $navigation->get('coursereports'); $navigation->add_node($settingsnode);
if (isset($settingsnode) && !empty($reportnode)) {
$reportnode->add_node($settingsnode);
}
} }
} }
} }

View File

@ -22,7 +22,7 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @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); $predictionid = required_param('id', PARAM_INT);
@ -46,7 +46,7 @@ if ($context->contextlevel === CONTEXT_MODULE) {
require_capability('moodle/analytics:listinsights', $context); require_capability('moodle/analytics:listinsights', $context);
$params = array('id' => $predictionobj->id); $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_url($url);
$PAGE->set_pagelayout('report'); $PAGE->set_pagelayout('report');
@ -60,9 +60,9 @@ $prediction = new \core_analytics\prediction($predictionobj, $sampledata);
$insightinfo = new stdClass(); $insightinfo = new stdClass();
$insightinfo->contextname = $context->get_context_name(); $insightinfo->contextname = $context->get_context_name();
$insightinfo->insightname = $model->get_target()->get_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)) { if (!$modelready && !has_capability('moodle/analytics:managemodels', $context)) {
echo $renderer->render_model_disabled($insightinfo); echo $renderer->render_model_disabled($insightinfo);
exit(0); exit(0);
@ -73,7 +73,7 @@ $PAGE->set_heading($title);
echo $OUTPUT->header(); echo $OUTPUT->header();
$renderable = new \core_analytics\output\prediction($prediction, $model); $renderable = new \report_insights\output\prediction($prediction, $model);
echo $renderer->render($renderable); echo $renderer->render($renderable);
echo $OUTPUT->footer(); echo $OUTPUT->footer();

View File

@ -29,10 +29,10 @@
* none * none
}} }}
<h2>{{#str}}prediction, analytics{{/str}}</h2> <h2>{{#str}}prediction, report_insights{{/str}}</h2>
{{> report_insights/prediction}} {{> report_insights/prediction}}
<h3>{{#str}} predictiondetails, analytics {{/str}}</h3> <h3>{{#str}} predictiondetails, report_insights {{/str}}</h3>
<div class="container prediction-calculations m-t-2"> <div class="container prediction-calculations m-t-2">
{{#calculations}} {{#calculations}}
<div class="{{style}}">{{name}} - {{displayvalue}}</div> <div class="{{style}}">{{name}} - {{displayvalue}}</div>

View File

@ -39,7 +39,7 @@
</div> </div>
{{/modelselector}} {{/modelselector}}
<h3>{{#str}} predictions, analytics {{/str}}</h3> <h3>{{#str}} predictions, report_insights {{/str}}</h3>
<div class="predictions-list"> <div class="predictions-list">
{{#predictions}} {{#predictions}}
{{> report_insights/prediction}} {{> report_insights/prediction}}