Updates to spltools. Classes for Brawl data
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).
New class: Brawl
I added a class for working with brawl data:
With the functions collapsed, the class summarizes to:
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:
The output of this function produces tables like this:
Guild | Wins | Losses | Crowns | SPS | Merits |
---|---|---|---|---|---|
Absalom | 90+38 | 40 | 148 | 117.950 | 8457 |
Aggressive Gamblers | 83+38 | 47 | 140 | 111.499 | 7333 |
PeakMonsters Legion | 90+24 | 22 | 131 | 105.049 | 7486 |
PeakMonsters [Vikings] | 57+38 | 73 | 110 | 87.541 | 5762 |
PeakMonsters [CHAMPS] | 44+38 | 86 | 95 | 75.562 | 4976 |
Team Possible Diamond | 37+38 | 93 | 86 | 69.111 | 4914 |
Roaring Twenties | 41+15 | 48 | 65 | 51.603 | 3714 |
Druids | 20+7 | 37 | 31 | 24.880 | 1624 |
HD HYBORIAN DREAM | 10+4 | 50 | 15 | 12.901 | 714 |
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.
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.
Usage example
This file can be found at examples/brawl_data_example.py.
Output:
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
Congratulations @kalkulus! You have completed the following achievement on the Hive blockchain And have been rewarded with New badge(s)
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
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
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.