1
Fork 0
Arthur Yunusov 2013-10-05 09:34:00 +06:00
commit fc4a526ebb
9 changed files with 167 additions and 6 deletions

View File

@ -7,7 +7,7 @@
- date: 15.09.2013
white: trex6
black: uroborus
black: uroboros
result: '0:1'
- date: 09.09.2013
@ -83,7 +83,7 @@
result: '0:1'
- date: 08.09.2013
white: uroborus
white: uroboros
black: aptyp
result: '1:0'
@ -130,7 +130,7 @@
result: '1:0'
- date: 26.09.2013
white: darkshvein
white: darkenshvein
black: Genuine
result: '0:1'
@ -213,6 +213,11 @@
black: DoctorSinus
result: '0:1'
- date: 01.10.2013
white: Michkova
black: farzeet
result: '1:0'
- date: 28.09.2013
white: HunOL
black: uroboros
@ -297,6 +302,11 @@
- number: 7
games:
- date: 02.10.2013
white: J
black: trex6
result: '1:0'
- date: 28.09.2013
white: Michkova
black: Kakadu
@ -317,6 +327,11 @@
black: raven_cler
result: '1:0'
- date: 04.10.2013
white: shell-script
black: Genuine
result: '0:1'
- date: 29.09.2013
white: redgremlin
black: Magian
@ -344,6 +359,11 @@
black: iVS
result: '0:1'
- date: 04.10.2013
white: Kakadu
black: HunOL
result: '1:0'
- date: 28.09.2013
white: aptyp
black: J
@ -354,3 +374,17 @@
black: Magian
result: '1:0'
- number: 9
games:
- date: 02.09.2013
white: darkenshvein
black: Kakadu
result: '0:1'
- number: 10
games:
- date: 04.10.2013
white: uroboros
black: shell-script
result: '1:0'

View File

@ -4,7 +4,7 @@
Время проведения: 07.09.2013 - 15.09.2013
09.09.2013 — Kakadu 1:0 farzeet
15.09.2013 — trex6 0:1 uroborus
15.09.2013 — trex6 0:1 uroboros
09.09.2013 — aptyp 1:0 raven_cler
08.09.2013 — J 1:0 LongLiveUbuntu
15.09.2013 — Michkova 1:0 Genuine

View File

@ -9,7 +9,7 @@
12.09.2013 — Genuine 1:0 HunOL
15.09.2013 — LongLiveUbuntu 0:1 Michkova
10.09.2013 — raven_cler 0:1 J
08.09.2013 — uroborus 1:0 aptyp
08.09.2013 — uroboros 1:0 aptyp
13.09.2013 — farzeet 0:1 trex6
07.09.2013 — DoctorSinus 0:1 Kakadu
15.09.2013 — MyTrooName 1:0 Kasparov

View File

@ -8,7 +8,7 @@
15.09.2013 — J 0:1 uroboros
20.09.2013 — Michkova 0:1 raven_cler
20.09.2013 — HunOL 1:0 LongLiveUbuntu
26.09.2013 — darkshvein 0:1 Genuine
26.09.2013 — darkenshvein 0:1 Genuine
15.09.2013 — iVS 0:1 Magian
15.09.2013 — Nedis 0:1 redgremlin
22.09.2013 — Kasparov 0:1 shell-script

5
bin/lorchess Executable file
View File

@ -0,0 +1,5 @@
#!/usr/bin/env ruby
require File.expand_path('../lib/lorchess.rb', File.dirname(__FILE__))
table = LORChess::TournamentTable.new
puts table.to_html

4
lib/lorchess.rb Normal file
View File

@ -0,0 +1,4 @@
$:.unshift File.dirname(__FILE__) # for use/testing when no gem is installed
# Internal requires
require 'lorchess/tournament_table.rb'

View File

@ -0,0 +1,118 @@
# -*- coding: utf-8 -*-
module LORChess
class TournamentTable
require 'yaml'
dir = File.dirname(__FILE__)
players_yaml = File.expand_path('../../autumn2013/players.yml', dir)
@@db_players = YAML.load_file players_yaml
results_yaml = File.expand_path('../../autumn2013/results.yml', dir)
@@db_results = YAML.load_file results_yaml
# Sort players in numerical order
@@db_players.sort! { |x,y| x['number'] <=> y['number'] }
def initialize
@players = []
@elo_list = []
@dim = @@db_players.length
@results = Array.new(@dim) { Array.new(@dim, '') }
@player_score = []
@buffer = ''
@@db_players.each do |player|
@players << player['lor']
@elo_list << player['elo']
end
# Correlate the player with his position
@player_pos = {}
@players.each_with_index { |player, pos| @player_pos[player] = pos }
fill
calculate
# Clean the vacancy place
index = @player_pos['Kasparov']
@players[index] = 'отсутствует'
@elo_list[index] = 1200
for cell in 0..(@dim-1)
@results[index][cell] = ''
end
end
def fill
@@db_results.each do |tour|
tour['games'].each do |game|
import game
end
end
end
def import game
pos_white = @player_pos[game['white']]
pos_black = @player_pos[game['black']]
score = game['result'].split ':'
@results[pos_white][pos_black] = score[0]
@results[pos_black][pos_white] = score[1]
end
def calculate
@results.each do |row|
sum = 0.0
row.each { |score| sum += score.to_f }
@player_score << sum
end
end
def to_html
@buffer << "<table class=\"table table-bordered table-condensed\">\n"
@buffer << " <caption>LOR Chess : Осень-2013<caption>\n"
@buffer << " <thead>\n"
@buffer << " <tr>\n"
@buffer << " <th></th>\n"
@buffer << " <th>Участник</th>\n"
@buffer << " <th>elo</th>\n"
for cell in 0..(@dim-1)
@buffer << " <th>" << (cell+1).to_s << "</th>\n"
end
@buffer << " <th>Очки</th>\n"
@buffer << " <th>Место</th>\n"
@buffer << " </tr>\n"
@buffer << " </thead>\n"
@buffer << " <tbody>\n"
for row in 0..(@dim-1)
@buffer << " <tr>\n"
@buffer << " <td>" << (row+1).to_s << "</td>\n"
@buffer << " <td>" << @players[row] << "</td>\n"
@buffer << " <td>" << @elo_list[row].to_s << "</td>\n"
for cell in 0..(@dim-1)
unless cell == row
@buffer << " <td class=\"table-cell\">" << @results[row][cell] << "</td>\n"
else
@buffer << " <td class=\"table-cell-diag\"></td>\n"
end
end
@buffer << " <td>" << @player_score[row].to_s << "</td>\n"
@buffer << " <td></td>\n"
@buffer << " </tr>\n"
end
@buffer << " </tbody>\n"
@buffer << "</table>\n"
@buffer
end
end
end