+ my @scenario = ();
+ open MCCALC, "$config::base_dir/mcwordfeud $trials $match_player $match_position < $tmpnam |"
+ or die "mccalc: $!";
+ while (<MCCALC>) {
+ /(\d+) (\d+) (-?\d+)/ or next;
+ chomp;
+ push @scenario, {
+ 'player-1' => $players{$1},
+ 'player-2' => $players{$2},
+ 'result' => sprintf("%+d", $3),
+ };
+ }
+ close MCCALC;
+ unlink $tmpnam;
+
+ my @sorted_players = sort { $players{$a} cmp $players{$b} } keys %players;
+ my $player_name = $players{$sorted_players[$match_player]};
+
+ if (scalar @scenario == 0) {
+ print CGI->header(-type=>'text/html; charset=utf-8', -expires=>'+5m');
+ wloh_common::process_template('scenario-not-found', $locale, {
+ '#nick' => $player_name,
+ '#rank' => sprintf("%d.", $match_position + 1)
+ });
+ } else {
+ print CGI->header(-type=>'text/html; charset=utf-8', -expires=>'+5m');
+ wloh_common::process_template('scenario', $locale, {
+ '#nick' => $player_name,
+ '#rank' => sprintf("%d.", $match_position + 1),
+ '#results' => \@scenario
+ });
+ }
+} else {
+ wloh_common::set_locale($locale);
+
+ my $max_division = $divisions[$#divisions];
+ my $lowest_division = ($division == $max_division);
+ my $basic_table = make_table($locale, $aux_parms, $match_stddev, $lowest_division, {}, {}, $division, $subdivision, 'scenario1');
+ my $adjusted_table = make_table($locale, $aux_parms, $match_stddev, $lowest_division, \%ratings, $cov, $division, $subdivision, 'scenario2');
+ my $cov_table = (defined($cgi->param('showcov'))) ? make_cov_table($cov) : '';
+
+ my $avg_rating = find_avg_rating(\%ratings);
+
+ print CGI->header(-type=>'text/html; charset=utf-8', -expires=>'+5m');
+ wloh_common::process_template('index', $locale, {
+ '#navbar' => wloh_common::get_navbar($cgi, $dbh, $locale),
+ '#division-selector/action' => "/$locale/",
+ '#division' => get_division_selector(\@divisions, $division),
+ '#subdivision' => get_division_selector(\@subdivisions, $subdivision),
+ '#basic-probabilities' => $basic_table,
+ '#adjusted-probabilities' => $adjusted_table,
+ 'cov-table' => $cov_table,
+ 'match-stddev' => sprintf("%.1f", $match_stddev),
+ '#average-rating' => sprintf("%.1f", $avg_rating),
+ 'last-sync' => wloh_common::get_last_sync($dbh),
+ });
+}