Created
December 22, 2011 05:41
-
-
Save tagomoris/1509104 to your computer and use it in GitHub Desktop.
reduce results of checker
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use 5.14.0; | |
my $seq = {first => [], second => [], third => [], forth => []}; | |
my $lines = 0; | |
my $bytes = 0; | |
my $broken = 0; | |
while(my $line = <STDIN>){ | |
chomp $line; | |
my ($tag, $start, $end) = split(/\t/, $line, 3); | |
if ($tag eq 'broken') { | |
$broken += $start; | |
next; | |
} | |
if ($tag eq 'bytes') { | |
$bytes += $start; | |
next; | |
} | |
if ($tag eq 'lines') { | |
$lines += $start; | |
next; | |
} | |
my $hit = 0; | |
foreach my $pair (@{$seq->{$tag}}) { | |
next if $hit; | |
if ($pair->[1] == $start - 1) { | |
$pair->[1] = $end; | |
$hit = 1; | |
} | |
elsif ($pair->[0] == $end + 1) { | |
$pair->[0] = $start; | |
$hit = 1; | |
} | |
} | |
next if $hit; | |
push $seq->{$tag}, [$start, $end]; | |
} | |
foreach my $tagname (keys %$seq) { | |
my @pairs = sort {$a->[0] <=> $b->[0]} @{$seq->{$tagname}}; | |
my @merged = (); | |
my $building = undef; | |
foreach my $pair (@pairs) { | |
unless ($building) { | |
$building = $pair; | |
next; | |
} | |
if ($pair->[0] == $building->[1] + 1) { | |
$building->[1] = $pair->[1]; | |
} | |
else { | |
push @merged, $building; | |
$building = $pair; | |
} | |
} | |
my $last = undef; | |
foreach my $pair (@merged) { | |
print $tagname, "\t", $pair->[0], "\t", $pair->[1], "\t", ($last ? $pair->[0] - $last : ''), "\n"; | |
$last = $pair->[1]; | |
} | |
} | |
print "lines\t", $lines, "\n"; | |
print "bytes\t", $bytes, "\n"; | |
print "broken\t", $broken, "\n"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment