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 class=dtdscore> (\d+) <\/td>//x) {
74 my $song = song_map($1);
77 printf "INSERT INTO scores (tournament, round, parallel, player, song, chosen, score) VALUES (\n";
78 print " (SELECT tournament FROM tournaments WHERE name='$name'),\n";
79 print " $round, $group,\n";
80 print " (SELECT player FROM players WHERE nick='$player'),\n";
81 print " (SELECT song FROM songs WHERE lower(title)=lower('$song')),\n";
88 if (/<h3 \s* class=dthr> Round \s* (\d+) \s* <\/h3>/x) {
91 print "INSERT INTO rounds (tournament, round, randomsongs, chosensongs) \n";
93 print " (SELECT tournament FROM tournaments WHERE name='$name'),\n";
95 print " 0, 0);\n"; # Don't worry, we'll fix it later :-P
98 # New group, and the random songs for it
99 if (/<th \s* class=dthp> ( Players | Group \s* (\d+) )<\/th>/x) {
100 # bit of an evil hack here
102 $group = 0 if ($1 eq 'Players');
106 print "INSERT INTO groups (tournament, round, parallel) VALUES (\n";
107 print " (SELECT tournament FROM tournaments WHERE name='$name'),\n";
108 print " $round, $group);\n";
110 # Find the random songs, if any
113 while (s/<th \s* class=dthpsong> .*? "color:white"> (.*?) <\/a><\/th>//x) {
114 my $song = song_map($1);
119 print "INSERT INTO roundrandomsongs (tournament, round, parallel, song) VALUES (\n";
120 print " (SELECT tournament FROM tournaments WHERE name='$name'),\n";
121 print " $round, $group,\n";
122 print " (SELECT song FROM songs WHERE lower(title)=lower('$song'))\n";
126 # Correct the random songs in the table
127 printf "UPDATE rounds SET randomsongs=%u WHERE \n", scalar @rsongs;
128 print " tournament=(SELECT tournament FROM tournaments WHERE name='$name') AND \n";
129 print " round=$round;\n";
132 # Header for chosen song (evil)
133 if (/<th \s* class=dthp \s* colspan=2> <\/th>/x) {
134 printf "UPDATE rounds SET chosensongs=1 WHERE \n";
135 print " tournament=(SELECT tournament FROM tournaments WHERE name='$name') AND \n";
136 print " round=$round;\n";
143 # different names for songs
147 $song =~ s/Paranoia -Rebirth-/PARANOiA Rebirth/;
148 $song =~ s/The Center of the heart/The Centre of the Heart (Stonebridge Club Mix)/;
149 $song =~ s/Can't stop falling in love/Can't Stop Fallin' in Love/;
150 $song =~ s/B4U -B4 ZA Beat Mix-/B4U (B4 Za Beat Mix)/;
151 $song =~ s/Jam Jam Reggae/Jam Jam Reggae (AM Swing Mix)/;
152 $song =~ s/Trip Machine -Climax-/Trip Machine Climax/;
153 $song =~ s/Dont try to stop it/Don't Try to Stop It/;
154 $song =~ s/Healing Vision -AM-/Healing Vision (Angelic Mix)/;
155 $song =~ s/5,6,7,8/5, 6, 7, 8/;
156 $song =~ s/Keep On Movin/Keep On Movin'/;
157 $song =~ s/So Deep/So Deep (Perfect Sphere Mix)/;
158 $song =~ s/Aarons Party/Aaron's Party (Come Get It)/;