Skip to content

Instantly share code, notes, and snippets.

@joelnitta
Created January 23, 2024 01:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joelnitta/98b6a9c00f58c433334c323b10052558 to your computer and use it in GitHub Desktop.
Save joelnitta/98b6a9c00f58c433334c323b10052558 to your computer and use it in GitHub Desktop.
Check the cards played on turn one of a Limited MtG game
# To install magicr
# pak::pkg_install("joelnitta/magicr")
library(tidyverse)
library(magicr)
# OP:
# I'm working on some WOE replay data for Premier Draft and I'm seeing some
# stuff I don't understand. On row-index 8541, user plays both "Bakery Raid" and
# "Welcome to Sweet Tooth" on turn one, which can't happen. The same happens on
# rows 184035, 280782,496625. The same thing happens on row 579074 with "Harried
# Spearguard" and "Hopeful Vigil" on turn one. Is anyone else able to see this
# too?
# Define function to read in a single row from WOE replay data
load_woe_game_row_single <- function(row, woe_colnames) {
# Load a single row of choice
magicr::mr_get_17lands_data(
"WOE", "replay", "premier", nrows = 1, skip = row - 1) %>%
# set column names
set_names(woe_colnames) %>%
# convert all values to character to avoid parsing errors when joining rows
mutate(across(everything(), as.character))
}
# Load card data (card IDs mapped to names)
cards <- data.table::fread(
"https://17lands-public.s3.amazonaws.com/analysis_data/cards/cards.csv") %>%
mutate(id = as.character(id))
# Load WOE column names
woe_colnames <- mr_get_17lands_data("WOE", "replay", "premier", nrows = 1) %>%
colnames()
# Define row numbers to fetch based on question
rows_get <- c(8541, 184035, 280782, 496625, 579074)
# Loop across row numbers and load them
woe_data <- map_df(rows_get, ~load_woe_game_row_single(.x, woe_colnames))
# Select cards cast on turn 1 and get their names
woe_data %>%
select(draft_id, matches("user_turn_1_.*cast")) %>%
select(-contains("oppo_")) %>%
pivot_longer(names_to = "cast", values_to = "id", -draft_id) %>%
separate_longer_delim(id, delim = "|") %>%
left_join(select(cards, id, name)) %>%
filter(!is.na(name))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment