Skip to content
Snippets Groups Projects
Commit a104e476 authored by Astor Bizard's avatar Astor Bizard :dog2:
Browse files

Fixed diff algorithm. Removed zero-diff files from diff graph.

parent 390df423
No related branches found
No related tags found
No related merge requests found
......@@ -474,7 +474,7 @@ class vpl_diff {
* @param string $filedata1
* @param string $filedata2
* @param int $timelimit The maximum amount of time to spend on this computation (in milliseconds).
* If provided and the time limit is exceeded, an exception will be thrown.
* If provided and the time limit is exceeded, a moodle_exception with code 'difftoolarge' will be thrown.
* @return int The diff in number of chars.
*/
static public function compute_filediff($filedata1, $filedata2, $timelimit=0) {
......@@ -500,7 +500,7 @@ class vpl_diff {
while (true) {
if ($timelimit > 0 && microtime(true) - $starttime > $timelimit / 1000) {
// Time out.
throw new Exception();
throw new moodle_exception('difftoolarge');
}
while (count($queue[$priority]) == 0) {
$priority++;
......@@ -525,7 +525,7 @@ class vpl_diff {
// Found shortest diff amongst lines.
// Backtrack to compute total diff as a sum of lines diff.
$totaldiff = 0;
while ($i1 > 0 && $i2 > 0) {
while ($i1 > 0 || $i2 > 0) {
if (!isset($prev[$i1][$i2])) {
$i1--;
$i2--;
......
......@@ -186,9 +186,25 @@ class vpl_grapher {
if ($diff && count($names) > 1) {
$names[] = get_string('total');
$series[get_string('total')] = $totalseries;
// Filter out all zero-diff files.
$names = array_filter($names, function($name) use(&$series){
foreach ($series[$name] as $value){
if ($value != 0) {
return true;
}
}
// All diffs are zero for this file - do not include it.
unset($series[$name]);
return false;
});
}
self::draw( $title, get_string( 'submissions', VPL ) , get_string( "sizeb" ), $subsn, $series, $names );
} catch (Exception $e) {
} catch (moodle_exception $e) {
if ($e->errorcode != 'difftoolarge') {
// The exception was not thrown by diff calculation, don't catch it.
throw $e;
}
global $PAGE;
echo '<span class="chart-area nograph">';
echo '<b>' . $title . '</b><br>';
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment