01
version 1.0;
02
03
ns junos = "http://xml.juniper.net/junos/*/junos";
04
ns xnm = "http://xml.juniper.net/xnm/1.1/xnm";
05
ns jcs = "http://xml.juniper.net/junos/commit-scripts/1.0";
06
07
param $screen-width = 80;
08
param $separator = " : ";
09
param $debug;
10
11
var $stars =
12
"**********************************************************************";
13
var $bangs =
14
"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!";
15
16
template star-graph($stats, $name = "Name", $value = "Value") {
17
param $header-format = "%-8s %-20s%s";
18
param $format = "%8s %-20s";
19
20
var $max = $stats/total;
21
var $threshold = floor($max * 0.80);
22
var $low = floor($max div 100);
23
24
<output> jcs:printf($header-format, $value, $name, " Graph");
25
for-each ($stats/item) {
26
<xsl:sort select="value" data-type="number" order="descending">;
27
if (value >= $low) {
28
var $title = jcs:printf($format,
29
value, substring(name, 0, 20));
30
call star-graph-line($title, $title-width = 30, $value = value,
31
$max, $threshold);
32
}
33
}
34
<output> "Total: " _ $max;
35
}
36
37
template star-graph-line($title, $title-width = 10, $value, $max, $threshold,
38
$max-width = $screen-width) {
39
var $width = $max-width - $title-width - string-length($separator);
40
var $per = $max div $width;
41
var $num = floor($value div $per);
42
43
var $threshold-num = floor($threshold div $per);
44
var $bang-num = {
45
if ($value < $threshold) {
46
expr 0;
47
} else {
48
expr $num - $threshold-num + 1;
49
}
50
}
51
52
var $star-num = $num - $bang-num;
53
var $star-string = substring($stars, 0, $star-num + 1);
54
var $bang-string = substring($bangs, 0, $bang-num + 1);
55
56
var $extra = {
57
if ($value - (floor($value div $per) * $per) >= $per div 2) {
58
if ($value > $threshold) {
59
expr ":";
60
} else {
61
expr "-";
62
}
63
}
64
}
65
66
<output> jcs:printf("%-*s%s%s%s%s\n", $title-width, $title, $separator,
67
$star-string, $bang-string, $extra);
68
}
|