Tournament table: add the support of rounds.
This commit is contained in:
parent
10f96915a0
commit
7244b0435a
@ -5,7 +5,8 @@ module LORChess
|
||||
|
||||
require 'yaml'
|
||||
|
||||
DATADIR='2014/1-tabiyas'
|
||||
DATADIR = '2014/1-tabiyas'
|
||||
ROUNDS = 2
|
||||
|
||||
dir = File.dirname(__FILE__)
|
||||
players_yaml = File.expand_path("../../#{DATADIR}/players.yml", dir)
|
||||
@ -14,6 +15,7 @@ module LORChess
|
||||
@@db_results = YAML.load_file results_yaml
|
||||
|
||||
@@dim = @@db_players.length
|
||||
@@rounds = ROUNDS || 1
|
||||
|
||||
# Sort players in numerical order
|
||||
@@db_players.sort! { |x,y| x['number'] <=> y['number'] }
|
||||
@ -21,11 +23,13 @@ module LORChess
|
||||
def initialize
|
||||
@players = @@db_players.map { |player| player['lor'] }
|
||||
@elo_points = @@db_players.map { |player| player['elo'].to_s }
|
||||
@game_scores = Array.new(@@dim) { Array.new(@@dim) }
|
||||
@player_games = []
|
||||
@total_scores = []
|
||||
@player_places = []
|
||||
@berger_coefs = []
|
||||
@game_scores = Array.new(@@rounds) {
|
||||
Array.new(@@dim) { Array.new(@@dim) }
|
||||
}
|
||||
@player_games = Array.new(@@dim, 0)
|
||||
@total_scores = Array.new(@@dim, 0.0)
|
||||
@player_places = Array.new(@@dim)
|
||||
@berger_coefs = Array.new(@@dim, 0.0)
|
||||
@buffer = ''
|
||||
|
||||
# Players withdrew from tournament
|
||||
@ -50,23 +54,27 @@ module LORChess
|
||||
|
||||
def fill_results
|
||||
@@db_results.each do |tour|
|
||||
# zero-based round
|
||||
round = (tour['number'] - 1).div(@@dim)
|
||||
|
||||
tour['games'].each do |game|
|
||||
import game
|
||||
import game, round
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def import game
|
||||
def import game, round
|
||||
num_white = @player_numbers[game['white']]
|
||||
num_black = @player_numbers[game['black']]
|
||||
score = game['result'].split ':'
|
||||
|
||||
@game_scores[num_white][num_black] = score[0].to_f
|
||||
@game_scores[num_black][num_white] = score[1].to_f
|
||||
@game_scores[round][num_white][num_black] = score[0].to_f
|
||||
@game_scores[round][num_black][num_white] = score[1].to_f
|
||||
end
|
||||
|
||||
def calculate
|
||||
@game_scores.each do |row|
|
||||
@game_scores.each do |round|
|
||||
round.each_with_index do |row, index|
|
||||
games = 0
|
||||
sum = 0.0
|
||||
row.each do |score|
|
||||
@ -75,8 +83,9 @@ module LORChess
|
||||
sum += score
|
||||
end
|
||||
end
|
||||
@player_games << games.to_s
|
||||
@total_scores << sum
|
||||
@player_games[index] += games
|
||||
@total_scores[index] += sum
|
||||
end
|
||||
end
|
||||
|
||||
calculate_berger
|
||||
@ -110,17 +119,24 @@ module LORChess
|
||||
end
|
||||
|
||||
def calculate_berger
|
||||
@berger_coefs = @game_scores.map do |row|
|
||||
@game_scores.each do |round|
|
||||
round.each_with_index do |row, index|
|
||||
berger = 0.0
|
||||
row.each_with_index do |score, i|
|
||||
berger += score * @total_scores[i] unless score.nil?
|
||||
end
|
||||
berger
|
||||
@berger_coefs[index] += berger
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def results_to_s
|
||||
@game_scores.map! { |row| row.map { |cell| stylize_score cell } }
|
||||
@game_scores.map! do |round|
|
||||
round.map do |row|
|
||||
row.map { |cell| stylize_score cell }
|
||||
end
|
||||
end
|
||||
@player_games.map! { |num| num.to_s }
|
||||
@total_scores.map! { |score| stylize_score score }
|
||||
@berger_coefs.map! { |coef| coef.to_s }
|
||||
end
|
||||
@ -148,7 +164,7 @@ module LORChess
|
||||
@buffer << " <th>Участник</th>\n"
|
||||
@buffer << " <th>elo*</th>\n"
|
||||
|
||||
@@dim.times do |i|
|
||||
(@@dim * @@rounds).times do |i|
|
||||
@buffer << " <th class=\"{sorter: false}\">" << (i + 1).to_s << "</th>\n"
|
||||
end
|
||||
|
||||
@ -160,7 +176,7 @@ module LORChess
|
||||
@buffer << " </thead>\n"
|
||||
@buffer << " <tfoot>\n"
|
||||
@buffer << " <tr>\n"
|
||||
@buffer << " <td colspan=\"" << (@@dim + 7).to_s << "\">* Средний elo на начало турнира</td>\n"
|
||||
@buffer << " <td colspan=\"" << (@@dim * @@rounds + 7).to_s << "\">* Средний elo на начало турнира</td>\n"
|
||||
@buffer << " </tr>\n"
|
||||
@buffer << " </tfoot>\n"
|
||||
@buffer << " <tbody>\n"
|
||||
@ -172,13 +188,15 @@ module LORChess
|
||||
@buffer << " <td class=\"player\"><strong>" << @players[i] << "</strong></td>\n"
|
||||
@buffer << " <td class=\"elo\">" << @elo_points[i] << "</td>\n"
|
||||
|
||||
@@rounds.times do |round|
|
||||
@@dim.times do |j|
|
||||
unless j == i
|
||||
@buffer << " <td class=\"score\">" << @game_scores[i][j] << "</td>\n"
|
||||
@buffer << " <td class=\"score\">" << @game_scores[round][i][j] << "</td>\n"
|
||||
else
|
||||
@buffer << " <td class=\"diagonal\"></td>\n"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@buffer << " <td class=\"games\">" << @player_games[i] << "</td>\n"
|
||||
@buffer << " <td class=\"total\">" << @total_scores[i] << "</td>\n"
|
||||
|
Loading…
Reference in New Issue
Block a user