-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbuild_compare_table.pl
More file actions
executable file
·208 lines (167 loc) · 4.51 KB
/
build_compare_table.pl
File metadata and controls
executable file
·208 lines (167 loc) · 4.51 KB
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
#!/bin/env perl
$|=1;
use strict;
use JSON;
my($infile, $outfile, $docket_title) = @ARGV;
unless ($infile) {
print "Usage: build_compare_table <path to infile>\n";
exit;
}
# get info on correlations
my($headers, $data) = read_table($infile);
# output
open OUTF, ">$outfile";
print_header("DOCKET compare");
print_section("DOCKET Compare for $docket_title");
print OUTF "<hr>\n";
print_table($data, 'table', 'numcorr', "Associations", $headers, {});
print OUTF qq(
<script src="https://code.jquery.com/jquery-3.4.1.js" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js" crossorigin="anonymous"></script>
<script type="text/javascript" src="https://cdn.datatables.net/v/dt/dt-1.10.20/r-2.2.3/datatables.min.js"></script>
<script>
const config_num = {
"language": {
"search": "🔍",
"searchPlaceholder": "search data"
},
"autoWidth": true,
"order": [
[3, "desc"]
]
}
\$(document).ready(function () {
\$('#numcorr').DataTable(config_num);
});
</script>
);
print_footer();
close OUTF;
#########################
sub print_header {
my($title) = @_;
print OUTF "<!doctype html public \"-//w3c//dtd html 4.0 transitional//en\">\n";
print OUTF "<html>\n<head>\n";
print OUTF " <title>$title</title>\n" if $title;
print OUTF qq(
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.20/css/jquery.dataTables.css">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
<link href="/css/style.css" rel="stylesheet" type="text/css">
<style>
.row {
margin-bottom: 25px;
}
</style>
);
print OUTF "</head>\n<body>\n";
}
sub print_footer {
print OUTF "</body>\n</html>\n";
}
sub print_section {
my($heading, $content) = @_;
print OUTF " <h2>$heading</h2>\n";
if (ref($content) eq 'ARRAY') {
print_block($_) foreach @$content;
} elsif (ref($content) eq 'HASH') {
foreach my $blockname (sort keys %$content) {
print OUTF " <h3>$blockname</h3>\n";
print_block($content->{$blockname});
}
}
}
sub print_block {
my($bl) = @_;
if (ref($bl) eq 'ARRAY') {
my($what, $format) = @$bl;
if ($format eq 'table') {
print_table(@$bl);
}
} elsif (ref($bl) eq 'HASH') {
} else {
print OUTF "$bl<br>\n";
}
}
sub print_table {
my($what, $format, $table_id, $table_title, $headers, $replace) = @_;
my(@columns, $body);
if (ref($what) eq 'HASH') {
my @keys = sort keys %$what;
my %cols;
while (my($key, $v) = each %$what) {
$cols{$_}++ foreach keys %$v;
}
my @cols = sort keys %cols;
@columns = ('Column name', map {$replace->{$_} || $_} @cols);
foreach my $key (@keys) {
$body .= "<tr><td>$key</td><td>";
$body .= join("</td><td>", map {$what->{$key}{$_} || " "} @cols);
}
} elsif (ref($what) eq 'ARRAY') {
my @cols = @$headers;
@columns = map {$replace->{$_} || $_} @cols;
my $shown;
foreach my $line (@$what) {
$body .= "<tr><td>";
$body .= join("</td><td>", @$line);
}
}
print OUTF qq(
<div class="sorted-table__header">
<div class="sorted-table__container">
<h2>$table_title</h2>
</div>
);
print OUTF qq(<table id="$table_id" class="display compact responsive" border>\n);
print OUTF qq(<thead><tr><th class="text--gray">);
print OUTF join("</th><th class=\"text--gray\">", @columns);
print OUTF "</th></tr></thead>\n";
#print OUTF qq(<thead class="total_row"></thead>\n);
print OUTF "<tbody>$body</tbody>\n";
print OUTF "</table>\n";
print OUTF "</div>\n";
}
sub read_table {
my($file) = @_;
my(@headers, @table);
if ($file =~ /\.gz$/) {
open F, "gunzip -c $file |";
} else {
open F, $file;
}
while (<F>) {
next if /^#/;
chomp;
@headers = split /\t/;
last;
}
while (<F>) {
next if /^#/;
chomp;
my(@v) = split /\t/;
push @table, \@v;
}
close F;
return \@headers, \@table;
}
sub read_json {
my($file) = @_;
my $json;
open J, "gunzip -c $file |";
while (<J>) {
chomp;
$json .= $_;
}
close J;
return decode_json($json);
}
sub looks_like_a_docket {
my($dir) = @_;
return 1 if
-d $dir &&
-d "$dir/analyses" &&
-d "$dir/fingerprints" &&
-d "$dir/comparisons" &&
-d "$dir/visualizations";
}