]> git.sesse.net Git - ccbs/blobdiff - html/do-start-round.pl
Revert change to wrong branch.
[ccbs] / html / do-start-round.pl
index ea6894e7126e88f5fcf66fa614baf75331cb3a77..d843be2fb6e882374ca602535e3bf57e97d867ce 100755 (executable)
@@ -4,6 +4,8 @@ use ccbs;
 use strict;
 use warnings;
 
+ccbs::admin_only();
+
 my $dbh = ccbs::db_connect();
 my $cgi = new CGI;
 
@@ -19,9 +21,14 @@ $dbh->{AutoCommit} = 0;
 $dbh->do('INSERT INTO rounds (tournament, round, randomsongs, chosensongs, numqualifying) VALUES (?, ?, ?, ?, ?)',
        undef, $tournament, $round, $num_random, $num_chosen, $num_qual);
 
-for my $i (1..$num_groups) {
+if ($num_groups == 1) {
        $dbh->do('INSERT INTO groups (tournament, round, parallel) VALUES (?, ?, ?)',
-               undef, $tournament, $round, $i);
+               undef, $tournament, $round, 0);
+} else {
+       for my $i (1..$num_groups) {
+               $dbh->do('INSERT INTO groups (tournament, round, parallel) VALUES (?, ?, ?)',
+                       undef, $tournament, $round, $i);
+       }
 }
 
 # Seed people into groups (quite preliminary for now)
@@ -61,24 +68,36 @@ if ($round == 1) {
        }
 }
 
-# Zigzag people to get the most fair groups possible
-my $group = 1;
-my $direction = 1;
-my $position = 1;
-for my $p (@$people) {
-       $dbh->do('INSERT INTO roundparticipation (tournament, round, parallel, player, position) VALUES (?, ?, ?, ?, ?)', undef,
-               $tournament, $round, $group, $p->{'player'}, $position);
-
-       if ($group + $direction < 1 || $group + $direction > $num_groups) {
-               $direction = -$direction;
+if ($num_groups == 1) {
+       # Everybody's in the same group
+       my $position = 1;
+       for my $p (@$people) {
+               $dbh->do('INSERT INTO roundparticipation (tournament, round, parallel, player, position) VALUES (?, ?, ?, ?, ?)', undef,
+                       $tournament, $round, 0, $p->{'player'}, $position);
                $position++;
-       } else {
-               $group += $direction;
+       }
+} else {
+       # Zigzag people to get the most fair groups possible
+       my $group = 1;
+       my $direction = 1;
+       my $position = 1;
+       for my $p (@$people) {
+               $dbh->do('INSERT INTO roundparticipation (tournament, round, parallel, player, position) VALUES (?, ?, ?, ?, ?)', undef,
+                               $tournament, $round, $group, $p->{'player'}, $position);
+
+               if ($group + $direction < 1 || $group + $direction > $num_groups) {
+                       $direction = -$direction;
+                       $position++;
+               } else {
+                       $group += $direction;
+               }
        }
 }
 
 # Pick random songs for the groups
 for my $g (1..$num_groups) {
+       my $gg = ($num_groups == 1) ? 0 : $g;
+
        for my $s (1..$num_random) {
                my $ref = $dbh->selectrow_hashref('SELECT * FROM machinesongs WHERE song NOT IN ( SELECT song FROM randomsongsused ) AND machine=( SELECT machine FROM tournaments WHERE tournament=? ) ORDER BY random() LIMIT 1',
                        undef, $tournament);
@@ -88,18 +107,20 @@ for my $g (1..$num_groups) {
                $dbh->do('INSERT INTO randomsongsused (song) VALUES (?)',
                        undef, $ref->{'song'});
                $dbh->do('INSERT INTO roundrandomsongs (tournament, round, parallel, song) VALUES (?,?,?,?)',
-                       undef, $tournament, $round, $g, $ref->{'song'});
+                       undef, $tournament, $round, $gg, $ref->{'song'});
 
-               $dbh->do('INSERT INTO scores SELECT tournament,round,parallel,player,?,?,NULL,NULL,\'f\',NULL FROM roundparticipation WHERE tournament=? AND round=? AND parallel=?', undef,
-                       $s, $ref->{'song'}, $tournament, $round, $g);
+               $dbh->do('INSERT INTO scores SELECT tournament,round,parallel,player,?,?,\'single\',\'expert\',\'f\',NULL FROM roundparticipation WHERE tournament=? AND round=? AND parallel=?', undef,
+                       $s, $ref->{'song'}, $tournament, $round, $gg);
        }
 }
 
 # Add empty "score" records for the chosen songs.
 for my $g (1..$num_groups) {
+       my $gg = ($num_groups == 1) ? 0 : $g;
+
        for my $s (1..$num_chosen) {
-               $dbh->do('INSERT INTO scores SELECT tournament,round,parallel,player,?,NULL,NULL,NULL,\'t\',NULL FROM roundparticipation WHERE tournament=? AND round=? AND parallel=?', undef,
-                       $s + $num_random, $tournament, $round, $g);
+               $dbh->do('INSERT INTO scores SELECT tournament,round,parallel,player,?,NULL,\'single\',\'expert\',\'t\',NULL FROM roundparticipation WHERE tournament=? AND round=? AND parallel=?', undef,
+                       $s + $num_random, $tournament, $round, $gg);
        }
 }