Skip to content
Snippets Groups Projects
Commit e659074a authored by Chris Sangwin's avatar Chris Sangwin
Browse files

Improvements to the reporting on the graphs, specifically reporting question names.

parent c98a572a
Branches
Tags
No related merge requests found
......@@ -291,7 +291,12 @@ class restore_qtype_stack_plugin extends restore_qtype_plugin {
$graph->layout();
$roots = $graph->get_roots();
if (count($roots) != 1 || $graph->get_broken_cycles()) {
throw new coding_exception('The PRT ' . $prt->name . ' is malformed.');
$questions = $DB->get_records('question', array('id' => $prt->questionid), '', 'name');
$qnames = array();
foreach($questions as $q) {
$qnames[] = $q->name;
}
throw new coding_exception('The PRT named "' . $prt->name . '" is malformed in question id '.$prt->questionid.', question named "'.implode(', ',$qnames).'".');
}
reset($roots);
$firstnode = key($roots) - 1;
......
......@@ -42,14 +42,21 @@ $nodes = $DB->get_recordset('qtype_stack_prt_nodes', array(), 'questionid, prtna
'questionid, prtname, nodename, truenextnode, falsenextnode');
$trees = array();
foreach ($nodes as $node) {
$trees[$node->questionid . '|' . $node->prtname][$node->nodename] = array($node->truenextnode, $node->falsenextnode);
$questions = $DB->get_records('question', array('id' => $node->questionid), '', 'name');
$qnames = array();
foreach($questions as $q) {
$qnames[] = $q->name;
}
$trees[implode(', ',$qnames).' ('.$node->questionid . ') ' . $node->prtname][$node->nodename] = array($node->truenextnode, $node->falsenextnode);
}
$nodes->close();
$uniquetrees = array();
$frequency = array();
foreach ($trees as $tree) {
$qnamesused = array();
foreach ($trees as $qname => $tree) {
$key = json_encode($tree);
$uniquetrees[$key] = $tree;
$qnamesused[$key][] = $qname;
if (array_key_exists($key, $frequency)) {
$frequency[$key] += 1;
} else {
......@@ -81,6 +88,9 @@ foreach ($frequency as $key => $count) {
}
reset($uniquetree);
echo $OUTPUT->heading('Tree used ' . $count . ' times');
if ($count < 10) {
echo '<p>'.implode('<br .>', $qnamesused[$key]).'</p>';
}
try {
$tree->layout();
echo stack_abstract_graph_svg_renderer::render($tree, 'real' . $i++);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment