Python code for identifying Splinterlands' best brawlers.

Image created with Bing image generator.

This is a companion post to the Best brawlers in Tier 3,4,5 post. Here, I go over the python code used to download and process the brawl data.

Identifying the best brawlers is a slightly complicated data sorting task. We need to ask for brawl data for each guild and each brawl. Downloading this data takes quite a while. Fortunately, I have stored the brawl data once before up to brawl #232, so there is not that much additional data to download for me.

Once we have the brawl data, we need to compute statistics for each fray.

separator.png

Python code

The script is available in entirety in spltools: best_brawler_in_fray.py

image.png

First, we import a few standard python libraries. I also use Numpy, an absolutely amazing library, in this script to do some math manipulations. From spltools, I use the Guild and Brawl classes, as well as the two functions get_guild_list and get_player_guild.

Next we define functions to download and load brawl data. To identify the best all-time brawlers, we need to download every brawl for all top 300 guilds. This is a lot of data, so we need to save it to file, otherwise we risk losing it all if we get some network/computer error. I added a manual delay in the download function to be a bit nice with the Splinterlands servers.

image.png

image.png

image.png

The main processing of the data is done within the BrawlHistory class. I set it up so that the BrawlHistory object is specific for a tier, and we instantiate one for tier 3, one for tier 4 and one for tier 5. It has a function to add brawl data: BrawlHistory.add_data(...). It takes a Brawl object as input and then inserts player results into the correct data structures.

image.png

In the BrawlHistory initializer I have hard-coded some properties for the three Brawl tiers I'm interested in analyzing. First of all, we need to know the number of frays, and also which frays have the same rules - for those we want to combine the results.

So I set up the number of frays and the duplicate_fray info from the tier parameter, and then define a list of unique frays, along with the names of the unique frays. For example, frays 3 and 4 are duplicates in tier 3, so I label the combined one '3+4'. Then I setup the fray_data dictionary where I will store all the data

image.png

The add_data function is quite simple, since the data is already nicely structured in the Brawl object. We loop over the players, look at which fray they played and insert their data. If we have seen the player before in this fray, we add the brawl results to the already existing data structure, otherwise we add a new one.

image.png

Finally, we can identify the best players in each fray. Again, since we have well structured data, the code can be quite compact and nice. I call an internal function that converts the dictionaries to lists of players, wins, losses and winrates, and then find which index in the list that corresponds to the highest number of wins. That is done with the np.argmax function call. Then, the last step is to print a markdown table line with the info for that player.

image.png

There is also a function to compute the best players in the tier. It does essentially the same as the get_best_player_in_fray, but has to combine the fray data into one big data set first.

Finally, the rest of the script just calls the functions we have defined. We loop over all guilds, get their data from each brawl, and insert it into the BrawlHistory objects.

image.png

Once all data is setup up, we call the functions to get the best players:

image.png

separator.png

Final words

Thank you for your attention. If you are interested in more posts about the spltools python package, you can find the previous ones here:

spltools update posts:

4. spltools update: Classes for Brawl data
3. spltools update: Reward chest classes
2. spltools update: Checking which set a card belongs to
1. Initial spltools commit


If you have not yet joined Splinterlands please click the referral link below to get started.



Join Splinterlands


Best wishes
@Kalkulus

separator.png

H2
H3
H4
3 columns
2 columns
1 column
Join the conversation now
Logo
Center