#!/usr/bin/perl
use strict;
use warnings;

my $fn = $ARGV[0] || 'rakudo-data';
open my $f, '<', $fn or die "Can't open file '$fn' for reading: $!";
my (@x, @tests, @pass);
while (<$f>) {
    chomp;
    m/(\d{4}-\d{2}-\d{2})\s+\d+:\d+\s+\d+\s+(\d+)\s+(\d+)/
        or die "Can't parse line '$_'\n";
    push @x, $1;
    push @tests, $2;
    push @pass, $3;
}

use GD::Graph::lines;

my $p = GD::Graph::lines->new(600, 400);
$p->set(
        x_label         => 'Date',
        y_label         => 'Tests',
        title           => 'Passing Rakudo Spectests',
        x_label_skip    => 2,
        x_labels_vertical => 1,
    ) or die $p->error;
my $g = $p->plot([\@x, \@pass]) or die $p->error;
open my $o, '>', "graph.png" or die "Can't open file graph.png for writing: $!";
binmode $o;
print $o $g->png;
close $o;

