Merge branch 'MDL-59063_master' of git://github.com/dmonllao/moodle

This commit is contained in:
Andrew Nicols 2017-10-19 09:01:58 +08:00
commit ff7081150b
12 changed files with 317 additions and 4 deletions

View File

@ -0,0 +1,158 @@
<?php
// 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 <http://www.gnu.org/licenses/>.
/**
* 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(['notimesplitting' => 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;
}
}

View File

@ -230,6 +230,16 @@ class models_list implements \renderable, \templatable {
$actionsmenu->add($icon);
}
// Invalid analysables.
$analyser = $model->get_analyser(['notimesplitting' => true]);
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();

View File

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

View File

@ -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';

View File

@ -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();

View File

@ -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 <http://www.gnu.org/licenses/>.
}}
{{!
@template tool_analytics/invalid_analysables
Template for invalid analysables.
Classes required for JS:
* none
Data attributes required for JS:
* none
Context variables required for this template:
* none
Example context (json):
{
"modelname": "Not engaging courses",
"analysables": [
{
"url": "<a href=\"#\">Maths</a>",
"validtraining": "Ongoing course",
"validprediction": "Not enough students activity"
}, {
"url": "<a href=\"#\">Psichology</a>",
"validtraining": "No students",
"validprediction": "No students"
}
]
}
}}
<div class="box">
<h3>{{#str}}modelinvalidanalysables, tool_analytics, {{modelname}}{{/str}}</h3>
<div>{{#str}}invalidanalysablesinfo, tool_analytics{{/str}}</div>
<div class="m-t-2 m-b-1">
<span>{{#prev}}{{> core/single_button}}{{/prev}}</span>
<span>{{#next}}{{> core/single_button}}{{/next}}</span>
</div>
<table class="generaltable fullwidth">
<caption class="accesshide">{{#str}}invalidanalysablestable, tool_analytics{{/str}}</caption>
<thead>
<tr>
<th scope="col">{{#str}}name{{/str}}</th>
<th scope="col">{{#str}}invalidtraining, tool_analytics{{/str}}</th>
<th scope="col">{{#str}}invalidprediction, tool_analytics{{/str}}</th>
</tr>
</thead>
<tbody>
{{#analysables}}
<tr>
<td>{{{url}}}</td>
<td>{{validtraining}}</td>
<td>{{validprediction}}</td>
</tr>
{{/analysables}}
</tbody>
</table>
<div class="m-t-1 m-b-2">
<span>{{#prev}}{{> core/single_button}}{{/prev}}</span>
<span>{{#next}}{{> core/single_button}}{{/next}}</span>
</div>
</div>

View File

@ -47,6 +47,13 @@ interface analysable {
*/
public function get_id();
/**
* The analysable human readable name
*
* @return string
*/
public function get_name();
/**
* The analysable context.
*

View File

@ -195,6 +195,15 @@ class course implements \core_analytics\analysable {
return $this->course->id;
}
/**
* The course short name
*
* @return string
*/
public function get_name() {
return format_string($this->course->shortname, true, array('context' => $this->get_context()));
}
/**
* get_context
*

View File

@ -363,7 +363,7 @@ abstract class base {
$result = $this->analysabletarget->is_valid_analysable($analysable, $includetarget);
if ($result !== true) {
$a = new \stdClass();
$a->analysableid = $analysable->get_id();
$a->analysableid = $analysable->get_name();
$a->result = $result;
$this->add_log(get_string('analysablenotvalidfortarget', 'analytics', $a));
return array();
@ -407,7 +407,7 @@ abstract class base {
}
$a = new \stdClass();
$a->analysableid = $analysable->get_id();
$a->analysableid = $analysable->get_name();
$a->errors = implode(', ', $errors);
$this->add_log(get_string('analysablenotused', 'analytics', $a));
}

View File

@ -54,6 +54,15 @@ class site implements \core_analytics\analysable {
return SYSCONTEXTID;
}
/**
* Site.
*
* @return string
*/
public function get_name() {
return get_string('site');
}
/**
* Analysable context.
*

View File

@ -292,6 +292,7 @@ $string['counteditems'] = '{$a->count} {$a->items}';
$string['country'] = 'Country';
$string['course'] = 'Course';
$string['courseadministration'] = 'Course administration';
$string['coursealreadyfinished'] = 'Course already finished';
$string['courseapprovedemail'] = 'Your requested course, {$a->name}, has been approved and you have been made a {$a->teacher}. To access your new course, go to {$a->url}';
$string['courseapprovedemail2'] = 'Your requested course, {$a->name}, has been approved. To access your new course, go to {$a->url}';
$string['courseapprovedfailed'] = 'Failed to save the course as approved!';
@ -336,8 +337,8 @@ $string['coursehelpnewsitemsnumber'] = 'Number of recent announcements appearing
$string['coursehelpnumberweeks'] = 'Number of sections in the course (applies to certain course formats only).';
$string['coursehelpshowgrades'] = 'Enable the display of the gradebook. It does not prevent grades from being displayed within the individual activities.';
$string['coursehidden'] = 'This course is currently unavailable to students';
$string['coursenotyetstarted'] = 'The course is not yet started';
$string['coursenotyetfinished'] = 'The course is not yet finished';
$string['coursenotyetstarted'] = 'The course has not yet started';
$string['coursenotyetfinished'] = 'The course has not yet finished';
$string['courseoverviewfiles'] = 'Course summary files';
$string['courseoverviewfilesext'] = 'Course summary files extensions';
$string['courseoverviewfileslimit'] = 'Course summary files limit';

View File

@ -158,6 +158,11 @@ class course_dropout extends \core_analytics\local\target\binary {
return get_string('coursetoolong', 'analytics');
}
// Finished courses can not be used to get predictions.
if (!$fortraining && $course->is_finished()) {
return get_string('coursealreadyfinished');
}
// Ongoing courses data can not be used to train.
if ($fortraining && !$course->is_finished()) {
return get_string('coursenotyetfinished');