6 # Parses tournament results from the DDR Europe result list
9 my ($name, $round, $group, $player, @rsongs);
10 die "Missing season (give on command line)." if (!defined($season));
12 # commented out -- see player below
16 if (/<h2> \s* (.*?) \s* <\/h2>/x) {
20 if (/<br>Country: \s* (.*?) \s*
21 <br>Location: \s* (.*?) \s*
22 <br>Date: \s* (.*?) \s*
23 <br>Mix: \s* (.*?) \s*
24 <br>ScoringSystem: \s* (.*?) \s* <br>
26 my ($country, $location, $date, $mix, $system) = ($1, $2, $3, $4, $5);
27 $mix =~ s/Euromix/EuroMix/;
29 print "INSERT INTO tournaments \n";
30 print " (season, name, country, location, \"date\", machine, scoringsystem) VALUES (\n";
31 print " (SELECT season FROM seasons WHERE name='$season'),\n";
33 print " (SELECT country FROM countries WHERE name='$country'),\n";
34 print " '$location',\n";
35 printf " '%s',\n", Date::Manip::UnixDate($date, '%Y-%m-%d');
36 print " (SELECT machine FROM machines WHERE name='$mix'),\n";
37 print " (SELECT scoringsystem FROM scoringsystems WHERE name='$system')\n";
41 # Player's results (header)
42 if (/^ <tr><td \s* class=dtd> .*? class="link"> (.*?) <\/a> $/x) {
44 printf "INSERT INTO players (nick) VALUES ('%s');\n", $player;
45 printf "INSERT INTO roundparticipation (tournament, round, parallel, player) VALUES (\n";
46 print " (SELECT tournament FROM tournaments WHERE name='$name'),\n";
47 print " $round, $group,\n";
48 print " (SELECT player FROM players WHERE nick='$player')\n";
52 # Player's results (score)
53 if (/<td \s* class=dtdm>/x) {
57 while (s/<td \s* class=dtdm> (\d+) <\/td>//x) {
58 printf "INSERT INTO scores (tournament, round, parallel, player, song, chosen, score) VALUES (\n";
59 print " (SELECT tournament FROM tournaments WHERE name='$name'),\n";
60 print " $round, $group,\n";
61 print " (SELECT player FROM players WHERE nick='$player'),\n";
62 print " (SELECT song FROM songs WHERE lower(title)=lower('$rsongs[$i]')),\n";
69 while (s/<td \s* class=dtdsong> .*? class="link"> (.*?) <\/a> .*? <td class=dtdscore> (\d+) <\/td>//x) {
70 my $song = song_map($1);
73 printf "INSERT INTO scores (tournament, round, parallel, player, song, chosen, score) VALUES (\n";
74 print " (SELECT tournament FROM tournaments WHERE name='$name'),\n";
75 print " $round, $group,\n";
76 print " (SELECT player FROM players WHERE nick='$player'),\n";
77 print " (SELECT song FROM songs WHERE lower(title)=lower('$song')),\n";
84 if (/<h3 \s* class=dthr> Round \s* (\d+) \s* <\/h3>/x) {
87 print "INSERT INTO rounds (tournament, round, randomsongs, chosensongs) \n";
89 print " (SELECT tournament FROM tournaments WHERE name='$name'),\n";
91 print " 0, 0);\n"; # Don't worry, we'll fix it later :-P
94 # New group, and the random songs for it
95 if (/<th \s* class=dthp> ( Players | Group \s* (\d+) )<\/th>/x) {
96 # bit of an evil hack here
98 $group = 0 if ($1 eq 'Players');
100 print "INSERT INTO groups (tournament, round, parallel) VALUES (\n";
101 print " (SELECT tournament FROM tournaments WHERE name='$name'),\n";
102 print " $round, $group);\n";
104 # Find the random songs, if any
107 while (s/<th \s* class=dthpsong> .*? "color:white"> (.*?) <\/a><\/th>//x) {
108 my $song = song_map($1);
113 print "INSERT INTO roundrandomsongs (tournament, round, parallel, song) VALUES (\n";
114 print " (SELECT tournament FROM tournaments WHERE name='$name'),\n";
115 print " $round, $group,\n";
116 print " (SELECT song FROM songs WHERE lower(title)=lower('$song'))\n";
120 # Correct the random songs in the table
121 printf "UPDATE rounds SET randomsongs=%u WHERE \n", scalar @rsongs;
122 print " tournament=(SELECT tournament FROM tournaments WHERE name='$name') AND \n";
123 print " round=$round;\n";
126 # Header for chosen song (evil)
127 if (/<th \s* class=dthp \s* colspan=2> <\/th>/x) {
128 printf "UPDATE rounds SET chosensongs=1 WHERE \n";
129 print " tournament=(SELECT tournament FROM tournaments WHERE name='$name') AND \n";
130 print " round=$round;\n";
137 # different names for songs
141 $song =~ s/Paranoia -Rebirth-/PARANOiA Rebirth/;
142 $song =~ s/The Center of the heart/The Centre of the Heart (Stonebridge Club Mix)/;
143 $song =~ s/Can't stop falling in love/Can't Stop Fallin' in Love/;
144 $song =~ s/B4U -B4 ZA Beat Mix-/B4U (B4 Za Beat Mix)/;
145 $song =~ s/Jam Jam Reggae/Jam Jam Reggae (AM Swing Mix)/;
146 $song =~ s/Trip Machine -Climax-/Trip Machine Climax/;
147 $song =~ s/Dont try to stop it/Don't Try to Stop It/;
148 $song =~ s/Healing Vision -AM-/Healing Vision (Angelic Mix)/;
149 $song =~ s/5,6,7,8/5, 6, 7, 8/;
150 $song =~ s/Keep On Movin/Keep On Movin'/;
151 $song =~ s/So Deep/So Deep (Perfect Sphere Mix)/;
152 $song =~ s/Aarons Party/Aaron's Party (Come Get It)/;