parsegame(): Support for saving away sgf copies for debugging
[asr.git] / reset.pl
blob4aa94ca9d4a0e040cc800006ce80a495b327a262
1 #!/usr/bin/perl
3 use strict;
4 use warnings;
5 use ASR;
6 use POSIX qw/strftime/;
7 use Carp qw/cluck/;
8 $SIG{__WARN__} = sub { cluck $_[0] };
10 my $ctx = ASR::Ladder->new;
12 $ctx->header('Monthly reset');
14 if ($ctx->param('pwd') ne $ctx->{adminpw}) {
15 print $ctx->p('Invalid password.');
16 $ctx->footer;
17 exit;
20 if (not system('mysqldump -u asr -p'.$ctx->{password}.' asr >/tmp/ASR-`date +%F`.dump')) {
21 print $ctx->p("Error: Database backup failed: $?, $!");
22 $ctx->footer;
23 exit;
26 ($ctx->db_do('START TRANSACTION') and
27 $ctx->db_do('CREATE TEMPORARY TABLE inactive (id INT)') and
28 $ctx->db_do('INSERT INTO inactive SELECT id FROM raw_ladder ' .
29 'WHERE last_game IS NULL OR last_game < ' .
30 'DATE("'.$ctx->param('cutoffdate').'")') and
31 $ctx->db_do('DELETE FROM player WHERE id IN (SELECT id FROM inactive)') and
32 $ctx->db_do('DROP TABLE inactive') and
33 $ctx->db_do('COMMIT')) or
34 print $ctx->p('Removing inactive players failed.');
36 $ctx->db_do('UPDATE player SET score = 100 WHERE score < 100') or
37 print $ctx->p('Flooring score to 100 failed.');
38 $ctx->db_do('UPDATE player SET score = 200 WHERE score > 200') or
39 print $ctx->p('Ceiling score to 200 failed.');
40 $ctx->db_do('UPDATE player SET score = 100 + (score - 100) / 2 WHERE score > 100') or
41 print $ctx->p('Halving score failed.');
43 $ctx->footer;