- push @$pl, { nick => $player, songs => [], total => 0 };
+ push @$pl, { player => $score->{'player'}, nick => $player, songs => [], total => 0, rank => 1 };
+ }
+
+ push @{$pl->[$#$pl]->{'songs'}}, $score;
+
+ if (defined($score->{'score'})) {
+ $pl->[$#$pl]->{'total'} += $score->{'score'};
+ }
+}
+
+# Find the rank of all the players in every group, via simple insertion-like
+# sort
+for my $r (@rounds) {
+ for my $p (@{$r->{'parallels'}}) {
+ my $pls = $p->{'players'};
+ for my $i (0..$#$pls) {
+ my $rank = 1;
+ for my $j (0..($i-1)) {
+ if ($pls->[$i]->{'total'} < $pls->[$j]->{'total'}) {
+ $pls->[$i]->{'rank'}++;
+ } elsif ($pls->[$i]->{'total'} > $pls->[$j]->{'total'}) {
+ $pls->[$j]->{'rank'}++;
+ }
+ }
+ }