Last active
August 29, 2015 14:12
-
-
Save ABrambleNinja/359e8811c0cd8885bb31 to your computer and use it in GitHub Desktop.
Interprets Antar's stats and allows for easy access of raw data for usage based metas
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Pokemon Showdown Data Interpreter | |
# Created by ABrambleNinja (smogon: Piccolo Daimao), released under MIT license | |
# <abrambleninja.mit-license.org> | |
# | |
# Find the most updated version of this code here: | |
# https://gist.github.com/ABrambleNinja/359e8811c0cd8885bb31 | |
require 'pry' | |
require 'uri' | |
require 'net/http' | |
print "Please enter URL of statistics you wish to interpret: " | |
url = URI(gets.chomp) | |
raw_data = Net::HTTP.get(url) | |
pokemon = [] | |
total_battles = 0 | |
class Pokemon | |
attr_reader :rank, :pokemon, :usage_percent, :raw_number, :real_number | |
def initialize opts | |
@rank = opts[:rank] | |
@pokemon = opts[:pokemon] | |
@usage_percent = opts[:usage_percent] | |
@raw_number = opts[:raw_number] | |
@real_number = opts[:real_number] | |
end | |
def to_s | |
@pokemon | |
end | |
end | |
raw_data.split("\n").each.with_index do |line, index| | |
if !(line =~ /^\ Total battles:\ /).nil? | |
total_battles = line[16..line.length] | |
end | |
if !(line =~ /^\ \|\ \d{1,3}\ {2,4}\|\ /i).nil? # this line is a pokemon line | |
opts = {} | |
opts[:rank] = index - 4 # gotta adjust for the lines that aren't Pokemon | |
opts[:pokemon] = line[10..28].strip | |
opts[:usage_percent] = line[31..38].strip.to_f | |
opts[:raw_number] = line[43..48].strip.to_i | |
opts[:real_number] = line[62..67].strip.to_i | |
pokemon << Pokemon.new(opts) | |
end | |
end | |
def to_list pokemon | |
"[" + pokemon.map { |mon| "'#{mon}'" }.join(", ") + "]" | |
end | |
# Stats available here: http://www.smogon.com/forums/threads/3508502/ | |
# Pokemon class has attributes rank, pokemon, usage_percent, raw_number, | |
# and real_number. to_list(pokemon) takes an array and returns it in a | |
# JS-usable format. pokemon is an array that contains Pokemon objects in | |
# order of usage. Enjoy! | |
binding.pry |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment