-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmakehtml.pl
35 lines (30 loc) · 1.14 KB
/
makehtml.pl
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
use 5.20.0;
use utf8;
use IO::Dir;
use IO::All;
use File::Spec::Functions qw/catfile/;
use Time::Piece;
use JSON::XS;
my $base_dir = $ARGV[0];
my $result_summaries_dir_base = $ARGV[1];
my $result_summaries_dir = catfile $base_dir, $result_summaries_dir_base;
my $html_file = catfile $base_dir, $ARGV[2];
my $summarize_file = "results.json";
my $html_template_file = "index.html";
my $results_info = [];
my $dh = new IO::Dir($result_summaries_dir);
while (my $result_filename = $dh->read) {
next if $result_filename =~ /^\./;
my $time = Time::Piece->strptime($result_filename, "%Y-%m-%dT%H-%M-%S.json");
my $json = io(catfile $result_summaries_dir, $result_filename)->utf8->all;
my $data = JSON::XS->new->decode($json);
my $info = {%$data, time => $time->epoch * 1000};
push @$results_info, $info;
}
@$results_info = sort {$a->{time} <=> $b->{time}} @$results_info;
my $js_str = "const resultsInfo = " . JSON::XS->new->utf8->encode($results_info) . ";";
my $template = io($html_template_file)->utf8->all;
$template =~ s@const resultsInfo = \[\];@$js_str@;
my $fh = new IO::File($html_file, ">:encoding(utf8)");
print $fh $template;
$fh->close;