DGS SK 2005/Nastroje

Sub-page of DGSSK2005

This page or section is in the slovak language.


Perlovsky skript na generovanie tabulky hracov a komi:

 #!/usr/bin/perl -w
 # reads from the input file a komitable and a sequence of uids
 # makes on the output the table of games and komi used according to
 # the table in komi lines in the input file
 # usage: maketable.pl input.txt output.txt
 # Made by: Zerodan
 $inputfile=shift @ARGV; print "The INPUTFILE = ".$inputfile."\n";
 $outputfile=shift @ARGV; print "The OUTPUTFILE = ".$outputfile."\n";
 if (!open(INPUTFILE, "<".$inputfile)) {
     print STDERR "Can't open $inputfile...\n";
 }
 if (!open(OUTPUTFILE, ">".$outputfile)) {
     print STDERR "Can't open $outputfile...\n";
 }
 $intpat='[+-]?\d+';
 $strpat ='\w+';
 $menopat = "\<tr\>\<td\>\<b\>Meno\</b\>\</td\>\<td\>(.*)\</td\>\</tr\>";
 $triedapat = "Trieda.*black>(.*)\&.*;(.*)\&.*;.($intpat)%";
 use LWP 5.64;
 my $browser = LWP::UserAgent->new;
 use HTTP::Cookies;
 # yes, loads HTTP::Cookies::Netscape too
 $browser->cookie_jar( HTTP::Cookies::Netscape->new(
    'file' => 'cookies.txt',
         # where to read cookies
   ));
 @rankb = ();
 @komi = ();
 @hrac = ();
 @rank = ();
 @zesort = ();
 @skupina = ();
 $linecounter = 0;
 $th = 0;
 $ph = 0;
 $maxname = 6;
 # pocet skupin, ktore sa vytvoria z danej mnoziny hracov
 $ps = 1;
 # sposob vytvorenia skupin
 $ss = 1;
 print "Vstupny subor sa spracovava.\n";
 while (<INPUTFILE>)
 {
     $line = $_;
     if ($line =~ /^\s*$intpat\s+$intpat/)
     {
 #      print "1. vzor: ", $line;
        ($line =~ /^\s*($intpat)\s+($intpat)/);
        $krb = $1;
        $krk = $2;
        push(@rankb,$krb);
        push(@komi,$krk);
        $th++;
 #      print "Komi pravidlo: ",$krb," ",$krk,"\n";
     }
     else
     {
        if ($line =~ /^$intpat/)
        {
 #          print "2. vzor: ", $line;
            ($line =~ /^($intpat)/);
            $uid = $1;
            $urlbase = '[ext] http://www.dragongoserver.net/userinfo.php?uid=';
            $url = sprintf("%s%d",$urlbase,$1); print($url);
            $response = $browser->get( $url);
            die "Can't get $url -- ", $response->status_line
                unless $response->is_success;
            die "Hey, I was expecting HTML, not ", $response->content_type
                unless $response->content_type eq 'text/html';
 # Then go do things with $content, like this:
            if($response->content =~ /$menopat/)
            {
                ($response->content =~ /$menopat/);
                $meno = $1;
 #              print "Meno=",$meno;
                ($response->content =~ /$triedapat/);
                $trieda = $1;
                $kd = $2;
                $uroven = $3;
 #              print "trieda=",$trieda,"\nkd=",$kd,"\nuroven=", $uroven,"\n";
            }
            else
            {
                print "Co to je za stranka?\n";
            }
            $udaje{$meno} = sprintf("%s %d %s (%+d%s)",$meno,$trieda,$kd,$uroven,"%");
            $huid{$meno} = $uid;
            if (length($meno) > $maxname) {$maxname = length($meno);}
            push(@hrac,$meno);
            if ($kd =~ /kyu/)
            {
                $body = $trieda*(-100)+$uroven;
                push(@rank,$body);
                $ph++;
 #              print $meno," ", $trieda," ", $kd," ", $uroven," ",$body,"\n";
            }
            else {
                if ($kd =~ /dan/)
                {
                    $body = ($trieda-1)*(100)+$uroven;
                    push(@rank,$body);
                    $ph++;
 #                  print $meno," ", $trieda," ", $kd," ", $uroven," ",$body,"\n";
                }
                else
                {
                    print "Cudna trieda (treba: kyu, dan).\n"
                    }
            }
        }
        else
        {
            if ($line =~ /^\s*GROUPS:\s*$intpat/)
            {
                ($line =~ /^\s*GROUPS:\s*($intpat)/) ;
                $ps = $1;
            }
            else
            {
                if ($line =~ /^\s*SPLITWAY:\s*$intpat/)
                {
                    ($line =~ /^\s*SPLITWAY:\s*($intpat)/) ;
                    $ss = $1;
                }
            }
        }
     }
     $linecounter++;
 }
 ##tu utried $rank, $hrac
 for($i=0; $i < $ph; $i++)
 {
     $hracbody{$hrac[$i]} = $rank[$i];
 #    print $hracbody{$hrac[$i]}, " ";
 }
 @zesort = sort {$hracbody{$b} <=> $hracbody{$a}} @hrac;
 if ($ss == 1)
 {
     for ($i = 0; $i < $ps; $i++) {push @skupina,[()];}
     for ($i = 0; $i < $ph; $i++)
     {
        $skupina[$i % $ps][($i - ($i % $ps))/ $ps] = $i;
        print $i, " ",$i % $ps, " ",($i - ($i % $ps))/ $ps," -> ",$skupina[$i % $ps][($i - ($i % $ps))/$ps],"\n";
     }
 }
 # Vyrob vystupne data - tabulku s komi pre hry
 $maxname++;
 $onenameformat = sprintf("%s%d%s","%-",$maxname,"s");
 $spaceonenameformat = sprintf("%s%s","%s%3s",$onenameformat);
 $spaceonekomiformat = sprintf("%s%d%s","%s%3s%4d%",$maxname-4,"s");
 #print $linecounter," precitanych riadkov.\n";
 print OUTPUTFILE "Komi tabulka.\n";
 print OUTPUTFILE "-------------\n\n";
 for ($k = 0; $k < $th; $k++)
 {
     print OUTPUTFILE $rankb[$k], " ", $komi[$k], "\n";
 }
 print OUTPUTFILE "\n\n";
 #print $ph, "\n";
 for ($isk = 0; $isk < $ps; $isk++)
 {
     print OUTPUTFILE $isk+1,". skupina \n";
     print OUTPUTFILE "Zoznam hracov:\n";
     print OUTPUTFILE "--------------\n\n";
     $sph = $#{$skupina[$isk]}+1; #print $sph," ", join(" ",@{$skupina[$isk]}),"\n";
     for ($i = 0; $i < $sph; $i++)
     {
        print OUTPUTFILE "[",$udaje{$zesort[$skupina[$isk][$i]]},"|",$urlbase,$huid{$zesort[$skupina[$isk][$i]]},"]\n";
     }
     print OUTPUTFILE "\n\n";
     print OUTPUTFILE "Tabulka komi pre vzajomne zapasy:\n";
     print OUTPUTFILE "---------------------------------\n\n";
     $line = sprintf($onenameformat,"");
     for ($i = 0; $i < $sph; $i++)
     {
        $namelen = length($zesort[$skupina[$isk][$i]]);
        if ($namelen  < 7) {$namelen = 7;}
        $thisnameformat = sprintf("%s%d%s","%-",$namelen,"s"),
        $spacethisnameformat = sprintf("%s%s","%s%3s",$thisnameformat),
        $line = sprintf($spacethisnameformat,$line,"   ",$zesort[$skupina[$isk][$i]]);
     }
     print OUTPUTFILE $line, "\n";
     for ($i = 0; $i < $sph; $i++)
     {
        $line = sprintf($onenameformat,$zesort[$skupina[$isk][$i]]);
        for ($j = 0; $j < $sph; $j++)
        {
            $namelen = length($zesort[$skupina[$isk][$j]]);
            if ($namelen  < 7) {$namelen = 7;}
            $thisnameformat = sprintf("%s%d%s","%-",$namelen,"s"),
            $spacethisnameformat = sprintf("%s%s","%s%3s",$thisnameformat),
            $spacethiskomiformat = sprintf("%s%d%s","%s%3s%4d%",$namelen-4,"s");
            if ($i != $j)
            {
                $dif = abs($hracbody{$zesort[$skupina[$isk][$i]]} - $hracbody{$zesort[$skupina[$isk][$j]]});
 #          print $i, " ", $j, " ", $dif, "\n";
                $k = 0; $tgk = $komi[0];
                while (($k < $th) && ($dif > $rankb[$k]))
                {
                    $tgk = $komi[$k];
                    $k++;
                }
                $line = sprintf($spacethiskomiformat,$line,"   ",$tgk," ");
 #          print $hrac[$i], " ", $hrac[$j], " ", $tgk,"\n";
            }
            else
            {
                $line = sprintf($spacethisnameformat,$line,"   ","****");
            }
        }
        print OUTPUTFILE $line,"\n";
     }
 }

Priklad vstupneho suboru:


 GROUPS: 2
 SPLITWAY: 1
    0   6
   50   5
  200   4
  350   3
  500   2
  650   1
  800   0
  950  -1
 1100  -2
 1250  -3
 1400  -4
 1550  -5
 1700  -6
 1850  -7
 2000  -8
 2150  -9
 2300 -10
 2450 -11
 2600 -12
 2750 -13
 2900 -14
 3050 -15
 3200 -16
 103
 145
 175
 197
 231
 264
 347
 448
 1285
 1602
 2202
 2813
 4483
 5025
 5555
 5758
 7389
 7398
 7445
 7959
 13741
 14403
 15262
 17987
 17999
 18197
 18602


This is a copy of the living page "DGS SK 2005/Nastroje" at Sensei's Library.
(OC) 2009 the Authors, published under the OpenContent License V1.0.
[Welcome to Sensei's Library!]
StartingPoints
ReferenceSection
About