-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdeltas
executable file
·110 lines (96 loc) · 3.11 KB
/
deltas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#!/usr/bin/perl -w
#
# Copyright 2014 (c) Kolbe Kegel
#
# Author: Kolbe Kegel <[email protected]>
#
# This file 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, version 2.
#
# This program 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
# this program; if not, write to the Free Software Foundation, Inc., 51
# Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
use strict;
use Getopt::Std;
# egrep 'Handler_(read|update)' qa/qa_update.log | tr -d '|' | deltas | column -t
# cat global_0508121* | deltas -v | egrep -v '\+0\b' | column -t
# -v to get "vertical" output (this is the default)
# -h if you want "horizontal" output, otherwise you get vertical
# -Z will exclude all rows that don't change at all across all iterations
# -s will output a summary at the end that shows the final value and the change across all outputs
# -n controls output of header information
my %v;
my %opt = (h=>0,v=>0,n=>0,Z=>0,s=>0);
getopts('hvsnZ', \%opt);
if ($opt{v} and $opt{h}) {
print STDERR "[ERROR]: -h and -v options conflict.\n";
exit 1;
}
while (<>) {
my @F = split(' ');
push @{$v{$F[0]}}, $F[1] if defined $F[0];
}
sub prn($$) {
my $n = shift;
my $v = shift;
my $p = $n > 0 ? "+" : "";
printf "%${p}d\t", $v->[$n] - ($n ? $v->[$n-1] : 0), "\t";
}
# This will loop around through the entiiiiiire data set and remove any items that do not change at all from start to finish
if ($opt{Z}) {
for my $k (keys %v) {
my $l=$v{$k}->[0];
# try to handle some case where arguments are non-numeric or undefined or something
delete $v{$k} and next if not defined $l;
my $n=1;
while ($n < @{$v{$k}} and $l eq $v{$k}->[$n]) {
$l=$v{$k}->[$n++];
}
if ($n==@{$v{$k}}) {
delete $v{$k};
}
}
}
my @k = sort keys %v;
my $ln=0;
my $rows=40;
$rows=`tput lines`||40 if ($opt{n});
if ($opt{v}) {
for my $k (@k) {
if (not $ln % ($rows - 5) and $opt{n}) {
print "# \t";
for (my $i=0; $i < @{$v{$k[0]}}; $i++) { printf "%i\t", $i+1; }
print "\n\n";
}
print "$k\t";
for (my $n=0; $n < @{$v{$k}}; $n++) {
prn($n,$v{$k})
}
#printf "%${p}d\t", $v->[$n] - ($n ? $v->[$n-1] : 0), "\t";
if ($opt{s}) {
printf "%d\t", $v{$k}->[-1];
printf "%+d\t", $v{$k}->[-1] - $v{$k}->[0];
}
print "\n";
$ln++;
}
} else {
#print "# \t" if $opt{n};
for (my $n=0; $n < @{$v{$k[0]}}; $n++) {
if (not $n % ($rows - 5)) {
print "#\t" if $opt{n};
print join("\t", @k),"\n"
}
printf "%i\t", ++$ln if $opt{n};
for my $k (@k) {
prn($n,$v{$k})
}
print "\n";
}
}