MDL-64783 analytics: Reset PAGE after analytics processes

This commit is contained in:
David Monllaó
2019-04-09 00:25:24 +02:00
committed by Eloy Lafuente (stronk7)
parent c9382c1d28
commit 78e77fab2e
5 changed files with 35 additions and 4 deletions
@@ -92,4 +92,17 @@ class helper {
$PAGE->set_title($title);
$PAGE->set_heading($title);
}
/**
* Resets the current page.
*
* Note that this function can only be used by analytics pages that work at the system context.
*
* @return null
*/
public static function reset_page() {
global $PAGE;
$PAGE->reset_theme_and_output();
$PAGE->set_context(\context_system::instance());
}
}
@@ -60,6 +60,10 @@ class predict_models extends \core\task\scheduled_task {
foreach ($models as $model) {
$result = $model->predict();
// Reset the page as some indicators may call external functions that overwrite the page context.
\tool_analytics\output\helper::reset_page();
if ($result) {
echo $OUTPUT->heading(get_string('modelresults', 'tool_analytics', $model->get_target()->get_name()));
$renderer = $PAGE->get_renderer('tool_analytics');
@@ -71,6 +71,10 @@ class train_models extends \core\task\scheduled_task {
}
$result = $model->train();
// Reset the page as some indicators may call external functions that overwrite the page context.
\tool_analytics\output\helper::reset_page();
if ($result) {
echo $OUTPUT->heading(get_string('modelresults', 'tool_analytics', $model->get_target()->get_name()));
@@ -111,6 +111,9 @@ $analyseroptions = array(
// Evaluate its suitability to predict accurately.
$results = $model->evaluate($analyseroptions);
// Reset the page as some indicators may call external functions that overwrite the page context.
\tool_analytics\output\helper::reset_page();
$renderer = $PAGE->get_renderer('tool_analytics');
echo $renderer->render_evaluate_results($results, $model->get_analyser()->get_logs());
+11 -4
View File
@@ -156,8 +156,6 @@ switch ($action) {
case 'evaluate':
confirm_sesskey();
echo $OUTPUT->header();
if ($model->is_static()) {
throw new moodle_exception('errornostaticevaluate', 'tool_analytics');
}
@@ -176,6 +174,12 @@ switch ($action) {
$options['mode'] = 'trainedmodel';
}
$results = $model->evaluate($options);
// We reset the theme and the output as some indicators may be using external functions
// which reset $PAGE.
\tool_analytics\output\helper::reset_page();
echo $OUTPUT->header();
$renderer = $PAGE->get_renderer('tool_analytics');
echo $renderer->render_evaluate_results($results, $model->get_analyser()->get_logs());
break;
@@ -183,8 +187,6 @@ switch ($action) {
case 'getpredictions':
confirm_sesskey();
echo $OUTPUT->header();
if ($onlycli) {
throw new moodle_exception('erroronlycli', 'tool_analytics');
}
@@ -202,6 +204,11 @@ switch ($action) {
$predictlogs = array();
}
// We reset the theme and the output as some indicators may be using external functions
// which reset $PAGE.
\tool_analytics\output\helper::reset_page();
echo $OUTPUT->header();
$renderer = $PAGE->get_renderer('tool_analytics');
echo $renderer->render_get_predictions_results($trainresults, $trainlogs, $predictresults, $predictlogs);
break;