Skip to content

Commit

Permalink
Merge pull request #14 from Hart-House-Chess-Club/develop
Browse files Browse the repository at this point in the history
Developed initial architecture for FIDE ratings
  • Loading branch information
victor-zheng-codes committed Jan 4, 2024
2 parents 08c0e2e + cc5987c commit 5cf6a29
Show file tree
Hide file tree
Showing 6 changed files with 132 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion .idea/ratings-calculator.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

104 changes: 104 additions & 0 deletions bin/generate_FIDE.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
"""Generates all FIDE data and stores it into the bin
Includes Analysis Data
- data on rating changes
- data on arbiters
- data on masters
- data on potential norm tournaments
Player Data
- data on ratings of all players, from
- http://ratings.fide.com/download/players_list.zip
"""
from pathlib import Path
from chess import Board
from fideparser import tournament, ratingperiod


class FideAssets:
"""Generates a list of norm eligble tournaments in the given country"""

def generate_fide_arbiters(self, arb_type: int) -> None:
"""Generates the list of FIDE arbiters for the given country
:param arb_type: Represents which type of master title to generate.
"""
pass

def generate_fide_international_masters(self, master_type: int) -> None:
"""Generates JSONS for FIDE international masters for the given country
:param master_type: Represents which type of master title to generate.
"""
pass

def generate_fide_rating_changes(self) -> None:
"""Generates a list of rating changes within the country
"""
pass

def generate_norm_tournaments(self) -> None:
"""Generates a list of norm elidble tournaments in the given country
"""
pass


class FidePlayerData:
"""Using fideparser library to generate files for exporting FIDE data.
"""
def __init__(self, country: str, arb_data: bool, report_data: bool):
""" Initialization variables
"""
self.country = country
self.arb_data = arb_data
self.report_data = report_data

"""Generates FIDE player data"""
def generate_player_data(self, period: str) -> None:
"""Generates a list of all tournaments in the given country
"""
print("Running generate player data")

rating_period = ratingperiod.RatingPeriod(
self.country,
period,
arbiters_data=self.arb_data,
report_data=self.report_data
)

output_file = f"{period}-{self.country}"

# append to the output file name
if self.report_data:
output_file += "-report-true"
else:
output_file += "-report-false"

if self.arb_data:
output_file += "-arb-true"
else:
output_file += "-arb-false"

rating_period.save()

output_file = Path(__file__).parent.parent / "src" / "ratings_calculator" / "assets" / "cache" / "fide" / f"{output_file}.csv"
rating_period.export(output_file, "csv")

print("Finished generating player data")

def generate_full_year(self, year: str):
"""Generates a list of all tournaments this year in the given country
"""
period = ""

# iterate through 12 months
for i in range(1, 13):
# format for the period is yyyy-mm-dd
period = year + "-" + str.zfill(str(i), 2) + "-" + "01"

self.generate_player_data(period)


data = FidePlayerData("CAN", False, True)

data.generate_full_year("2023")
11 changes: 11 additions & 0 deletions docs/useful_links.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
## Useful links

The following page includes useful links for developing this application

Chess.com links:
1. https://www.chess.com/news/view/published-data-api

Chess.ca links:
1. https://forum.chesstalk.com/forum/chesstalk-canada-s-chess-discussion-board-go-to-www-strategygames-ca-for-your-chess-needs/207021-cfc-to-launch-new-website/page5
2. https://www.chesscanada.info/forum/showthread.php?5400-CFC-to-launch-new-website&highlight=website+issues
3. https://www.chess.ca/en/ws/old-chess-ca/
6 changes: 0 additions & 6 deletions src/ratings_calculator/Profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,3 @@ def calc_national_master_norms(self) -> tuple:
title_valid = True

return title_valid, perf_tournaments


class FIDEProfile:
"""Gets user id data for FIDE profile"""

pass
14 changes: 14 additions & 0 deletions src/ratings_calculator/tests/rating_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ def test_get_national_master_norms_invalid(self) -> None:
assert nm_norms[0] is False

def test_get_national_master_norms_valid(self) -> None:
# success fnd nm norms
config = Config(web_profile=True, quick=False)

profile = CFCProfile(154677, config) # for now, input int
Expand All @@ -82,6 +83,19 @@ def test_get_national_master_norms_valid(self) -> None:
print(nm_norms)

assert nm_norms[0] is True
assert len(nm_norms[1]) >= 3

def test_get_national_master_norms_false(self) -> None:
# fail nm norms finding
config = Config(web_profile=True, quick=False)

profile = CFCProfile(152240, config) # for now, input int

nm_norms = profile.calc_national_master_norms()
print(nm_norms)

assert nm_norms[0] is False
assert len(nm_norms[1]) < 3


class TestBasicFunctionalities(unittest.TestCase):
Expand Down

0 comments on commit 5cf6a29

Please sign in to comment.