#!/usr/bin/perl -w
$|=1;
use strict;

my %stats;
my %time;

while (<>) {
    my ($date)= ($ARGV =~ m{/(\d{8})});

    if (my ($time1, $km)= /<img src=.*width=.* height=\d* .*.nbsp;(\d+:\d+) .nbsp;? (\d*) km/) {
        $stats{$date}{$time1}{km}= $km;
        $time{$time1}++;
    }
    elsif (my ($time2, $bm)= /<img +src=.*width=.* height=.*.nbsp;(\d+:\d+) .nbsp;? (\d*) belemmeringen/) {
        $stats{$date}{$time2}{bm}= $bm;
        $time{$time2}++;
    }
}

print "      :";
for my $date (sort keys %stats) {
    printf(" %8s", $date);
}
print "\n";

for my $time (sort keys %time) {
    printf("%-6s:", $time);
    for my $date (sort keys %stats) {
        my $stat= $stats{$date}{$time};
        printf(" %4s:%3s", $stat->{km}||"", $stat->{bm}||"");
    }
    print "\n";
}

