/
graph-result-data.pl6
141 lines (118 loc) · 4.02 KB
/
graph-result-data.pl6
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
use v6.c;
use JSON::Fast;
use RandomColor;
use SVG;
my %graph-data;
sub MAIN (*@filenames) {
my @bl = "BuildList".IO.slurp.lines;
my (%order, @points);
my $idx = 0;
for @bl {
%order{$_} = $idx++ ;
#"{$_}: $idx".say;
}
# Ascending order. Last results on top. Most of these files have a date
# serial, although if we convert them to IO paths, we could use generation
# date. I guess we can make these options if we want to get schmansy
@filenames.sort;
# Generate random colors. Using date of initial completion as the current
# seed. This will change to something more presentable, if necessary.
my @colors = RandomColor.new(
seed => 20181127,
count => +@filenames,
format => 'color'
).list;
my @legend;
for @filenames.kv -> $k, $v {
my $l = text => [
:x(20),
:y(10 + $k * 15),
:font-size(6),
:style("fill:{ @colors[$k].to-string('rgb') }"),
$v.subst('.json', '')
];
@legend.push: $l;
}
my ($c, $yo) = (0, 25 + 15 * @filenames.elems);
die "Cannot load '$_'!" unless .IO.e for @filenames;
for @filenames -> $filename {
my (@text-lines, @polyline, @dp);
my %data = from-json($filename.IO.slurp);
for %data.keys {
next if $_ eq <SUMMARY DEPENDENCIES>.any;
# Remove outdated stat.
next if $_ eq 'GTK::Plus';
my $n = $_;
# Fixes long standing bug with renamed file.
$n = 'GTK::ShortcutsWindow' if $n eq 'GTK::ShorcutsWindow';
# Adjustment from 580d13887aaf1e4504ee719eca91f0786806c276 where
# ::TreeRow was renamed to ::TreeRowReference
$n = 'GTK::TreeRowReference' if $n eq 'GTK::TreeRow';
# Adjustment from e8c4c74070c5f00924e8e35949e8c52dfd3c9a34 where
# ::Compat::Action was made into ::Compat::Roles::Action
$n = 'GTK::Compat::Roles::Action' if $n eq 'GTK::Compat::Action';
# Adjustment from ab3d879ddb303371fb1ca00d8d7d6446414420e7 where
# ::Compat::File was replaced with ::Compat::Roles::GFile
$n = 'GTK::Compat::Roles::GFile' if $n eq 'GTK::Compat::File';
without %order{$n} {
$n.say;
exit;
}
@points[%order{$n}] = %data{$n};
}
my $rgbh = @colors[$c].lighten(10).to-string('rgb');
my $rgb = @colors[$c++].to-string('rgb');
$idx = 0;
(my $sname = $filename) ~~ s/ 'LastBuildResults-' //;
for @bl -> $bl {
if %graph-data<text>:!exists {
my $p = text => [ :x(20), :y($yo + $idx * 30), :font-size(8), $bl ];
@text-lines.push: $p;
}
with @points[$idx] {
my ($px, $py) = ( (200 + @points[$idx]<parse> * 25).Int,
$yo + $idx * 30 );
@polyline.push: "{$px},{$py}";
@dp.push: (circle => [
:cx($px), :cy($py), :r(4), :fill($rgb),
title => [ "{ $sname } - { @points[$idx]<parse> }" ]
]);
}
$idx++;
}
%graph-data<text> //= @text-lines;
my $avg-parse = %data.values.map( *<parse> ).sum / %data.keys.elems,
my ($x0, $y1) = (200 + 25 * $avg-parse, $yo + @points.elems * 30);
my $l-style = "stroke:{ $rgbh };stroke-width:1";
my $pl-style = "fill:none;stroke:{ $rgb };stroke-width:3";
%graph-data<series>.push: [
line => [
:x1($x0), :y1(0), :x2($x0), :y2($y1), :style($l-style),
title => [ "{ $sname } - Avg: { $avg-parse }s" ]
],
polyline => [ :points(@polyline.join(' ')), :style($pl-style) ],
|@dp
];
}
my $svg = [
width => 900,
height => 25 + @filenames.elems * 15 + @bl.elems * 30,
style => [ 'svg { background-color: #333333; } text { fill: #cccccc; }' ],
|@legend,
|%graph-data<text>,
];
# Labelling?
$svg.push: |$_ for %graph-data<series>.values;
my $outputname = @filenames[0];
if @filenames.elems > 1 {
my $ser = DateTime.now(
formatter => {
sprintf "%4d%02d%02d-%02d%02d", .year, .month, .day, .hour, .minute
}
);
$outputname = "OutputGraph-{ $ser }";
}
my $f = "$outputname.svg".IO.open(:w);
$f.say( SVG.serialize( svg => $svg ) );
$f.close;
}