MDL-59106 report_insights: show time created and time range used

This commit is contained in:
Mark Nelson 2017-10-06 17:20:55 +08:00
parent f87174dcc2
commit c614073940
6 changed files with 115 additions and 49 deletions

View File

@ -71,10 +71,23 @@ class insight implements \renderable, \templatable {
* @return \stdClass
*/
public function export_for_template(\renderer_base $output) {
// Get the prediction data.
$predictiondata = $this->prediction->get_prediction_data();
$data = new \stdClass();
$data->insightname = format_string($this->model->get_target()->get_name());
// Get the details.
$data->timecreated = userdate($predictiondata->timecreated);
$data->timerange = '';
if (!empty($predictiondata->timestart) && !empty($predictiondata->timeend)) {
$timerange = new \stdClass();
$timerange->timestart = userdate($predictiondata->timestart);
$timerange->timeend = userdate($predictiondata->timeend);
$data->timerange = get_string('timerangewithdata', 'report_insights', $timerange);
}
// Sample info (determined by the analyser).
list($data->sampledescription, $samplerenderable) = $this->model->prediction_sample_description($this->prediction);
@ -84,10 +97,10 @@ class insight implements \renderable, \templatable {
}
// Prediction info.
$predictedvalue = $this->prediction->get_prediction_data()->prediction;
$predictionid = $this->prediction->get_prediction_data()->id;
$predictedvalue = $predictiondata->prediction;
$predictionid = $predictiondata->id;
$data->predictiondisplayvalue = $this->model->get_target()->get_display_value($predictedvalue);
list($data->style, $data->outcomeicon) = $this->get_calculation_display($this->model->get_target(),
list($data->style, $data->outcomeicon) = self::get_calculation_display($this->model->get_target(),
floatval($predictedvalue), $output);
$actions = $this->model->get_target()->prediction_actions($this->prediction, $this->includedetailsaction);
@ -124,7 +137,7 @@ class insight implements \renderable, \templatable {
$obj = new \stdClass();
$obj->name = call_user_func(array($calculation->indicator, 'get_name'));
$obj->displayvalue = $calculation->indicator->get_display_value($calculation->value, $calculation->subtype);
list($obj->style, $obj->outcomeicon) = $this->get_calculation_display($calculation->indicator,
list($obj->style, $obj->outcomeicon) = self::get_calculation_display($calculation->indicator,
floatval($calculation->value), $output, $calculation->subtype);
$data->calculations[] = $obj;
@ -149,7 +162,7 @@ class insight implements \renderable, \templatable {
* @param string|false $subtype
* @return array The style as 'success', 'info', 'warning' or 'danger' and pix_icon
*/
protected function get_calculation_display(\core_analytics\calculable $calculable, $value, $output, $subtype = false) {
public static function get_calculation_display(\core_analytics\calculable $calculable, $value, $output, $subtype = false) {
$outcome = $calculable->get_calculation_outcome($value, $subtype);
switch ($outcome) {
case \core_analytics\calculable::OUTCOME_NEUTRAL:

View File

@ -95,17 +95,39 @@ class insights_list implements \renderable, \templatable {
if ($this->model->uses_insights()) {
$predictionsdata = $this->model->get_predictions($this->context, true, $this->page, $this->perpage);
$data->insights = array();
$data->predictions = array();
$predictionvalues = array();
$insights = array();
if ($predictionsdata) {
list($total, $predictions) = $predictionsdata;
foreach ($predictions as $prediction) {
$predictedvalue = $prediction->get_prediction_data()->prediction;
// Only need to fill this data once.
if (!isset($predictionvalues[$predictedvalue])) {
$preddata = array();
$preddata['predictiondisplayvalue'] = $this->model->get_target()->get_display_value($predictedvalue);
list($preddata['style'], $preddata['outcomeicon']) =
insight::get_calculation_display($this->model->get_target(), $predictedvalue, $output);
$predictionvalues[$predictedvalue] = $preddata;
}
$insightrenderable = new \report_insights\output\insight($prediction, $this->model, true);
$data->insights[] = $insightrenderable->export_for_template($output);
$insights[$predictedvalue][] = $insightrenderable->export_for_template($output);
}
// Ok, now we have all the data we want, put it into a format that mustache can handle.
foreach ($predictionvalues as $key => $prediction) {
if (isset($insights[$key])) {
$prediction['insights'] = $insights[$key];
}
$data->predictions[] = $prediction;
}
}
if (empty($data->insights) && $this->page == 0) {
if (empty($insights) && $this->page == 0) {
if ($this->model->any_prediction_obtained()) {
$data->noinsights = get_string('noinsights', 'analytics');
} else {

View File

@ -40,4 +40,7 @@ $string['prediction'] = 'Prediction';
$string['predictioncalculations'] = 'Indicator calculations';
$string['predictiondetails'] = 'Prediction details';
$string['nodetailsavailable'] = 'No prediction details are relevant.';
$string['timecreated'] = 'Time predicted';
$string['timerange'] = 'Time range';
$string['timerangewithdata'] = '{$a->timestart} to {$a->timeend}';
$string['selectotherinsights'] = 'Select other insights...';

View File

@ -31,29 +31,16 @@
Example context (json):
{
"sampleimage": "<a href=\"#\">Link</a>",
"sampledescription": "Sample description",
"style": "success",
"outcomeicon": {
"attributes": [
{"name": "src", "value": "https://moodle.org/logo/moodle-logo.svg" }
]
},
"predictiondisplayvalue": "This dev will understand it"
"sampledescription": "Sample description"
}
}}
<tr>
<td class="col-sm-6">
<td class="col-sm-10">
{{#sampleimage}}
{{{sampleimage}}}
{{/sampleimage}}
{{{sampledescription}}}
</td>
<td class="{{#style}}table-{{style}}{{/style}} col-sm-4">
{{#outcomeicon}}
{{> core/pix_icon}}
{{/outcomeicon}}
<span>{{predictiondisplayvalue}}</span>
</td>
<td class="col-sm-2">
{{#actions}}
{{> core/action_menu}}

View File

@ -31,6 +31,8 @@
Example context (json):
{
"insightname": "Best insight ever",
"timecreated": "Thursday, 5 October 2017, 4:16 PM",
"timerange": "Monday, 4 September 2017, 6:00 PM to Thursday, 5 October 2017, 12:00 AM",
"sampleimage": "<a href=\"#\">Link</a>",
"sampledescription": "Sample description",
"style": "success",
@ -73,11 +75,18 @@
<h2 class="m-b-2">{{#str}}insightprediction, report_insights, {{insightname}} {{/str}}</h2>
<table class="generaltable insights-list">
<caption>{{#str}}insight, report_insights{{/str}}</caption>
<caption>
{{#str}}prediction, report_insights{{/str}}:
<span class="{{#style}}table-{{style}}{{/style}}">
{{#outcomeicon}}
{{> core/pix_icon}}
{{/outcomeicon}}
{{predictiondisplayvalue}}
</span>
</caption>
<thead>
<tr>
<th scope="col" class="col-sm-6">{{#str}}name{{/str}}</th>
<th scope="col" class="col-sm-4">{{#str}}prediction, report_insights{{/str}}</th>
<th scope="col" class="col-sm-10">{{#str}}name{{/str}}</th>
<th scope="col" class="col-sm-2">{{#str}}actions{{/str}}</th>
</tr>
</thead>
@ -86,8 +95,23 @@
</tbody>
</table>
<table class="generaltable prediction-calculations">
<table class="generaltable prediction-timedetails">
<caption>{{#str}}predictiondetails, report_insights{{/str}}</caption>
<tbody>
<tr>
<td scope="col" class="col-sm-3">{{#str}}timecreated, report_insights{{/str}}</td>
<td scope="col" class="col-sm-9">{{timecreated}}</td>
</tr>
{{#timerange}}
<tr>
<td scope="col" class="col-sm-3">{{#str}}timerange, report_insights{{/str}}</td>
<td scope="col" class="col-sm-9">{{.}}</td>
</tr>
{{/timerange}}
</tbody>
</table>
<table class="generaltable prediction-calculations">
<caption class="accesshide">{{#str}}predictioncalculations, report_insights{{/str}}</caption>
<thead>
<tr>
<th scope="col" class="col-sm-8">{{#str}}indicator, report_insights{{/str}}</th>
@ -99,7 +123,7 @@
<tr>
<td class="{{#style}}table-{{style}}{{/style}} col-sm-8">{{name}}</td>
<td class="{{#style}}table-{{style}}{{/style}} col-sm-4">{{#outcomeicon}}{{> core/pix_icon}}{{/outcomeicon}} {{displayvalue}}</td>
</td>
</tr>
{{/calculations}}
</tbody>
</table>

View File

@ -31,27 +31,35 @@
Example context (json):
{
"insightname": "Best insight ever",
"insights": [
"predictions": [
{
"sampleimage": "<a href=\"#\">Link</a>",
"sampledescription": "Sample description",
"predictiondisplayvalue": "This dev will understand it",
"style": "success",
"outcomeicon": {
"attributes": [
{"name": "src", "value": "https://moodle.org/logo/moodle-logo.svg" }
]
},
"predictiondisplayvalue": "This dev will understand it"
"insights": [
{
"sampleimage": "<a href=\"#\">Link</a>",
"sampledescription": "Sample description"
}
]
}, {
"sampleimage": "<a href=\"#\">Any renderable</a>",
"sampledescription": "Another sample description",
"predictiondisplayvalue": "This dev will not understand it",
"style": "danger",
"outcomeicon": {
"attributes": [
{"name": "src", "value": "https://moodle.org/logo/moodle-logo.svg" }
]
},
"predictiondisplayvalue": "This dev will not understand it"
"insights": [
{
"sampleimage": "<a href=\"#\">Any renderable</a>",
"sampledescription": "Another sample description"
}
]
}
],
"noinsights": false
@ -67,21 +75,30 @@
<h2 class="m-b-2">{{{insightname}}}</h2>
{{^noinsights}}
{{{ pagingbar }}}
{{#predictions}}
<table class="generaltable insights-list">
<caption>{{#str}}insights, report_insights{{/str}}</caption>
<caption>
{{#str}}prediction, report_insights{{/str}}:
<span class="{{#style}}table-{{style}}{{/style}}">
{{#outcomeicon}}
{{> core/pix_icon}}
{{/outcomeicon}}
{{predictiondisplayvalue}}
</span>
</caption>
<thead>
<tr>
<th scope="col" class="col-sm-6">{{#str}}name{{/str}}</th>
<th scope="col" class="col-sm-4">{{#str}}prediction, report_insights{{/str}}</th>
<th scope="col" class="col-sm-10">{{#str}}name{{/str}}</th>
<th scope="col" class="col-sm-2">{{#str}}actions{{/str}}</th>
</tr>
</thead>
<tbody>
{{#insights}}
<tbody>
{{> report_insights/insight}}
{{/insights}}
</tbody>
{{/insights}}
</table>
{{/predictions}}
{{{ pagingbar }}}
{{/noinsights}}
{{#noinsights}}