Pokemon Pocket Julia Notebook

I created a Pluto Notebook to view and filter Pokemon Pocket cards. I think it ended up looking pretty nice, rendering images of the cards inside the data frames. I thought I would share it here in case anyone else plays the game or finds it illustrative.

nathanrboyer/PokemonPocketCardData: Suggests Pokemon Pocket card packs you should open based on which cards you are missing.

7 Likes

This is very cool! Really liked how the image display β€œjust works”

1 Like

@pdeffebach You may be interested in this, and I think it relates to Redesign of stack and unstack Β· Issue #3237 Β· JuliaData/DataFrames.jl.

Yesterday I had fairly clean Split-Apply-Combine code under β€œPack Information”.

@chain desired_cards_unpacked begin
	groupby(:pack)
	@combine(
		$"Desired Cards" = [copy(:image)],
		:Total = $nrow,
		:β—Š = count(==("β—Š"), :rarity),
		:β—Šβ—Š = count(==("β—Šβ—Š"), :rarity),
		:β—Šβ—Šβ—Š = count(==("β—Šβ—Šβ—Š"), :rarity),
		:β—Šβ—Šβ—Šβ—Š = count(==("β—Šβ—Šβ—Šβ—Š"), :rarity),
		:β˜† = count(==("β˜†"), :rarity),
		:β˜†β˜† = count(==("β˜†β˜†"), :rarity),
		:β˜†β˜†β˜† = count(==("β˜†β˜†β˜†"), :rarity),
		:β™› = count(==("β™›"), :rarity),
	)
	@rselect!(:Pack = [pack_images[:pack]], $(Not(:pack)))
	sort!([:Total, :β—Š, :β—Šβ—Š, :β—Šβ—Šβ—Š, :β—Šβ—Šβ—Šβ—Š, :β˜†, :β˜†β˜†, :β˜†β˜†β˜†, :β™›], rev=true)
end

Today I figured I could clean up and shorten the code by removing the hard-coded rarity symbols. But I’m not sure this equivalent is better.

@chain desired_cards_unpacked begin
	groupby([:pack, :rarity])
	combine(
		:image => (x -> [copy(x)]),
		nrow,
		renamecols = false,
	)
	sort!(:rarity)
	unstack(:rarity, :nrow, fill=0)
	groupby(:pack)
	combine(
		:image => (x -> [reduce(vcat, x)]),
		Not(:pack, :image) .=> sum,
		renamecols = false,
	)
	transform!(Not(:pack, :image) => (+) => :total)
	select!(
		:pack => ByRow(x -> [pack_images[x]]) => "Pack",
		:image => "Desired Cards",
		:total => "Total",
		Not(:pack, :image, :total),
	)
	sort!("Total", rev=true)
end

I ended up abandoning DataFramesMeta.jl in this cell because I was adding more escaping characters than I was saving, and I couldn’t get renamecols=false to work. Also, now I am Split-Apply-Combine-Sorting twice. Do you know a better way?


Example data is below if you don’t want to download the Pluto notebook:

desired_cards_unpacked = DataFrame(
    [
        "A1" 41 "Arcanine ex" "β—Šβ—Šβ—Šβ—Š" "Pikachu" "150" "Image 1"
        "A1" 45 "Flareon" "β—Šβ—Šβ—Š" "Charizard" "120" "Image 2"
        "A1" 125 "Hypno" "β—Šβ—Šβ—Š" "Pikachu" "100" "Image 3"
        "A1" 203 "Kangaskhan" "β—Šβ—Šβ—Š" "Charizard" "100" "Image 4"
        "A1" 267 "Misty" "β˜†β˜†" "Pikachu" missing "Image 5"
        "A1" 275 "Articuno ex" "β˜†β˜†" "Mewtwo" "140" "Image 6"
        "A1a" 46 "Aerodactyl ex" "β—Šβ—Šβ—Šβ—Š" "Mew" "140" "Image 7"
        "A1a" 72 "Vaporeon" "β˜†" "Mew" "120" "Image 8"
        "A1a" 84 "Aerodactyl ex" "β˜†β˜†" "Mew" "140" "Image 9"
        "A2" 24 "Magmortar" "β—Šβ—Šβ—Š" "Palkia" "130" "Image 10"
    ],
    ["series", "number", "name", "rarity", "pack", "health", "image"],
)
pack_images = Dict(
    "Pikachu" => "Pikachu",
    "Charizard" => "Charizard",
    "Mewtwo" => "Mewtwo",
    "Mew" => "Mew",
    "Palkia" => "Palkia",
    "Dialga" => "Dialga",
)