From: Steinar H. Gunderson Date: Tue, 23 Jun 2015 23:48:00 +0000 (+0200) Subject: Remove ingest.pl, as planned. X-Git-Url: https://git.sesse.net/?p=remoteglot;a=commitdiff_plain;h=84c8115a1719c935ad2dd0c99b6277c738f577d9 Remove ingest.pl, as planned. --- diff --git a/ingest.pl b/ingest.pl deleted file mode 100755 index 9e03f8a..0000000 --- a/ingest.pl +++ /dev/null @@ -1,57 +0,0 @@ -#! /usr/bin/perl - -# To ingest old data into the database. - -use strict; -use warnings; -use DBI; -use DBD::Pg; -use JSON::XS; -use Tie::Persistent; - -my $dbh = DBI->connect('dbi:Pg:dbname=remoteglot'); -$dbh->{AutoCommit} = 0; -$dbh->{RaiseError} = 1; - -# Import positions from history. -for my $filename () { - $filename =~ m#www/history/(.*)\.json#; - my $id = $1; - print "Analysis: $id...\n"; - - my $contents; - { - local $/ = undef; - open my $fh, "<", $filename - or die "$filename: $!"; - $contents = <$fh>; - close $fh; - } - - #$dbh->do('INSERT INTO analysis VALUES (?)', undef, $contents); - - my $json = JSON::XS::decode_json($contents); - if (defined($json->{'plot_score'})) { - my $engine = $json->{'id'}{'name'} // die; - my $depth = $json->{'depth'} // 0; - my $nodes = $json->{'nodes'} // 0; - - $dbh->do('DELETE FROM scores WHERE id=?', undef, $id); - $dbh->do('INSERT INTO scores (id, plot_score, short_score, engine, depth, nodes) VALUES (?, ?, ?, ?, ?, ?)', - undef, $id, $json->{'plot_score'}, $json->{'short_score'}, $engine, $depth, $nodes); - } -} - -# Import clock information. -tie my %clock_info_for_pos, 'Tie::Persistent', 'clock_info.db', 'rw'; - -while (my ($id, $clock_info) = each %clock_info_for_pos) { - print "Clock: $id...\n"; - $dbh->do('DELETE FROM clock_info WHERE id=?', undef, $id); - $dbh->do('INSERT INTO clock_info (id, white_clock, black_clock, white_clock_target, black_clock_target) VALUES (?, ?, ?, ?, ?)', - undef, $id, $clock_info->{'white_clock'}, $clock_info->{'black_clock'}, - $clock_info->{'white_clock_target'}, $clock_info->{'black_clock_target'}); -} - -$dbh->commit; -