-
Notifications
You must be signed in to change notification settings - Fork 0
/
generatecharts.pl
executable file
·109 lines (89 loc) · 2.65 KB
/
generatecharts.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
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
#!/usr/bin/perl
use strict;
use Chart::Clicker;
use Chart::Clicker::Axis::DateTime;
use Chart::Clicker::Data::DataSet;
use Chart::Clicker::Data::Series;
use Chart::Clicker::Renderer::Area;
use DBI;
use Data::Dumper;
chdir("/home/aiarena/rtb-web");
my $database = 'aiarena';
my $hostname = 'localhost';
my $port = '3306';
my $user = 'aiarena';
my $pass = 'bTs8aum3';
chdir('/home/m1nd/rtb-web/');
my $dsn = "DBI:mysql:database=$database;host=$hostname;port=$port";
my $dbh = DBI->connect($dsn, $user, $pass);
# Get the Botlist
my $sth = $dbh->prepare('SELECT name FROM bots',);
$sth->execute();
while (my $ref = $sth->fetchrow_hashref()) {
my $bot = $ref->{'name'};
&getdata($bot);
}
$sth->finish;
# Read the ELO History of each Bot
sub getdata {
my $name = shift;
print("Reading elohistory of $name\n");
my $sth = $dbh->prepare('SELECT elo, date FROM elohistory where name = ?',);
$sth->execute($name);
my $elotable = $sth->fetchall_arrayref({});
if ($elotable) {
&createchart($name,$elotable);
}
}
# Create a chart for each Bot
sub createchart {
my $name = shift;
my $history = shift;
my $cc = Chart::Clicker->new(width => 800, height => 400);
my @elo;
my @date;
if (!$elo[0]) {
return;
}
foreach (@$history) {
push (@elo, $_->{'elo'});
push (@date, $_->{'date'});
}
my $series1 = Chart::Clicker::Data::Series->new(
name => 'ELO',
values => [@elo],
keys => [@date]
);
my $ds = Chart::Clicker::Data::DataSet->new(series => [ $series1 ]);
$cc->add_to_datasets($ds);
my $def = $cc->get_context('default');
my $dtaxis = Chart::Clicker::Axis::DateTime->new(
format => '%m/%d',
position => 'bottom',
orientation => 'horizontal'
);
$def->domain_axis($dtaxis);
$def->range_axis->brush->width(1);
$def->domain_axis->brush->width(1);
$def->range_axis->show_ticks(1);
$def->domain_axis->show_ticks(1);
$cc->border->width(0);
$cc->background_color(
Graphics::Color::RGB->new(red => .95, green => .94, blue => .92)
);
my $orange = Graphics::Color::RGB->new(
red => .88, green => .48, blue => .09, alpha => 1
);
$cc->color_allocator->colors([ $orange ]);
$def->domain_axis->tick_label_angle(0.785398163);
$def->range_axis->label_font->family('Hoefler Text');
$def->range_axis->tick_font->family('Hoefler Text');
$def->domain_axis->tick_font->family('Hoefler Text');
$def->domain_axis->label_font->family('Hoefler Text');
$cc->plot->grid->background_color->alpha(0);
$def->renderer(Chart::Clicker::Renderer::Area->new(opacity => .50));
$def->renderer->brush->width(2);
$cc->legend->font->family('Hoefler Text');
$cc->legend->visible(0);
$cc->write_output("./public/charts/$name.png");
}