diff --git a/admin/tool/analytics/classes/output/invalid_analysables.php b/admin/tool/analytics/classes/output/invalid_analysables.php
new file mode 100644
index 00000000000..35a6f90962b
--- /dev/null
+++ b/admin/tool/analytics/classes/output/invalid_analysables.php
@@ -0,0 +1,158 @@
+.
+
+/**
+ * Invalid analysables renderable.
+ *
+ * @package tool_analytics
+ * @copyright 2017 David Monllao {@link http://www.davidmonllao.com}
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+namespace tool_analytics\output;
+
+defined('MOODLE_INTERNAL') || die;
+
+/**
+ * Invalid analysables renderable.
+ *
+ * @package tool_analytics
+ * @copyright 2017 David Monllao {@link http://www.davidmonllao.com}
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+class invalid_analysables implements \renderable, \templatable {
+
+ /**
+ * @var \core_analytics\model
+ */
+ protected $model = null;
+
+ /**
+ * @var int
+ */
+ protected $page = 0;
+
+ /**
+ * @var int
+ */
+ protected $perpage = 0;
+
+ /**
+ * Inits the invalid analysables renderable.
+ *
+ * @param \core_analytics\model $model
+ * @param int $page
+ * @param int $perpage
+ * @return \stdClass
+ */
+ public function __construct(\core_analytics\model $model, $page, $perpage) {
+
+ $this->model = $model;
+ $this->page = $page;
+ $this->perpage = $perpage;
+ }
+
+ /**
+ * Export the data.
+ *
+ * @param \renderer_base $output
+ * @return \stdClass
+ */
+ public function export_for_template(\renderer_base $output) {
+ global $PAGE;
+
+ $offset = $this->page * $this->perpage;
+
+ $analysables = $this->model->get_analyser(['evaluation' => true])->get_analysables();
+
+ $skipped = 0;
+ $enoughresults = false;
+ $morepages = false;
+ $results = array();
+ foreach ($analysables as $key => $analysable) {
+
+ $validtraining = $this->model->get_target()->is_valid_analysable($analysable, true);
+ if ($validtraining === true) {
+ if ($this->model->is_static()) {
+ // We still want to show this analysable if it is not valid to get predictions.
+ $validtraining = get_string('notrainingbasedassumptions', 'analytics');
+ } else {
+ // We skip analysables that are valid for training or valid for prediction.
+ continue;
+ }
+ }
+
+ $validprediction = $this->model->get_target()->is_valid_analysable($analysable, false);
+ if ($validprediction === true) {
+ // We skip analysables that are valid for training or valid for prediction.
+ continue;
+ }
+
+ if ($offset && $skipped < $offset) {
+ $skipped++;
+ continue;
+ }
+
+ // Add a new results if we don't have enough yet.
+ if (!$enoughresults) {
+ $results[$analysable->get_id()] = array($analysable, $validtraining, $validprediction);
+ if ($this->perpage && count($results) === $this->perpage) {
+ $enoughresults = true;
+ }
+ } else {
+ // Confirmed that we have results we can not fit into this page.
+ $morepages = true;
+ break;
+ }
+
+ unset($analysables[$key]);
+ }
+
+ // Prepare the context object.
+ $data = new \stdClass();
+ $data->modelname = $this->model->get_target()->get_name();
+
+ if ($this->page > 0) {
+ $prev = clone $PAGE->url;
+ $prev->param('page', $this->page - 1);
+ $button = new \single_button($prev, get_string('previouspage', 'tool_analytics'), 'get');
+ $data->prev = $button->export_for_template($output);
+ }
+ if ($morepages) {
+ $next = clone $PAGE->url;
+ $next->param('page', $this->page + 1);
+ $button = new \single_button($next, get_string('nextpage', 'tool_analytics'), 'get');
+ $data->next = $button->export_for_template($output);
+ }
+
+ $data->analysables = [];
+ foreach ($results as list($analysable, $validtraining, $validprediction)) {
+ $obj = new \stdClass();
+ $obj->url = \html_writer::link($analysable->get_context()->get_url(), $analysable->get_name(),
+ array('target' => '_blank'));
+
+ if ($validtraining !== true) {
+ $obj->validtraining = $validtraining;
+ }
+ if ($validprediction !== true) {
+ $obj->validprediction = $validprediction;
+ }
+ $data->analysables[] = $obj;
+ }
+
+ return $data;
+ }
+}
diff --git a/admin/tool/analytics/classes/output/models_list.php b/admin/tool/analytics/classes/output/models_list.php
index cc499ef5345..ad326a6ecf7 100644
--- a/admin/tool/analytics/classes/output/models_list.php
+++ b/admin/tool/analytics/classes/output/models_list.php
@@ -230,6 +230,16 @@ class models_list implements \renderable, \templatable {
$actionsmenu->add($icon);
}
+ // Invalid analysables.
+ $analyser = $model->get_analyser();
+ if (!$analyser instanceof \core_analytics\local\analyser\sitewide) {
+ $urlparams['action'] = 'invalidanalysables';
+ $url = new \moodle_url('model.php', $urlparams);
+ $pix = new \pix_icon('i/report', get_string('invalidanalysables', 'tool_analytics'));
+ $icon = new \action_menu_link_secondary($url, $pix, get_string('invalidanalysables', 'tool_analytics'));
+ $actionsmenu->add($icon);
+ }
+
// Clear model.
if (!empty($predictioncontexts)) {
$actionid = 'clear-' . $model->get_id();
diff --git a/admin/tool/analytics/classes/output/renderer.php b/admin/tool/analytics/classes/output/renderer.php
index 628b097f264..4201482df14 100644
--- a/admin/tool/analytics/classes/output/renderer.php
+++ b/admin/tool/analytics/classes/output/renderer.php
@@ -207,4 +207,15 @@ class renderer extends plugin_renderer_base {
return $output;
}
+
+ /**
+ * Defer to template.
+ *
+ * @param \tool_analytics\output\invalid_analysables $invalidanalysables
+ * @return string HTML
+ */
+ protected function render_invalid_analysables(\tool_analytics\output\invalid_analysables $invalidanalysables) {
+ $data = $invalidanalysables->export_for_template($this);
+ return parent::render_from_template('tool_analytics/invalid_analysables', $data);
+ }
}
diff --git a/admin/tool/analytics/lang/en/tool_analytics.php b/admin/tool/analytics/lang/en/tool_analytics.php
index e1362fdca97..c4f0e5ae4f5 100644
--- a/admin/tool/analytics/lang/en/tool_analytics.php
+++ b/admin/tool/analytics/lang/en/tool_analytics.php
@@ -59,9 +59,16 @@ $string['goodmodel'] = 'This is a good model for using to obtain predictions. En
$string['indicators'] = 'Indicators';
$string['info'] = 'Info';
$string['insights'] = 'Insights';
+$string['invalidanalysables'] = 'Invalid site elements';
+$string['invalidanalysablesinfo'] = 'This pages lists this site analysable elements that can not be used by this prediction model. The listed elements can not be used neither to train the prediction model nor the prediction model can get predictions for them.';
+$string['invalidanalysablestable'] = 'Invalid site analysable elements table';
+$string['invalidprediction'] = 'Invalid to get predictions';
+$string['invalidtraining'] = 'Invalid to train the model';
$string['loginfo'] = 'Log extra info';
+$string['modelinvalidanalysables'] = 'Invalid analysable elements for "{$a}" model';
$string['modelresults'] = '{$a} results';
$string['modeltimesplitting'] = 'Time splitting';
+$string['nextpage'] = 'Next page';
$string['nodatatoevaluate'] = 'There is no data to evaluate the model';
$string['nodatatopredict'] = 'No new elements to get predictions for';
$string['nodatatotrain'] = 'There is no new data that can be used for training';
@@ -71,6 +78,7 @@ $string['predictionresults'] = 'Prediction results';
$string['predictmodels'] = 'Predict models';
$string['predictorresultsin'] = 'Predictor logged information in {$a} directory';
$string['predictionprocessfinished'] = 'Prediction process finished';
+$string['previouspage'] = 'Previous page';
$string['samestartdate'] = 'Current start date is good';
$string['sameenddate'] = 'Current end date is good';
$string['target'] = 'Target';
diff --git a/admin/tool/analytics/model.php b/admin/tool/analytics/model.php
index e418b4656bb..58f11292bd4 100644
--- a/admin/tool/analytics/model.php
+++ b/admin/tool/analytics/model.php
@@ -63,6 +63,9 @@ switch ($action) {
case 'clear':
$title = get_string('clearpredictions', 'tool_analytics');
break;
+ case 'invalidanalysables':
+ $title = get_string('invalidanalysables', 'tool_analytics');
+ break;
default:
throw new moodle_exception('errorunknownaction', 'analytics');
}
@@ -219,6 +222,20 @@ switch ($action) {
$model->clear();
redirect(new \moodle_url('/admin/tool/analytics/index.php'));
break;
+
+ case 'invalidanalysables':
+
+ echo $OUTPUT->header();
+
+ $page = optional_param('page', 0, PARAM_INT);
+ // No option in the UI to change this, only for url hackers ;).
+ $perpage = optional_param('perpage', 10, PARAM_INT);
+
+ $renderable = new \tool_analytics\output\invalid_analysables($model, $page, $perpage);
+ $renderer = $PAGE->get_renderer('tool_analytics');
+ echo $renderer->render($renderable);
+
+ break;
}
echo $OUTPUT->footer();
diff --git a/admin/tool/analytics/templates/invalid_analysables.mustache b/admin/tool/analytics/templates/invalid_analysables.mustache
new file mode 100644
index 00000000000..c97dd6be309
--- /dev/null
+++ b/admin/tool/analytics/templates/invalid_analysables.mustache
@@ -0,0 +1,78 @@
+{{!
+ 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
{{#str}}name{{/str}} | +{{#str}}invalidtraining, tool_analytics{{/str}} | +{{#str}}invalidprediction, tool_analytics{{/str}} | +
---|---|---|
{{{url}}} | +{{validtraining}} | +{{validprediction}} | +