Updates to spltools. Classes for Brawl data

in Splinterlandslast month

Image created with Bing Image Generator.

I've begun work on an updated version of this post Celebrating 200 Splinterlands Brawls. A compilation of historical guild results and top brawlers. . That one was after we passed 200 Brawls. Now we have passed 250 and its time to do another one. Unfortunately, I was too busy the last weeks to time the post with the completion of brawl #250. Nevertheless, the update is coming soon.

I could have just used the same code I did last time, and had the post up already. But I wanted to take the chance to update spltools with code to work with guild data. Therefore, it will be a bit longer before that post is ready.

In this post I will go over the code I have added to spltools so far in this process. I'm also copying some of the code that I usually use to produce brawl reports.

Summary of updates
  • Class to download and work with brawl data.
  • Class to contain player brawl results.
  • Example script for using these classes.
  • New urls added to settings.py (Tournaments url, and some artwork urls).

separator.png

New class: Brawl

I added a class for working with brawl data:


image.png

With the functions collapsed, the class summarizes to:

image.png

We have the init function, an internal function to fetch the brawl data, a string representation of the class, the function print_results, which prints results for each player in the guild we specify and a function to print a markdown table with the brawl results:


image.png

The output of this function produces tables like this:

GuildWinsLossesCrowns SPS Merits
Absalom90+3840148117.9508457
Aggressive Gamblers83+3847140111.4997333
PeakMonsters Legion90+2422131105.0497486
PeakMonsters [Vikings]57+387311087.5415762
PeakMonsters [CHAMPS]44+38869575.5624976
Team Possible Diamond37+38938669.1114914
Roaring Twenties41+15486551.6033714
Druids20+7373124.8801624
HD HYBORIAN DREAM10+4501512.901714

You might have seen these tables before if you clicked into one of my brawl reports.

New class: BrawlerResults

This class is a simple container that we use to store a player's results in a specific brawl. It collects the relevant data from the dictionary we get as part of the data returned by the call to find_brawl.


image.png

I also added a simple string representation, so that we can do:

print(brawler_result)  # Where b is an instance of BrawlerResults
> kalkulus, fray 6: 8 W, 0 L, 0 AW.

separator.png

Usage example

This file can be found at examples/brawl_data_example.py.

image.png

Output:

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:

spltools update: Reward chest classes
spltools update: Checking which set a card belongs to
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

Sort:  

Cool update this time. I have not done much yet with the brawl api 👏

That's one I've interacted a lot with :)

I also added the requests.Session structure you suggested earlier. It seems quite convenient, but I think I ran into some rate limiting issues when I tried to download a lot of previous brawl data with it. Did you experience anything like that with it?

Quick search tells me that I can add an event hook to manually introduce a lag, but I'd rather not if there is any more standard solution available.

As far is a known the retry with backoff strategy is an solid one because the rate limit is determined by spl, which is necessary for them so the api traffic is not overloaded.

You can look if you can make the api call bigger so it includes more data at once (less calls). But i expect you need to do something for every brawl cycle.

These are the reason (for me to retrieve many transactions and balances) why there is sometimes a large wait to retrieve data from spl.

Not for your case but if you store the already retrieved data you do not have to retrieve it again in a later phase. Then you have to think on how to store it, this is where the application get more complicated imho.

For this I just store the raw returned data so its not that complicated, and rate limiting is just a small issue. I'm not even 100% that's what happened, but I found that I was not able to log into Splinterlands while my script was running 😅

you can look at event bases system that gives back the information asynchronous. that is more used in react framework, I'm not familiar with that in python

This post has been supported by @Splinterboost with a 15% upvote! Delagate HP to Splinterboost to Earn Daily HIVE rewards for supporting the @Splinterlands community!

Delegate HP | Join Discord

Congratulations @kalkulus! You have completed the following achievement on the Hive blockchain And have been rewarded with New badge(s)

You distributed more than 22000 upvotes.
Your next target is to reach 23000 upvotes.

You can view your badges on your board and compare yourself to others in the Ranking
If you no longer want to receive notifications, reply to this comment with the word STOP

Thanks for sharing! - @mango-juice

Thanks for your contribution to the STEMsocial community. Feel free to join us on discord to get to know the rest of us!

Please consider delegating to the @stemsocial account (85% of the curation rewards are returned).

You may also include @stemsocial as a beneficiary of the rewards of this post to get a stronger support. 
 

@kalkulus, I paid out 1.109 HIVE and 0.214 HBD to reward 1 comments in this discussion thread.