vinnydiehl / pokelog

The enthusiast's EV training tool.
https://www.pokelog.net
Other
3 stars 1 forks source link

Add filters and item behavior for different generations #26

Closed vinnydiehl closed 1 year ago

vinnydiehl commented 1 year ago

Would like to be able to filter search results by generation. Also, generation affects the behavior of some items, as well as the EV system in general.

Here is the business logic for the feature and their test implementation status:

Gen. Behavior Tests
1-2 EVs behave completely differently and will not be included (for now) N/A
3 The power items are unavailable (macho brace is available) ✔️
7 The macho brace is unavailable (power items are available) ✔️
3-4 Feathers/wings are not available ✔️
5-9 Feathers/wings are available ✔️
3-7 They are called wings ✔️
8-9 They are called feathers ✔️
3-5 Stats are capped at 255 ✔️
6-9 Stats are capped at 252 ✔️
4 EV berries reduce the EVs in their stat to 100 if it was >110 ✔️
4-6 The power items yield 4 EVs ✔️
7-9 The power items yield 8 EVs ✔️
3-7 Vitamins are capped at 100 EVs ✔️
8-9 Vitamins are capped at 252 EVs ✔️
All Species limitations in data/species.yml ✔️

First task is gathering data on the availability of each species throughout the generations so that I may apply a search filter. I'm thinking about putting the feature right on the filters page, but I'm not 100% sure about that; this is intended to be a persistent setting so that might not be appropriate.

vinnydiehl commented 1 year ago

Used this to get the data:

DATA_FILE = "data/species.yml"

# First 7 gens are easy
gens = [151, 251, 386, 493, 649, 721, 809].map { |n| (1..n).to_a }

puts "Fetching API data..."

# Get all the dexes from the PokeApi. Gen 8 has 3, gen 9 is just 1 for now
[[27, 28, 29], [31]].each do |dexes|
  gens << dexes.map do |dex|
    PokeApi.get(pokedex: dex).pokemon_entries.map do |entry|
      entry.pokemon_species.url.match(/\d+(?=\/$)/).to_s.to_i
    end
  end.flatten
end

# BD/SP
gens[7] += gens[3]

gens.map! &:uniq

data = YAML.unsafe_load_file DATA_FILE
data.each { |entry| entry[:generations] = [] }

gens.each_with_index do |ids, gen|
  puts "Processing Gen #{gen += 1}: #{ids.size} Pokémon found"

  ids.each do |id|
    # Use int_id on the species model to locate the proper ID
    Species.all.select { |sp| sp.int_id == id }.each do |species|
      data.find { |e| e[:id] == species.id }[:generations] << gen
    end
  end
end

File.open(DATA_FILE, "w") { |f| f.write data.to_yaml }