From: Steinar H. Gunderson Date: Mon, 14 Feb 2005 20:25:35 +0000 (+0000) Subject: Add people into groups. X-Git-Url: https://git.sesse.net/?p=ccbs;a=commitdiff_plain;h=182d123acc98ab1fd5139be06e671d46952abbf5 Add people into groups. --- diff --git a/html/do-start-round.pl b/html/do-start-round.pl index 5cd6779..2e503bb 100755 --- a/html/do-start-round.pl +++ b/html/do-start-round.pl @@ -14,6 +14,8 @@ my $num_chosen = $cgi->param('numchosen'); my $num_groups = $cgi->param('numgroups'); my $num_qual = $cgi->param('numqual'); +$dbh->{AutoCommit} = 0; + $dbh->do('INSERT INTO rounds (tournament, round, randomsongs, chosensongs, numqualifying) VALUES (?, ?, ?, ?, ?)', undef, $tournament, $round, $num_random, $num_chosen, $num_qual); @@ -22,6 +24,41 @@ for my $i (1..$num_groups) { undef, $tournament, $round, $i); } -ccbs::print_see_other('show-tournamelt.pl?id=' . $tournament); +# Seed people into groups (quite preliminary for now) +my $people; +if ($round == 1) { + $people = ccbs::db_fetch_all($dbh, 'SELECT * FROM players WHERE player IN ( SELECT player FROM tournamentparticipation WHERE tournament=? ) ORDER BY lower(nick)', + $tournament); +} else { + die "Fix qualifying later"; +} + +# 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 (FIXME: add state to the random generator later) +for my $g (1..$num_groups) { + for my $s (1..$num_random) { + my $ref = $dbh->selectrow_hashref('SELECT * FROM songs ORDER BY random() LIMIT 1'); + $dbh->do('INSERT INTO roundrandomsongs (tournament, round, parallel, song) VALUES (?,?,?,?)', + undef, $tournament, $round, $g, $ref->{'song'}); + } +} + +ccbs::print_see_other('show-tournament.pl?id=' . $tournament); +$dbh->commit; $dbh->disconnect;