Spaces:
Runtime error
Runtime error
File size: 2,986 Bytes
cb8fc87 97794a7 9115421 0108cbe 9115421 fe2ae41 cb8fc87 9115421 cb8fc87 9115421 cb8fc87 9115421 6ff217d fe2ae41 e2db22b fe2ae41 e2db22b fe2ae41 e2db22b fe2ae41 e2db22b fe2ae41 6ff217d 9115421 97794a7 0108cbe fe2ae41 0108cbe fe2ae41 0108cbe 9115421 e2db22b fe2ae41 9115421 fe2ae41 9115421 97794a7 9115421 97794a7 9115421 fe2ae41 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
import chess
import matplotlib.pyplot as plt
import pandas as pd
import streamlit as st
from typing import Dict
from logger import Logger
import time
import numpy as np
class GameDatabase:
def __init__(self):
self.db = []
pass
def add_game(self, game: Dict[str, str]):
self.db.append(game)
def display_game(self, game_num: int): #Displays analytics for a specific game
game = self.db[game_num]
fig, axs = plt.subplots(2,2)
fig.tight_layout()
width = 0.4
def list_sets_graph(data_list: [], axs_pos: [], title, width = 0.4):
white_data = data_list[::2]
black_data = data_list[1::2]
x_w = np.arange(len(white_data))
x_b = np.arange(len(black_data))
axs[axs_pos[0], axs_pos[1]].set_xticks(x_w, [x for x in range(len(white_data))])
axs[axs_pos[0], axs_pos[1]].bar(x_w - (width/2), white_data, width, color = "navajowhite")
axs[axs_pos[0], axs_pos[1]].bar(x_b + (width/2), black_data, width, color = "saddlebrown")
axs[axs_pos[0], axs_pos[1]].legend(["White", "Black"])
axs[axs_pos[0], axs_pos[1]].set_title(title)
#plot time per move, with data for each model
time_title = "Seconds Per Move"
list_sets_graph(game[time_title], axs_pos=[0,0], title=time_title)
#plot cheating per model
cheat_title = "Cheat Attempts Per Move"
list_sets_graph(game["Cheat Attempts"], axs_pos=[1,0], title = cheat_title)
#stockfish analysis of each player over time
#plt.show()
st.pyplot(fig)
def display_tournament(self): #Displays analytics for the entire tournament
df = pd.DataFrame(self.db)
#heatmap of tournament winrates
#bar chart of tournament winrates
win_results = df["Winner"].value_counts()
print(win_results.rank())
names = ["steve", "bob", "emily"]
nums = [1,2,3]
fig, axs = plt.subplots(2,1)
axs[0].plot(win_results)
axs[1].bar(names, nums)
st.pyplot(fig)
if __name__ == "__main__":
test_logger = Logger("ChessGPT", "ChatGPT")
test_logger.add_cheat()
time.sleep(1)
test_logger.add_legal_move("e4")
time.sleep(1)
test_logger.add_legal_move("e4 e6")
time.sleep(2)
test_logger.add_legal_move("e4 e6 Nf3")
test_logger.add_checkmate("ChessGPT")
#test_logger.add_legal_move("e4 e5")
formatted = test_logger.return_formatted_game()
test_logger_2 = Logger("ChessGPT", "BERT")
test_logger_2.add_checkmate("BERT")
formatted_2 = test_logger_2.return_formatted_game()
test_logger_3 = Logger("ChessGPT", "BERT")
test_logger_3.add_checkmate("ChessGPT")
formatted_3 = test_logger_3.return_formatted_game()
db = GameDatabase()
db.add_game(formatted)
db.add_game(formatted_2)
db.add_game(formatted_3)
db.display_game(0)
|