From ea702e677702b5cbb22f819d8f0731715e887d03 Mon Sep 17 00:00:00 2001 From: "Steinar H. Gunderson" Date: Mon, 14 Feb 2005 22:05:06 +0000 Subject: [PATCH] Add state to the random song chooser, so it doesn't choose the same songs twice. Only choose songs from the mix used in this tournament. --- html/do-start-round.pl | 10 ++++++++-- sql/ccbs.sql | 4 ++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/html/do-start-round.pl b/html/do-start-round.pl index ff0a417..2637076 100755 --- a/html/do-start-round.pl +++ b/html/do-start-round.pl @@ -49,10 +49,16 @@ for my $p (@$people) { } } -# Pick random songs for the groups (FIXME: add state to the random generator later) +# Pick random songs for the groups 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'); + 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); + if (!defined($ref)) { + ccbs::user_error('Det er ikke flere sanger igjen i sangvelgeren!'); + } + $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'}); diff --git a/sql/ccbs.sql b/sql/ccbs.sql index 19eeb0e..d7d461f 100644 --- a/sql/ccbs.sql +++ b/sql/ccbs.sql @@ -152,3 +152,7 @@ CREATE TABLE scores ( FOREIGN KEY (tournament, round, parallel, player) REFERENCES roundparticipation (tournament, round, parallel, player), PRIMARY KEY (tournament, round, parallel, player, songnumber) ); + +CREATE TABLE randomsongsused ( + song INTEGER NOT NULL PRIMARY KEY REFERENCES songs +); -- 2.39.2