#! /usr/bin/perl5.8 use warnings; use strict; use IO::File; use FindBin; use File::Spec; use DBI; my $user = shift; my $dbh = DBI->connect('dbi:CSV:f_dir=' . $FindBin::Bin . ";csv_eol=\n") or warn "Can't connect to DBI"; my $table_file = File::Spec->catfile($dbh->{f_dir},'stats'); $table_file .= '.'.$user if -e "$table_file.$user"; $dbh->{csv_tables}->{stats} = { file => $table_file, # col_names => [qw(DATE XP)], }; my @markers_old = ( [ Initiate => 0 ], [ Novice => 20 ], [ Acolyte => 50 ], [ Scribe => 100 ], [ Monk => 200 ], [ Friar => 500 ], [ Abbot => 1000 ], [ Bishop => 1600 ], [ Pontiff => 2300 ], [ Saint => 3000 ], ); my @markers = ( [ Initiate => 0 ], [ Novice => 20 ], [ Acolyte => 50 ], [ Sexton => 90 ], [ Beadle => 150 ], [ Scribe => 250 ], [ Monk => 400 ], [ Pilgrim => 600 ], [ Friar => 900 ], [ Hermit => 1300 ], [ Chaplain => 1800 ], [ Deacon => 2400 ], [ Curate => 3000 ], [ Priest => 4000 ], [ Vicar => 5400 ], [ Parson => 7000 ], [ Prior => 9000 ], [ Monsignor => 12000 ], [ Abbot => 16000 ], [ Canon => 22000 ], [ Chancellor => 30000 ], [ Bishop => 40000 ], [ Archbishop => 50000 ], [ Cardinal => 60000 ], [ Sage => 70000 ], [ Saint => 80000 ], [ Apostle => 90000 ], [ Pope => 100000 ], ); my $total; my %best = ( XP => 0 ); #my $sth = $dbh->prepare('select * from stats order by date'); #$sth->execute(); #while (my $line = $sth->fetchrow_hashref()) my $query = $dbh->selectall_arrayref('select * from stats', {Slice=>{}}); my @lens; my @data; foreach my $line (@$query) { next unless length $line->{XP}; $total += $line->{XP}; my @d = ( $line->{DATE}, $total ); if ($line->{XP}) { push @d, sprintf "%s%d", $line->{XP} > 0 ? '+' : '', $line->{XP}; } else { push @d, '0'; } my @made = ''; unless ($best{XP} >= $line->{XP}) { %best = %$line; push @made, 'New daily record!'; } unless (@markers) { if (int($total / 1000) > int(($total - $line->{XP})/1000)) { push @made, sprintf "(Reached %d000 XP!)", int($total/1000); } } while (@markers and $total >= $markers[0][1]) { push @made, sprintf "(Made %s!)", $markers[0][0]; shift @markers; } push @d, join ' ', @made; push @data, \@d; } use Text::Table; my $sep = '|'; my $tb = Text::Table->new('Date',\$sep, 'Total',\$sep, "Gain\n&right",\$sep, 'Notes'); $tb->load(@data); my @col_range = $tb->colrange(-1); foreach (@data) { my $notes = $_->[-1]; $_->[-1] = '*' x ($_->[2] * $col_range[1] / $best{XP}) if $_->[2] > 0; substr($_->[-1], 0, length($notes)) = $notes; } $tb->clear()->load(@data); print $tb; #$sth->finish(); if ($total) { printf( "Only %d more XP to becoming %s!\n", ($markers[0][1] - $total), $markers[0][0] ) if @markers; printf("Best day: %s at %dXP!\n", @best{qw(DATE XP)}); }