q p said: I originally toyed with the idea of getting EV spreads straight from the moveset stats (
example ), but they seemed a little... daunting to work with for a first project. So I settled on sticking to base speed and usage stats and letting the user handle everything else. :3c
Click to expand... Click to collapse... Howdy! I don't actually do much but lurk here (except for one post I made about a dumb gimmick set when I was new to BH ^^;), but I saw this and figured some code I have might help. I run a Skype bot that does, among other things, some informational commands about pokemon stuff (think showdown's !data and !analysis), and one of them presents usage data, which I pull from the moveset stats and then prune using python and some regexes I wrote. It's pretty simple:
Hide Code: for line in rawdata:
results = re.search(r"^ \| ([A-Za-z]+)\ +\|", line)
try:
try:
if results.group(1).lower() in pokemonlist: #is it a pokemon?
formatteddata[results.group(1)] = {}
currentpokemon = results.group(1)
formatteddata[currentpokemon][currentcategory] = currentpokemon.lower()
elif results.group(1) == "Abilities": #is it a category header?
currentcategory = "Abilities"
formatteddata[currentpokemon][currentcategory] = {}
elif results.group(1) == "Items":
currentcategory = "Items"
formatteddata[currentpokemon][currentcategory] = {}
elif results.group(1) == "Spreads":
currentcategory = "Spreads"
formatteddata[currentpokemon][currentcategory] = {}
elif results.group(1) == "Moves":
currentcategory = "Moves"
formatteddata[currentpokemon][currentcategory] = {}
elif results.group(1) == "Teammates":
currentcategory = "ELSE"
except:
pass
if currentcategory != "ELSE": #is it data under one of the important categories?
inlinedata = re.search(r"^ \| (.+) (.+)\% +\|", line)
#inlinedata.group(1), inlinedata.group(2)
formatteddata[currentpokemon][currentcategory][inlinedata.group(1)] = inlinedata.group(2)
except:
passwhere rawdata is the usage data .txt, and pokemonlist is a list of all pokemon. It returns a list formatted as such:
Code: formatteddata = {
"Labababba": {
"Abilities": {"Gooey": 50, "Cute Charm": 25, "Blaze": 25},
"Items": {"Sea Incense": 80, "White Herb": 20},
"Spreads": {"Relaxed:252/0/252/0/4/0": 90, "Bold:252/0/4/0/252/0": 10},
"Moves": {"Celebrate": 100, "Hold Hands": 100, "Baton Pass": 100, "Judgment": 100}
}
}
Of course, that code takes a minute or two to run on the gargantuan usage stat files, but you could opt to run a program like this one once, put the data in, and then rerun it every time new stats are posted. Getting rid of all the non-EV stuff and possibly doing it in another language would probably make it a lot faster, anyway. A better alternative (for a webapp that's meant to do a bunch of tiers, at least) might also be to pull out those two regexes and use them to do basically the same thing, but only for mons that are in a tier, or only the mons listed in its viability rankings, or only for mons above a usage cutoff (which you could easily use that second regex to find directly within the data, tbh). I haven't looked too hard into what FLG did above, but from what I understand theirs is a thing they ran in advance and used the results of, which would require rerunning every month if you wanted to base off usage stats, and rerunning every time a new analysis is posted otherwise. Even if it's not, I think having usage-based speed tiers rather than analysis-based ones would be cool :B
If you're not familiar with regex/regular expressions (and it sounds like you're fairly new to programming, so probably not), the tl;dr is that you can write small strings of code (ie, expressions) to look for patterns in text (ie, regularities). I use two in that code - "^ \| ([A-Za-z]+)\ +\|" to check if a line is a header, and then "^ \| (.+) (.+)\% +\|" to add any useful information it contains to formatteddata. The way mine is structured is not terribly efficient, because I wrote it very fast and didn't need it to run in realtime in a webapp or anything. But the regexes both work, so at the very least you can borrow those, and if you want to do something similar, well, here's how I did it. If you want to repay me, you can add BH speed tiers to your tool ;) I've found your tool really nifty already for LC tiers!
Last edited: Mar 17, 2016