version 1.16, 2000/10/22 23:47:06
|
version 1.30, 2003/01/08 23:36:38
|
Line 6 updatedb.pl - a script for creation of n
|
Line 6 updatedb.pl - a script for creation of n
|
|
|
=head1 SYNOPSIS |
=head1 SYNOPSIS |
|
|
updatedb.pl I<file1> I<file2>.... |
updatedb.pl B<[-i]> I<file1> I<file2>.... |
|
|
|
|
=head1 DESCRIPTION |
=head1 DESCRIPTION |
|
|
Updates information in the B<chgk> databse. Uses file |
Updates information in the B<chgk> databse. Uses file |
|
|
|
=head1 OPTIONS |
|
|
|
=item B<-i> |
|
|
|
Ask about ParentId. |
|
|
|
|
=head1 BUGS |
=head1 BUGS |
|
|
Line 26 Dmitry Rubinstein
|
Line 32 Dmitry Rubinstein
|
|
|
=cut |
=cut |
|
|
|
use vars qw($opt_i); |
|
|
|
use Getopt::Std; |
|
getopts('i'); |
|
#open STDERR, ">errors"; |
|
my $Interactive=$opt_i || 0; |
|
|
|
|
my (%RevMonths) = |
my (%RevMonths) = |
('Jan', '1', 'Feb', '2', 'Mar', '3', 'Apr', '4', 'May', '5', 'Jun', '6', |
('Jan', '1', 'Feb', '2', 'Mar', '3', 'Apr', '4', 'May', '5', 'Jun', '6', |
'Jul', '7', 'Aug', '8', 'Sep', '9', 'Oct', '10', 'Nov', '11', |
'Jul', '7', 'Aug', '8', 'Sep', '9', 'Oct', '10', 'Nov', '11', |
Line 44 my ($sth);
|
Line 58 my ($sth);
|
|
|
use DBI; |
use DBI; |
use strict; |
use strict; |
|
my $isunsorted=0; |
sub UpdateParents { |
sub UpdateParents { |
my ($dbh, $ParentId, $all_qnum) = @_; |
my ($dbh, $ParentId, $all_qnum) = @_; |
if ($ParentId) { |
if ($ParentId) { |
Line 67 sub getField {
|
Line 81 sub getField {
|
s/[
]//g; |
s/[
]//g; |
if ($key && /^\s*$/) { |
if ($key && /^\s*$/) { |
chomp $value; |
chomp $value; |
|
$value =~ s/\s+$//; |
chomp $key; |
chomp $key; |
if ($key eq 'Дата') { |
if ($key eq 'Дата') { |
$value =~ s/^(.*)-(.*)-(.*)$/$3-$2-$1/; |
$value =~ s/^(.*)-(.*)-(.*)$/$3-$2-$1/; |
my($month) = $RevMonths{$2} || '000'; |
my($month) = $RevMonths{$2} || '01'; |
$value =~ s/$2/$month/; |
$value =~ s/-(.*)-/-$month-/; |
|
$value =~ s/-00*$/-01/; |
} |
} |
$value = $dbh->quote($value); |
$value = $dbh->quote($value); |
return ($key, $value); |
return ($key, $value); |
Line 89 sub getField {
|
Line 105 sub getField {
|
} |
} |
} |
} |
if ($key && $value) { |
if ($key && $value) { |
|
$value=~s/\s+$//; |
$value = $dbh->quote($value); |
$value = $dbh->quote($value); |
return ($key, $value); |
return ($key, $value); |
} |
} |
Line 98 sub getField {
|
Line 115 sub getField {
|
sub SelectGroup { |
sub SelectGroup { |
my ($dbh, $source, $TourName) = @_; |
my ($dbh, $source, $TourName) = @_; |
my ($sth, $ParentId, $i, @arr); |
my ($sth, $ParentId, $i, @arr); |
|
|
$sth = $dbh->prepare("SELECT Id, Title FROM |
if ($Interactive) { |
|
$sth = $dbh->prepare("SELECT Id, Title FROM |
Tournaments WHERE Type = 'Г'"); |
Tournaments WHERE Type = 'Г'"); |
$sth->execute; |
$sth->execute; |
print "Выберите группу для турнира:\n$TourName, файл $source\n\n"; |
print "Выберите группу для турнира:\n$TourName, файл $source\n\n"; |
while (@arr=$sth->fetchrow) { |
while (@arr=$sth->fetchrow) { |
print "[$arr[0]] $arr[1]\n"; |
print "[$arr[0]] $arr[1]\n"; |
} |
} |
$ParentId = <STDIN>; |
$ParentId = <STDIN>; |
chomp $ParentId; |
chomp $ParentId; |
if (!$ParentId) { |
if (!$ParentId) { |
print "Пропускаем файл $source\n"; |
print "Пропускаем файл $source\n"; |
print STDERR "Файл $source отвергнут оператором\n"; |
print STDERR "Файл $source отвергнут оператором\n"; |
return (0,0); |
return (0,0); |
|
} else { |
|
print "Вы выбрали турнир: $ParentId\n"; |
|
$sth = $dbh->prepare("INSERT INTO Tournaments |
|
(Title, Type, ParentId, FileName) |
|
VALUES ($TourName, 'Ч', $ParentId, |
|
$source)"); |
|
$sth->execute; |
|
my $TournamentId = $sth->{mysql_insertid}; |
|
return ($TournamentId,$ParentId); |
|
} |
} else { |
} else { |
print "Вы выбрали турнир: $ParentId\n"; |
# Теперь, если файла нет в дереве турниров, никаких вопросов не |
$sth = $dbh->prepare("INSERT INTO Tournaments |
# задаётся, а вместо этого он добавляется в группу 9999 |
|
$ParentId = 9999; |
|
print UNSORTED "$source".((12 -length($source))x' ')."\t$TourName\n"; |
|
$isunsorted=1; |
|
$sth = $dbh->prepare("INSERT INTO Tournaments |
(Title, Type, ParentId, FileName) |
(Title, Type, ParentId, FileName) |
VALUES ($TourName, 'Ч', $ParentId, |
VALUES ($TourName, 'Ч', $ParentId, |
$source)"); |
$source)"); |
$sth->execute; |
$sth->execute; |
my $TournamentId = $sth->{mysql_insertid}; |
my $TournamentId = $sth->{mysql_insertid}; |
return ($TournamentId,$ParentId); |
return ($TournamentId,$ParentId); |
} |
} |
|
|
|
|
} |
} |
Line 199 sub GetTours {
|
Line 231 sub GetTours {
|
} |
} |
|
|
sub CreateTour { |
sub CreateTour { |
my ($dbh,$title,$ParentId,$rh_defaults)=@_; |
my ($dbh,$title,$ParentId,$TourNum,$rh_defaults)=@_; |
my $sth = $dbh->prepare("INSERT INTO Tournaments |
my $sth = $dbh->prepare("INSERT INTO Tournaments |
(Title, Type, ParentId) |
(Title, Type, ParentId, Number) |
VALUES ($title, 'Т', $ParentId)"); |
VALUES ($title, 'Т', $ParentId, $TourNum)"); |
$sth->execute; |
$sth->execute; |
my $TourId = $sth->{mysql_insertid}; |
my $TourId = $sth->{mysql_insertid}; |
while (my ($key,$value)=each %$rh_defaults) { |
while (my ($key,$value)=each %$rh_defaults) { |
Line 228 MAIN:
|
Line 260 MAIN:
|
# |
# |
my %QuestionFields = ('Тип'=> 'Type', 'Вид'=> 'Type', |
my %QuestionFields = ('Тип'=> 'Type', 'Вид'=> 'Type', |
'Автор' => 'Authors', 'Рейтинг'=>'Rating', |
'Автор' => 'Authors', 'Рейтинг'=>'Rating', |
'Источник' => 'Sources'); |
'Источник' => 'Sources', |
|
'Тема' => 'Topic'); |
|
|
|
|
my($source); |
my($source); |
|
|
my($dbh) = DBI->connect("DBI:mysql:chgk", "piataev", "") |
my($dbh) = DBI->connect("DBI:mysql:chgk", "piataev", "") |
or die "Can't connect to DB chgk\n"; |
or die "Can't connect to DB chgk\n"; |
|
my @sources; |
|
open UNSORTED, ">unsorted"; |
while ($source = shift) { |
while ($source = shift) { |
|
push @sources,glob($source); |
|
} |
|
foreach $source(@sources) { |
|
my $TourNum=0; |
my($PlayedAt) = ''; |
my($PlayedAt) = ''; |
my($QuestionId, $TourId, $TournamentId, $ParentId) = (0, 0, 0, 0); |
my($QuestionId, $TourId, $TournamentId, $ParentId) = (0, 0, 0, 0); |
my($tournum, $qnum, $all_qnum) = (0, 0, 0); |
my($tournum, $qnum, $all_qnum) = (0, 0, 0); |
Line 281 MAIN:
|
Line 319 MAIN:
|
WHERE Id=$TourId"); |
WHERE Id=$TourId"); |
} |
} |
$qnum = 0; |
$qnum = 0; |
$TourId=CreateTour($dbh,$value,$TournamentId,\%TourDefaults); |
$TourNum++; |
|
$TourId=CreateTour($dbh,$value,$TournamentId,$TourNum, |
|
\%TourDefaults); |
%QuestionDefaults=%QuestionGlobalDefaults; |
%QuestionDefaults=%QuestionGlobalDefaults; |
$QuestionId=0; |
$QuestionId=0; |
next; |
next; |
Line 289 MAIN:
|
Line 329 MAIN:
|
if ($key =~ /Вопрос/) { |
if ($key =~ /Вопрос/) { |
if (!$TourId) { |
if (!$TourId) { |
$qnum = 0; |
$qnum = 0; |
$TourId=CreateTour($dbh,'1',$TournamentId, |
$TourNum++; |
|
$TourId=CreateTour($dbh,'1',$TournamentId,$TourNum, |
\%TourDefaults); |
\%TourDefaults); |
%QuestionDefaults=%QuestionGlobalDefaults; |
%QuestionDefaults=%QuestionGlobalDefaults; |
} |
} |
Line 364 MAIN:
|
Line 405 MAIN:
|
&UpdateParents($dbh, $ParentId, $all_qnum); |
&UpdateParents($dbh, $ParentId, $all_qnum); |
print STDERR "Всего вопросов: $all_qnum \n"; |
print STDERR "Всего вопросов: $all_qnum \n"; |
} |
} |
|
close UNSORTED; |
|
unlink "unsorted" unless $isunsorted; |
$dbh->disconnect; |
$dbh->disconnect; |
} |
} |