Last active
May 8, 2022 19:34
-
-
Save timothyha/f5677fac62814667099e325951579b10 to your computer and use it in GitHub Desktop.
NZCF junior rating list
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from datetime import date | |
current_year = date.today().year | |
players = dict() | |
def readlist(timecontrol): | |
curplayer = "" | |
for line in lines: | |
field = 0 | |
for value in line.strip().split(';'): | |
field = field + 1 | |
# name | |
if field == 1: | |
if value not in players: | |
players[value] = { "year":0, "standard":0, "rapid":0 } | |
curplayer = value | |
# year of birth | |
if field == 3: | |
players[curplayer]["year"] = int(value.strip()) | |
# rating | |
if field == 10: | |
players[curplayer][timecontrol] = int(value.strip()) | |
with open('2022-2-Junior-Standard-Vega-20220501.csv') as f: | |
lines = f.readlines() | |
readlist("standard") | |
with open('2022-2-Junior-Rapid-Vega-20220501.csv') as f: | |
lines = f.readlines() | |
readlist("rapid") | |
print("<table cellpadding=10 cellspacing=5><tr><td align=left valign=top>") | |
# top 20 standard | |
sorted_players = dict(sorted(players.items(), key=lambda x:x[1]["standard"], reverse=True)) | |
print("<b>Top 20 Standard</b>") | |
print("<ol>") | |
limit = 0 | |
for player in sorted_players: | |
limit = limit + 1 | |
if limit <= 20: | |
print("<li>", player, "-", players[player]["standard"]) | |
print("</ol>") | |
print() | |
print("</td><td align=left valign=top>") | |
# top 20 rapid | |
sorted_players = dict(sorted(players.items(), key=lambda x:x[1]["rapid"], reverse=True)) | |
print("<b>Top 20 Rapid</b>") | |
print("<ol>") | |
limit = 0 | |
for player in sorted_players: | |
limit = limit + 1 | |
if limit <= 20: | |
print("<li>", player, "-", players[player]["rapid"]) | |
print("</ol>") | |
print() | |
print("</td></tr></table>") | |
print() | |
print("##Age groups") | |
print() | |
# redo sorting before printing age groups | |
sorted_players = dict(sorted(players.items(), key=lambda x:x[1]["standard"], reverse=True)) | |
# top 20 U-14 | |
print("<b>Top 20 Standard, under 14</b>") | |
print("<ol>") | |
limit = 0 | |
for player in sorted_players: | |
if players[player]["year"] >= current_year-14: | |
limit = limit + 1 | |
if limit <= 20: | |
print("<li>", player, "-", players[player]["standard"], "<font color='#c0c0c0'><i>b.", players[player]["year"], "</i></font>") | |
print("</ol>") | |
print() | |
# top 20 U-12 | |
print("<b>Top 20 Standard, under 12</b>") | |
print("<ol>") | |
limit = 0 | |
for player in sorted_players: | |
if players[player]["year"] >= current_year-12: | |
limit = limit + 1 | |
if limit <= 20: | |
print("<li>", player, "-", players[player]["standard"], "<font color='#c0c0c0'><i>b.", players[player]["year"], "</i></font>") | |
print("</ol>") | |
print() | |
# top 10 U-10 | |
print("<b>Top 10 Standard, under 10</b>") | |
print("<ol>") | |
limit = 0 | |
for player in sorted_players: | |
if players[player]["year"] >= current_year-10: | |
limit = limit + 1 | |
if limit <= 10: | |
print("<li>", player, "-", players[player]["standard"], "<font color='#c0c0c0'><i>b.", players[player]["year"], "</i></font>") | |
print("</ol>") | |
print() | |
# top 10 U-8 | |
print("<b>Top 10 Standard, under 8</b>") | |
print("<ol>") | |
limit = 0 | |
for player in sorted_players: | |
if players[player]["year"] >= current_year-8: | |
limit = limit + 1 | |
if limit <= 10: | |
print("<li>", player, "-", players[player]["standard"], "<font color='#c0c0c0'><i>b.", players[player]["year"], "</i></font>") | |
print("</ol>") | |
print() | |
# top 10 U-6 | |
print("<b>Top 10 Standard, under 6</b>") | |
print("<ol>") | |
limit = 0 | |
for player in sorted_players: | |
if players[player]["year"] >= current_year-6: | |
limit = limit + 1 | |
if limit <= 10: | |
print("<li>", player, "-", players[player]["standard"], "<font color='#c0c0c0'><i>b.", players[player]["year"], "</i></font>") | |
print("</ol>") | |
print() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment