simu

Ice hockey final standings simulator
git clone https://git.inz.fi/simu
Log | Files | Refs

parsedata (863B)


      1 #!/usr/bin/env perl
      2 
      3 use JSON;
      4 
      5 my $data = JSON->new->utf8->decode(join '', <<>>) || die "$!";
      6 my %teams;
      7 my @played;
      8 my @upcoming;
      9 
     10 for (@{$data}) {
     11 	my $ht = $_->{'homeTeam'}{'teamName'};
     12 	my $at = $_->{'awayTeam'}{'teamName'};
     13 	my $hid = $teams{$ht} // ($teams{$ht} = scalar %teams);
     14 	my $aid = $teams{$at} // ($teams{$at} = scalar %teams);
     15 
     16 	if ($_->{ended}) {
     17 		push @played, [$hid, $aid, $_->{'homeTeam'}{'goals'}, $_->{'awayTeam'}{'goals'}, $_->{'gameTime'}];
     18 	} else {
     19 		push @upcoming, [$hid, $aid];
     20 	}
     21 }
     22 
     23 printf("%d\n", scalar %teams);
     24 print join("\n", sort { $teams{$a} <=> $teams{$b} } keys %teams), "\n\n";
     25 
     26 printf("%d\n", scalar @played);
     27 print map { sprintf("%d %d %d %d %s\n", @$_[0..3], $_->[4] > 3600 ? $_->[4] == 3900 ? "SO" : "OT" : "") } @played;
     28 print "\n";
     29 
     30 printf("%d\n", scalar @upcoming);
     31 print map { (join ' ', @$_) . "\n" } @upcoming;