In this update, I have added some basic battle data processing to spltools. This is likely just the first update among several that will be concerned with battle data. A short summary of the update is:
- A function for downloading and saving battle data
- A class for storing and processing battle data
- A class for storing info about a battle lineup (Team)
- A function for generating the url for a scaled Splinterlands card image.
- A method in the Battle class for generating a markdown summary of the battle
Using the battle class is exceedingly simple for now. Simply initialize the Battle class with
the battle id, and optionally a directory to save the data if you don't want to have to download it next time you want to use that battle for something:
We can then call the markdown_summary method. This prints text to the terminal that can be copied directly into a hive post.
Copied text produces the following:
ag26 vs. kalkulus | |
---|---|
Type | Ranked |
Format | modern |
Mana | 13 |
Elements | Blue, Green, White, Black |
Winner | kalkulus |
ag26's team:
kalkulus's team:
Overview of added functionality:
Downloading battle data
There is not that much to say about the battle data download function. It takes a battle queue id as input (you can find that in the url when viewing a Splinterlands battle, or from several api endpoints), downloads the data, and optionally saves it for later use.
Battle class
The battle class takes the downloaded battle data and processes it into a more useful structure. For now, only a limited portion of the data is kept. This will likely be expanded later on when I use the other fields for something. You might notice that the Battle class instantiates two Team classes. These contain information about the two teams played in this battle.
Team class
The team class simply stores information about which cards is in the team, and has two methods for returning readable summaries of that. get_names returns the summoner name and a list of the monster names, and hive images returns a string with urls for the summoner and card images.
Markdown battle summary
In the markdown_summary method, we create a markdown table containing the match type, the format, mana cap, active elements and the winner. Also, there is an option (active by default) to also return hive image urls for the cards used in the battle. This option makes use of the hive_image function:
Hive image
The hive_image function constructs an url that can be copied into a hive post to display a Splinterlands card at a given level, with an image of specified width and height. Note that the image will keep its aspect ratio, so only the most limiting of these two dimensions will be used. For now, the function will not give alpha borders since alpha and beta cards have the save id, and I default it to the beta border. I plan to enable alpha borders eventually.
Final words
That concludes the post for this update. 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:
6. spltools setup guide
5. Best brawler code
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
Great addition again. Nice to see you still continue to work on this project 💪
Yeah, its still something I want to do. I just had to get rapidsps up and running, so this had to be on the backburner for a little while :)
as user or did you develop the tool?
Developed it, yeah 😎
Nice one, can be a helpful service for many and some extra SPS income 👍
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.
Thanks for sharing! - @yonilkar
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 1250 replies.
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
Check out our last posts: