6 # Parses tournament results from the DDR Europe result list
9 my ($name, $round, $group, $player, $position, @rsongs);
10 die "Missing season (give on command line)." if (!defined($season));
15 if (/<h2> \s* (.*?) \s* <\/h2>/x) {
19 if (/<br>Country: \s* (.*?) \s*
20 <br>Location: \s* (.*?) \s*
21 <br>Date: \s* (.*?) \s*
22 <br>Mix: \s* (.*?) \s*
23 <br>ScoringSystem: \s* (.*?) \s* <br>
25 my ($country, $location, $date, $mix, $system) = ($1, $2, $3, $4, $5);
26 $mix =~ s/Euromix/EuroMix/;
28 print "INSERT INTO tournaments \n";
29 print " (season, name, country, location, \"date\", machine, scoringsystem) VALUES (\n";
30 print " (SELECT season FROM seasons WHERE name='$season'),\n";
32 print " (SELECT country FROM countries WHERE name='$country'),\n";
33 print " '$location',\n";
34 printf " '%s',\n", Date::Manip::UnixDate($date, '%Y-%m-%d');
35 print " (SELECT machine FROM machines WHERE name='$mix'),\n";
36 print " (SELECT scoringsystem FROM scoringsystems WHERE name='$system')\n";
40 # Player's results (header)
41 if (/^ <tr><td \s* class=dtd> .*? class="link"> (.*?) <\/a> $/x) {
45 printf "INSERT INTO players SELECT nextval('players_player_seq') AS player, '%s' AS nick WHERE '%s' NOT IN ( SELECT nick FROM players );\n", $player, $player;
47 printf "INSERT INTO roundparticipation (tournament, round, parallel, player, position) VALUES (\n";
48 print " (SELECT tournament FROM tournaments WHERE name='$name'),\n";
49 print " $round, $group,\n";
50 print " (SELECT player FROM players WHERE nick='$player'),\n";
56 # Player's results (score)
57 if (/<td \s* class=dtdm>/x) {
61 while (s/<td \s* class=dtdm> (\d+) <\/td>//x) {
62 printf "INSERT INTO scores (tournament, round, parallel, player, song, chosen, score) VALUES (\n";
63 print " (SELECT tournament FROM tournaments WHERE name='$name'),\n";
64 print " $round, $group,\n";
65 print " (SELECT player FROM players WHERE nick='$player'),\n";
66 print " (SELECT song FROM songs WHERE lower(title)=lower('$rsongs[$i]')),\n";
73 while (s/<td \s* class=dtdsong> .*? class="link"> (.*?) <\/a> .*? <td \s* class=dtdscore> (\d+) <\/td>//x) {
74 my $song = song_map($1);
78 printf "INSERT INTO scores (tournament, round, parallel, player, song, chosen, score) VALUES (\n";
79 print " (SELECT tournament FROM tournaments WHERE name='$name'),\n";
80 print " $round, $group,\n";
81 print " (SELECT player FROM players WHERE nick='$player'),\n";
82 print " (SELECT song FROM songs WHERE lower(title)=lower('$song')),\n";
89 if (/<h3 \s* class=dthr> Round \s* (\d+) \s* <\/h3>/x) {
92 print "INSERT INTO rounds (tournament, round, randomsongs, chosensongs) \n";
94 print " (SELECT tournament FROM tournaments WHERE name='$name'),\n";
96 print " 0, 0);\n"; # Don't worry, we'll fix it later :-P
99 # New group, and the random songs for it
100 if (/<th \s* class=dthp> ( Players | Group \s* (\d+) )<\/th>/x) {
101 # bit of an evil hack here
103 $group = 0 if ($1 eq 'Players');
107 print "INSERT INTO groups (tournament, round, parallel) VALUES (\n";
108 print " (SELECT tournament FROM tournaments WHERE name='$name'),\n";
109 print " $round, $group);\n";
111 # Find the random songs, if any
114 while (s/<th \s* class=dthpsong> .*? "color:white"> (.*?) <\/a><\/th>//x) {
115 my $song = song_map($1);
120 print "INSERT INTO roundrandomsongs (tournament, round, parallel, song) VALUES (\n";
121 print " (SELECT tournament FROM tournaments WHERE name='$name'),\n";
122 print " $round, $group,\n";
123 print " (SELECT song FROM songs WHERE lower(title)=lower('$song'))\n";
127 # Correct the random songs in the table
128 printf "UPDATE rounds SET randomsongs=%u WHERE \n", scalar @rsongs;
129 print " tournament=(SELECT tournament FROM tournaments WHERE name='$name') AND \n";
130 print " round=$round;\n";
133 # Header for chosen song (evil)
134 if (/<th \s* class=dthp \s* colspan=2> <\/th>/x) {
135 printf "UPDATE rounds SET chosensongs=1 WHERE \n";
136 print " tournament=(SELECT tournament FROM tournaments WHERE name='$name') AND \n";
137 print " round=$round;\n";
144 # different names for songs
148 $song =~ s/Paranoia -Rebirth-/PARANOiA Rebirth/;
149 $song =~ s/The Center of the heart/The Centre of the Heart (Stonebridge Club Mix)/;
150 $song =~ s/Can't stop falling in love/Can't Stop Fallin' in Love/;
151 $song =~ s/B4U -B4 ZA Beat Mix-/B4U (B4 Za Beat Mix)/;
152 $song =~ s/Jam Jam Reggae/Jam Jam Reggae (AM Swing Mix)/;
153 $song =~ s/Trip Machine -Climax-/Trip Machine Climax/;
154 $song =~ s/Dont try to stop it/Don't Try to Stop It/;
155 $song =~ s/Healing Vision -AM-/Healing Vision (Angelic Mix)/;
156 $song =~ s/5,6,7,8/5, 6, 7, 8/;
157 $song =~ s/Keep On Movin/Keep On Movin'/;
158 $song =~ s/So Deep/So Deep (Perfect Sphere Mix)/;
159 $song =~ s/Aarons Party/Aaron's Party (Come Get It)/;
160 $song =~ s/Candy \*/Candy/;
161 $song =~ s/www\.blondie girl/www.blonde girl (MOMO Mix)/;
162 $song =~ s/DXY/DXY!/;
163 $song =~ s/Burning the floor/Burnin' the Floor/;
164 $song =~ s/Never Gonna Make/Never Gonna Make (Factory Team Mix)/;
165 $song =~ s/Max300/Max 300/;
166 $song =~ s/Era/era (nostalmix)/;
167 $song =~ s/Electro Tuned/Electro Tuned (the SubS Mix)/;
168 $song =~ s/Make a Jam/Make A Jam!/;
169 $song =~ s/Paranoia KCET -clean mix-/Paranoia KCET (Clean Mix)/;
170 $song =~ s/Cant Stop -Speed Mix-/Can't Stop Fallin' in Love (SPEED MIX)/;
171 $song =~ s/Love This Feelin/Love This Feelin'/;
172 $song =~ s/Trip Machine -Luv mix-/Trip Machine (Luv Mix)/;
173 $song =~ s/Let The Beat Hit Them/Let the Beat Hit 'em!/;
174 $song =~ s/Luv To Me/Luv to Me (AMD Mix)/;
175 $song =~ s/20 November/20th November/;