Package: chess-graph
The Chess Opening AnalyzerAboutA program that will produce a graphical sunburst chart of chess openings from the PGN that is provided to it.You can easily run this with the pip module in one function by simply specifying the path to the PGN database that you would like to have analyzed.This package can customize the multi=level pie chart in many ways. It can shade segments based on win percentage, you can click to zoom in, openings are highlighted, and so much more. It's the perfect learning tool for anyone interested in chess or wishing to improve their opening skills!FeaturesMake graph of games toany depthUpload acustom databaseand see howyourchart looks likeHoverto see metadata such asgame count and percentage of parentEasilyfind openingswith simple hover tooltip identificationClick to zoomin on a slice and expand it, making it easy to magnify any slice of the pie chartDownloadable files: you can download the chart as an interactive HTML, or as a static PNG/JPEG/SVG/WEBP image with just a few clicksWin Ratio Shadingmeans that you will never be in doubt as to what next move is statistically bestHide small slicesand prevent them from showing up in the graph!Custom branchingto analyze database fromany positionFind your player and colorby selecting games from someone based on their color (white or black) and namePrerequisitesRuns in Python 3, must have Python 3 installedRequires Plotly and pgnparserYou can install Plotly and pgnparser using PyPi, as long as you are an admin user on your device. To do so, simply typepip install plotlyandpip install pgnparserinto your terminal.Using via pip installpip install chess-graphOpen terminal/interpreter.import chess_graphchess_graph.graph(database, depth=5, shade = True, fragmentation_percentage=0.0032, should_defragment=False, custom_branching=False, should_download = False, download_format = 'png', download_name = 'fig1')Note that the path to the pgn file (the database) must be relative to the current directory python is running in. For example, if you have the pgn downloaded on your Desktop, you could easily solve this issue by navigating to Desktop within terminal (cd Desktop). From there, you can replace the database argument with the simple filename (assuming it is in Desktop). If this is confusing, just type in the full path.A Deeper Look at the FunctionThegraph()function takes 11 arguments, and 10 of them are default-set. We'll explore each of them so that you know how to properly use this package to its full potential.Thedatabaseargument: This argument mustalwaysbe inputted. It is the path to the file. Let's look at two examples.chess_graph.graph('Users/student/Desktop/pgns/mir_khan.pgn'). Here, we are running the chess_graph on a pgn from Mir Sultan Khan. We are showing the program what file to read this by providing the full path to the file.In the example above, you can see that the file is in thepgnsfolder in Desktop. So, we can open our terminal, and then typecd Desktop,cd pgnsto go the folder that has this file. Because we are now in that directory, we can type:chess_graph.graph('mir_khan.pgn')as it is in the current directory. If you are unsure, stick with the full file path.Thedepthargument. This is set to 5 by default, and shows the number of rings that the pie chart will have. You can change this by typingchess_graph.graph(*path to file*, depth = 7). Make sure that you typedepth =, and not just the integer depth.Theshadeargument. This is set to True by default. It is whether you should shade the segments or not based on W/B win percentage. If you set it to False, (chess_graph.graph(*path to file*, shade = False)), then a vividly colored chart will be produced instead.Thefragmentation_percentageargument. Set to 0.0032 by default. You can 'defragment' the graph by hiding very small slices. This argument shows how small the slices have to be (relative to the total number of games, e.g. 2 games/100 games total = 2%) to be deleted. In this example, the percentage is 100*0.0032 = 0.32%. Example:chess_graph.graph(*path to file*, fragmentation_percentage = 0.05)- 5% or smaller will be deleted.Theshould_defragmentargument. Set to False by default. Setting it to True will allow the graph to hide the slices, keeping it False will show all slices. Even if you change fragmentation_percentage, if this isn't set to True, nothing will change. Example:chess_graph.graph(*path to file*, fragmentation_percentage = 0.05, should_defragment = True)Thecustom branchingargument. Set to False by default. You can analyze a database from any position if set to True. Example:chess_graph.graph(*path to file*, custom_branching = True). You will be asked for an input for the custom branching. For the sake of this example, let's say you want to analyze only positions from e4 e5. So, type e4 e5. The graph will then show positions only from e4 e5.Theshould_downloadargument. Set to False be default. You can download the figures in five different formats (see more below). Make sure you have the packages installed before downloading. You can set this to True if you would like to download the figure.Thedownload_formatargument. Set to the string 'png' by default. Change it to the string of the file type you want the download to be in.chess_graph.graph(..., download_format = 'jpeg')Thedownload_nameargument. The name of the figure that will be downloaded. Set to be fig1 by default, meaning that files downloaded will be downloaded as fig1.png. See above.Thecolorargument. This is set to both by default. Valid inputs are 'both', 'white', 'w', 'black' and 'b'. If you change the color argument from both, then the program will only read games that are from the color you chose. Note that you need to also change the player name with thenameargument if you do so. See below.Thenameargument. This argument will allow the program to pick games from the file it is given, but only games from a certain player. There is an example below:
Set the color to 'black' or 'white' to pick only games where the player (the name) played as black or white. (i.e.chess_graph.graph('pgns/Carlsen.pgn', color = 'white', name = 'Magnus Carlsen')will pick all the games where Carlsen played as white.)Remember to include all variations and parts of a player's name! For example, the player Viktor Korchnoi has his last name spelled as Kortschnoj as well. In that case, for the 'name' field, type: Viktor Korchnoi KortschnojDownloadingDownloadingisan option, although you need to make sure you have the proper libraries installed.Currently, you can uncomment the download interactive HTML file without anything else to download. If you do so, an HTML file of the graph will be saved to your device, which you can open with your browser.You can also download the file as: SVG, PDF, JPEG, PNG, and WebP.However, if you want to download intheseformats you need the following installed.npm install -g electron@1.8.4 orcapip install psutil requestspip install psutilExamplesAll examples are those of Magnus Carlsen's OTB tournament gamesSimple Pie ChartHover Functionality | Show Percentage of Parent + Game CountClick to ZoomExtra InfoI based this chart loosely off of a post that I read on ebemunk's blog - you can find the link here:https://blog.ebemunk.com/a-visual-look-at-2-million-chess-games/. However, that project was written in Java and it didn't have everything that I wanted, such as showing all the games, zooming in, etc.