From 7af847dbb2629f2128006bbbc2ba12a2b018ed10 Mon Sep 17 00:00:00 2001 From: vonavi Date: Fri, 4 Oct 2013 21:12:53 +0300 Subject: [PATCH 1/3] Fix player's names for tournament 'autumn2013'. --- .../1.pgn | 0 autumn2013/tour_01/tour_info | 2 +- .../1.pgn | 0 autumn2013/tour_02/tour_info | 2 +- autumn2013/tour_03/tour_info | 2 +- 5 files changed, 3 insertions(+), 3 deletions(-) rename autumn2013/tour_01/{2013.09.15 — trex6 vs. uruborus => 2013.09.15 — trex6 vs. uroboros}/1.pgn (100%) rename autumn2013/tour_02/{2013.09.08 — uruboros vs. aptyp => 2013.09.08 — uroboros vs. aptyp}/1.pgn (100%) diff --git a/autumn2013/tour_01/2013.09.15 — trex6 vs. uruborus/1.pgn b/autumn2013/tour_01/2013.09.15 — trex6 vs. uroboros/1.pgn similarity index 100% rename from autumn2013/tour_01/2013.09.15 — trex6 vs. uruborus/1.pgn rename to autumn2013/tour_01/2013.09.15 — trex6 vs. uroboros/1.pgn diff --git a/autumn2013/tour_01/tour_info b/autumn2013/tour_01/tour_info index 38d53df..c47248c 100644 --- a/autumn2013/tour_01/tour_info +++ b/autumn2013/tour_01/tour_info @@ -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 diff --git a/autumn2013/tour_02/2013.09.08 — uruboros vs. aptyp/1.pgn b/autumn2013/tour_02/2013.09.08 — uroboros vs. aptyp/1.pgn similarity index 100% rename from autumn2013/tour_02/2013.09.08 — uruboros vs. aptyp/1.pgn rename to autumn2013/tour_02/2013.09.08 — uroboros vs. aptyp/1.pgn diff --git a/autumn2013/tour_02/tour_info b/autumn2013/tour_02/tour_info index 440d0b0..5be1d77 100644 --- a/autumn2013/tour_02/tour_info +++ b/autumn2013/tour_02/tour_info @@ -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 diff --git a/autumn2013/tour_03/tour_info b/autumn2013/tour_03/tour_info index e82ed9e..e7b75f7 100644 --- a/autumn2013/tour_03/tour_info +++ b/autumn2013/tour_03/tour_info @@ -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 From 887bd4e2b2972a528f36278c29371d95a8437c49 Mon Sep 17 00:00:00 2001 From: vonavi Date: Fri, 4 Oct 2013 22:08:24 +0300 Subject: [PATCH 2/3] Fix player's names in 'result.yml'. --- autumn2013/results.yml | 40 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 37 insertions(+), 3 deletions(-) diff --git a/autumn2013/results.yml b/autumn2013/results.yml index 00a8933..33ab40f 100644 --- a/autumn2013/results.yml +++ b/autumn2013/results.yml @@ -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' + From e622b8a4b3a24f4af87a30c3d11f71f8bc967a0f Mon Sep 17 00:00:00 2001 From: vonavi Date: Fri, 4 Oct 2013 23:16:33 +0300 Subject: [PATCH 3/3] Add Ruby routines for generating the tournament table. --- bin/lorchess | 5 ++ lib/lorchess.rb | 4 ++ lib/lorchess/tournament_table.rb | 118 +++++++++++++++++++++++++++++++ 3 files changed, 127 insertions(+) create mode 100755 bin/lorchess create mode 100644 lib/lorchess.rb create mode 100644 lib/lorchess/tournament_table.rb diff --git a/bin/lorchess b/bin/lorchess new file mode 100755 index 0000000..ff2f4ae --- /dev/null +++ b/bin/lorchess @@ -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 diff --git a/lib/lorchess.rb b/lib/lorchess.rb new file mode 100644 index 0000000..100c233 --- /dev/null +++ b/lib/lorchess.rb @@ -0,0 +1,4 @@ +$:.unshift File.dirname(__FILE__) # for use/testing when no gem is installed + +# Internal requires +require 'lorchess/tournament_table.rb' diff --git a/lib/lorchess/tournament_table.rb b/lib/lorchess/tournament_table.rb new file mode 100644 index 0000000..7778e48 --- /dev/null +++ b/lib/lorchess/tournament_table.rb @@ -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 << "\n" + @buffer << " \n" + @buffer << " \n" + @buffer << " \n" + @buffer << " \n" + @buffer << " \n" + + for cell in 0..(@dim-1) + @buffer << " \n" + end + + @buffer << " \n" + @buffer << " \n" + @buffer << " \n" + @buffer << " \n" + @buffer << " \n" + + for row in 0..(@dim-1) + + @buffer << " \n" + @buffer << " \n" + @buffer << " \n" + @buffer << " \n" + + for cell in 0..(@dim-1) + unless cell == row + @buffer << " \n" + else + @buffer << " \n" + end + end + + @buffer << " \n" + @buffer << " \n" + @buffer << " \n" + end + + @buffer << " \n" + @buffer << "
LOR Chess : Осень-2013\n" + @buffer << "
Участникelo" << (cell+1).to_s << "ОчкиМесто
" << (row+1).to_s << "" << @players[row] << "" << @elo_list[row].to_s << "" << @results[row][cell] << "" << @player_score[row].to_s << "
\n" + @buffer + end + + end +end