From ce5ccbf65483984e25fb08464f5f58e06a5f7bff Mon Sep 17 00:00:00 2001 From: victor-zheng-codes Date: Mon, 1 Jan 2024 10:50:56 -0800 Subject: [PATCH 1/8] create wrapper class for generating fide data --- src/bin/generate_FIDE.py | 52 +++++++++++++++++++++++++++++++ src/ratings_calculator/Profile.py | 6 ---- 2 files changed, 52 insertions(+), 6 deletions(-) create mode 100644 src/bin/generate_FIDE.py diff --git a/src/bin/generate_FIDE.py b/src/bin/generate_FIDE.py new file mode 100644 index 0000000..b7bf6ff --- /dev/null +++ b/src/bin/generate_FIDE.py @@ -0,0 +1,52 @@ +"""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 + +country = "CAN" + + +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: + """Generates FIDE player data""" + def generate_player_data(self) -> None: + """Generates a list of norm eligble tournaments in the given country + + """ + pass diff --git a/src/ratings_calculator/Profile.py b/src/ratings_calculator/Profile.py index bf39695..7fcf250 100644 --- a/src/ratings_calculator/Profile.py +++ b/src/ratings_calculator/Profile.py @@ -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 From 5109ba05519ff34b65d0348f889dee242604923e Mon Sep 17 00:00:00 2001 From: victor-zheng-codes Date: Mon, 1 Jan 2024 23:59:50 -0800 Subject: [PATCH 2/8] working generate fide data --- .idea/misc.xml | 2 +- .idea/ratings-calculator.iml | 3 ++- src/bin/generate_FIDE.py | 17 ++++++++++++++++- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/.idea/misc.xml b/.idea/misc.xml index d56657a..9cf1778 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,4 +1,4 @@ - + \ No newline at end of file diff --git a/.idea/ratings-calculator.iml b/.idea/ratings-calculator.iml index c3f591d..6d3cbf6 100644 --- a/.idea/ratings-calculator.iml +++ b/.idea/ratings-calculator.iml @@ -4,8 +4,9 @@ + - + diff --git a/src/bin/generate_FIDE.py b/src/bin/generate_FIDE.py index b7bf6ff..31e5249 100644 --- a/src/bin/generate_FIDE.py +++ b/src/bin/generate_FIDE.py @@ -12,6 +12,8 @@ """ from pathlib import Path +from chess import Board +from fideparser import tournament, ratingperiod country = "CAN" @@ -49,4 +51,17 @@ def generate_player_data(self) -> None: """Generates a list of norm eligble tournaments in the given country """ - pass + rating_period = ratingperiod.RatingPeriod( + "CAN", + "2023-12-01", + True, + True + ) + + output_file = "2023-12-01-csv.csv" + + rating_period.export(output_file, "csv") + + +data = FidePlayerData() +data.generate_player_data() From ba73201c88ac40f5e8170d029a071edf17f3d07e Mon Sep 17 00:00:00 2001 From: victor-zheng-codes Date: Tue, 2 Jan 2024 00:14:59 -0800 Subject: [PATCH 3/8] generate fide got working version of library for fide parser --- {src/bin => bin}/generate_FIDE.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) rename {src/bin => bin}/generate_FIDE.py (85%) diff --git a/src/bin/generate_FIDE.py b/bin/generate_FIDE.py similarity index 85% rename from src/bin/generate_FIDE.py rename to bin/generate_FIDE.py index 31e5249..18cacc0 100644 --- a/src/bin/generate_FIDE.py +++ b/bin/generate_FIDE.py @@ -51,17 +51,21 @@ def generate_player_data(self) -> None: """Generates a list of norm eligble tournaments in the given country """ + + print("Running") + rating_period = ratingperiod.RatingPeriod( - "CAN", - "2023-12-01", - True, - True + "ESP", + "2013-01-01" ) - output_file = "2023-12-01-csv.csv" + # output_file = "2023-12-01-csv.csv" + rating_period.save() + output_file = Path(__file__).parent.parent / "src" / "ratings_calculator" / "assets" / "cache" / "output_file.csv" rating_period.export(output_file, "csv") data = FidePlayerData() + data.generate_player_data() From 611605c9f9dcd5f79bf30dde11713364df494a94 Mon Sep 17 00:00:00 2001 From: victor-zheng-codes Date: Tue, 2 Jan 2024 21:24:29 -0800 Subject: [PATCH 4/8] Created files for generating FIDE with report true/false --- bin/generate_FIDE.py | 33 ++++++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/bin/generate_FIDE.py b/bin/generate_FIDE.py index 18cacc0..482a6a5 100644 --- a/bin/generate_FIDE.py +++ b/bin/generate_FIDE.py @@ -15,8 +15,6 @@ from chess import Board from fideparser import tournament, ratingperiod -country = "CAN" - class FideAssets: """Generates a list of norm eligble tournaments in the given country""" @@ -51,20 +49,41 @@ def generate_player_data(self) -> None: """Generates a list of norm eligble tournaments in the given country """ + print("Running generate player data") + + country = "CAN" + period = "2023-12-01" - print("Running") + arb_data = False + report_data = True rating_period = ratingperiod.RatingPeriod( - "ESP", - "2013-01-01" + country, + period, + arbiters_data=arb_data, + report_data=report_data ) - # output_file = "2023-12-01-csv.csv" + output_file = f"{period}-{country}" + + # append to the output file name + if report_data: + output_file += "-report-true" + else: + output_file += "-report-false" + + if 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" / "output_file.csv" + output_file = Path(__file__).parent.parent / "src" / "ratings_calculator" / "assets" / "cache" / f"{output_file}.csv" rating_period.export(output_file, "csv") + print("Finished generating player data") + data = FidePlayerData() From 923ab60f5b19cd1f0653e02ab7caa569e20c9fa5 Mon Sep 17 00:00:00 2001 From: victor-zheng-codes Date: Wed, 3 Jan 2024 18:15:26 -0800 Subject: [PATCH 5/8] generates all FIDE tournaments run in 2023 for FIDE --- bin/generate_FIDE.py | 48 ++++++++++++++++++++++++++++---------------- 1 file changed, 31 insertions(+), 17 deletions(-) diff --git a/bin/generate_FIDE.py b/bin/generate_FIDE.py index 482a6a5..b3161ae 100644 --- a/bin/generate_FIDE.py +++ b/bin/generate_FIDE.py @@ -44,35 +44,37 @@ def generate_norm_tournaments(self) -> None: class FidePlayerData: - """Generates FIDE player data""" - def generate_player_data(self) -> None: - """Generates a list of norm eligble tournaments in the given country + """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") - country = "CAN" - period = "2023-12-01" - - arb_data = False - report_data = True - rating_period = ratingperiod.RatingPeriod( - country, + self.country, period, - arbiters_data=arb_data, - report_data=report_data + arbiters_data=self.arb_data, + report_data=self.report_data ) - output_file = f"{period}-{country}" + output_file = f"{period}-{self.country}" # append to the output file name - if report_data: + if self.report_data: output_file += "-report-true" else: output_file += "-report-false" - if arb_data: + if self.arb_data: output_file += "-arb-true" else: output_file += "-arb-false" @@ -84,7 +86,19 @@ def generate_player_data(self) -> None: 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() +data = FidePlayerData("CAN", False, True) -data.generate_player_data() +data.generate_full_year("2023") From d80b4da569a076633593d1c80321e085d08216e5 Mon Sep 17 00:00:00 2001 From: victor-zheng-codes Date: Wed, 3 Jan 2024 18:20:12 -0800 Subject: [PATCH 6/8] commit location for FIDE --- bin/generate_FIDE.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/generate_FIDE.py b/bin/generate_FIDE.py index b3161ae..3e451bc 100644 --- a/bin/generate_FIDE.py +++ b/bin/generate_FIDE.py @@ -81,7 +81,7 @@ def generate_player_data(self, period: str) -> None: rating_period.save() - output_file = Path(__file__).parent.parent / "src" / "ratings_calculator" / "assets" / "cache" / f"{output_file}.csv" + 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") From 28a93f87ad6260a18d1da458f20d57bae52be777 Mon Sep 17 00:00:00 2001 From: victor-zheng-codes Date: Wed, 3 Jan 2024 20:55:36 -0800 Subject: [PATCH 7/8] add useful links pg --- docs/useful_links.md | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 docs/useful_links.md diff --git a/docs/useful_links.md b/docs/useful_links.md new file mode 100644 index 0000000..ead8d25 --- /dev/null +++ b/docs/useful_links.md @@ -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/ From cc5987c0554e52cdbc2e2937ae71459966a95345 Mon Sep 17 00:00:00 2001 From: victor-zheng-codes Date: Wed, 3 Jan 2024 21:26:33 -0800 Subject: [PATCH 8/8] create rating test fiail --- src/ratings_calculator/tests/rating_tests.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/ratings_calculator/tests/rating_tests.py b/src/ratings_calculator/tests/rating_tests.py index b6f75a0..7f17152 100644 --- a/src/ratings_calculator/tests/rating_tests.py +++ b/src/ratings_calculator/tests/rating_tests.py @@ -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 @@ -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):