Skip to content

Commit

Permalink
Fixed ELO bugs when displaying statistics
Browse files Browse the repository at this point in the history
  • Loading branch information
jfrozas committed Jan 23, 2024
1 parent 2213a4b commit a19e022
Showing 1 changed file with 32 additions and 4 deletions.
36 changes: 32 additions & 4 deletions src/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def __init__(self, root):

self.treeview_players.heading("#0", text="", anchor=tk.W)
self.treeview_players.heading("Player", text="Player", anchor=tk.W, command=lambda: self.sorter('1', self.treeview_players))
self.treeview_players.heading("Total Games", text="Total Games", anchor=tk.W)
self.treeview_players.heading("Total Games", text="Total Games", anchor=tk.W, command=lambda: self.sorter('2', self.treeview_players))

self.treeview_players.pack(side=tk.TOP, fill=tk.BOTH, expand=True)

Expand Down Expand Up @@ -240,12 +240,34 @@ def generate_player_stats(self):
# Separate dates and ELOs for plotting
dates = [date for elo, date in elo_dates]
elos = [int(elo) for elo, date in elo_dates]

unique_combinations = set()
unique_dates = []
unique_elos = []

for a, b in zip(dates, elos):
combination = (a, b)
if combination not in unique_combinations:
unique_combinations.add(combination)
unique_dates.append(a)
unique_elos.append(b)

for a, b in zip(unique_dates, unique_elos):
print(a, b)

conn.commit()
conn.close()

fig, ax = plt.subplots()
ax.plot(dates, elos)

if len(unique_elos) == 1:
# If only one value, create a scatter plot
ax.scatter(unique_dates, unique_elos, label="Elo", color='blue')
else:
# If multiple values, create a line plot
ax.plot(unique_dates, unique_elos, label="Elo", color='blue')

ax.plot(unique_dates, unique_elos, color='blue')
ax.set_title("ELO")
ax.set_xlabel("dates")
ax.set_ylabel("elos")
Expand Down Expand Up @@ -285,8 +307,8 @@ def sorter(self, column, tree):

def treeview_sort_column(tv, col, reverse, key=lambda t: t):
column_index = col

if col == 1:
#
if col == 1 and tv == self.treeview_partidas:
val_list = [(datetime.strptime(str(tv.item(k)["values"][column_index]), '%Y.%m.%d'), k) for k in tv.get_children('')]
else:
val_list = [(key(tv.item(k)["values"][column_index]), k) for k in tv.get_children('')]
Expand Down Expand Up @@ -402,6 +424,12 @@ def add_game(self):
evento = partida.headers['Event']
movements = list(partida.mainline_moves())

try:
datetime.strptime(fecha, '%Y.%m.%d')
except ValueError:
# If the date doesn't follow the format, skip to the next iteration
continue

movements_texto = ' '.join(str(move) for move in movements)

c.execute('''
Expand Down

0 comments on commit a19e022

Please sign in to comment.