Skip to content

Instantly share code, notes, and snippets.

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 dwbapst/a6c14157fe79b2a92e1b79890c820fe7 to your computer and use it in GitHub Desktop.
Save dwbapst/a6c14157fe79b2a92e1b79890c820fe7 to your computer and use it in GitHub Desktop.
Pokemon GO nest migration table - oddish removed, with gen 5 and no Eevee - 10-03-19
# Pokemon GO nest migration table - oddish removed, with gen 5 and no Eevee - 10-03-19
# taxa in full nesting list not in NEW nesting list
removeTaxaNew <- c("Oddish", "Eevee")
# taxa in full nesting list not in OLD nesting list
# this is often an empty set because
# the nesting list was fully utilized before an event
# if full list before migration, just do `""`
removeTaxaOld <- c("Eevee")
# REVERSE MIGRATION
reverseMigration <- FALSE
# where do you want the files / what do you want them named
filename <- "remove_oddish_plus_some_gen_5"
path<-"~/Documents/"
####################################
###################################
fullNestingList<-c(
# pre-halloween-2018 nesting list, as estimated by u/Clyphox and u/SnipeThemAll
# with hippopotas added, and gen 5 added as following u/MGDuck
###############
# Gen 1
##############
"Bulbasaur", "Charmander", "Squirtle",
# "Caterpie", "Weedle", "Pidgey", "Rattata", "Spearow", "Ekans", #REMOVED - u/Clyphox
"Pikachu",
# "Sandshrew", "Nidoran-F", "Nidoran-M", #REMOVED - u/Clyphox
"Clefairy", "Vulpix",
# "Jigglypuff", "Zubat", #REMOVED - u/Clyphox
"Oddish",
# "Paras", "Venonat", "Diglett", "Meowth", #REMOVED - u/Clyphox
"Psyduck",
# "Mankey", #REMOVED - u/Clyphox
"Growlithe", "Poliwag", "Abra", "Machop",
# "Bellsprout", #REMOVED - u/Clyphox
"Tentacool",
# "Geodude", #REMOVED - u/Clyphox
"Ponyta",
# "Slowpoke", #REMOVED - u/Clyphox
"Magnemite", "Doduo", "Seel", "Shellder", "Gastly", "Onix",
# "Drowzee", "Krabby", #REMOVED - u/Clyphox
"Voltorb", "Exeggcute", "Cubone", "Rhyhorn", "Horsea",
# "Goldeen", "Staryu", #REMOVED - u/Clyphox
"Scyther", "Jynx", "Electabuzz", "Magmar", "Pinsir",
"Magikarp", "Eevee",
"Omanyte", "Kabuto",
#"Dratini", #CD Pokemon
#################
###############
# Gen 2
##############
"Chikorita", "Cyndaquil", "Totodile",
# "Sentret", "Hoothoot", "Ledyba", "Spinarak", #REMOVED - u/Clyphox
"Chinchou",
# "Natu", #REMOVED - u/Clyphox
#"Mareep", # CD Pokemon
# "Marill", #REMOVED - u/Clyphox
"Sudowoodo", #### ADDED - u/Clyphox #####
# "Hoppip", #REMOVED - u/Clyphox
"Aipom",
# "Sunkern", #REMOVED - u/Clyphox
"Yanma",
# "Wooper", #REMOVED - u/Clyphox
"Misdreavus", "Wobbuffet", "Girafarig", "Dunsparce", "Snubbull",
"Qwilfish", "Shuckle", "Sneasel", "Teddiursa",
# "Slugma", #REMOVED - u/Clyphox
"Swinub",
# "Remoraid", #REMOVED - u/Clyphox
"Mantine", "Skarmory", #### ADDED - u/Clyphox #####
# "Houndour", #REMOVED - u/Clyphox
"Phanpy", "Stantler", #### ADDED - u/Clyphox #####
#"Larvitar", #CD Pokemon
###################
###############
# Gen 3
##############
"Treecko", "Torchic", "Mudkip", "Poochyena",
# "Zigzagoon", "Wurmple", #REMOVED - u/Clyphox
"Seedot",
# "Tailow", #REMOVED - u/Clyphox
"Wingull", "Surskit", "Shroomish",
# "Whismur", #REMOVED - u/Clyphox
"Makuhita", "Nosepass", "Skitty",
"Sableye", #### ADDED - u/Clyphox #####
# "Aron", #REMOVED - u/Clyphox
"Meditite", "Electrike",
"Plusle", "Minun", #### ADDED - u/Clyphox #####
# "Gulpin", #REMOVED - u/Clyphox
"Carvanha", "Wailmer", "Numel", "Spoink", "Swablu",
# "Barboach", #REMOVED - u/Clyphox
"Corphish", "Baltoy",
"Lileep", "Anorith", #### ADDED - u/Clyphox #####
"Shuppet", "Duskull",
# "Spheal", #REMOVED - u/Clyphox
"Luvdisc",
#"Beldum", #CD Pokemon
##################
###############
# Gen 4
##############
"Turtwig", "Chimchar", "Piplup",
"Bidoof",
"Hippopotas",
###############
# Gen 5
#################
"Snivy", "Tepig", "Oshawott",
"Patrat", "Lillipup", "Purrloin",
"Blitzle", "Foongus"
)
oldNesting <- fullNestingList
whichRemoveOld <- sapply(oldNesting,
function(x) all(x != removeTaxaOld))
oldNesting <- oldNesting[whichRemoveOld]
newNesting <- fullNestingList
whichRemoveNew <- sapply(newNesting,
function(x) all(x != removeTaxaNew))
newNesting <- newNesting[whichRemoveNew]
if(reverseMigration){
newNesting1 <- newNesting
newNesting <- oldNesting
oldNesting <- newNesting1
}
#########################################
# for nest migrations - source functions, modify vectors of lists of nesting species, then run
# use kable to produce markdown table for pasting to Silph Road
#approximate ranges for each species in the nesting lists
getRangesForNestingSpecies<-function(nestingSpecies, arbMax=256){
nNesting<-length(nestingSpecies)
intLength<-arbMax/nNesting
lowBound<-((1:nNesting)-1)*intLength
upperBound<-lowBound+intLength
res<-cbind(lowBound,upperBound)
rownames(res)<-nestingSpecies
return(res)
}
# find new species for each old nesting seed range
findNew<-function(oldRange,newRanges){
newRanges<-round(newRanges,5)
oldLow<-round(oldRange[1],5)
oldHigh<-round(oldRange[2],5)
#
newLowRow<-which(newRanges[,1]<=oldLow & newRanges[,2]>oldLow)
newHighRow<-which(newRanges[,1]<oldHigh & newRanges[,2]>=oldHigh)
#
#print(c(newLowRow,newHighRow))
newRows<-newLowRow:newHighRow
newNestNames<-rownames(newRanges)[newRows]
# calculate proportion of overlap (prob of shift)
propOverlap<-sapply(newRows,function(x)
getPropOverlap(X=newRanges[x,],Y=oldRange))
# paste them together
res<-paste0(newNestNames," (",round(propOverlap*100,1),"%)")
return(res)
}
getPropOverlap<-function(X,Y){
# calculate how much range X overlaps with range Y
overlapRange<-c(max(X[1],Y[1]),min(X[2],Y[2]))
overlap<-overlapRange[2]-overlapRange[1]
# divide by length of Y
propOverlap<-overlap/(Y[2]-Y[1])
return(propOverlap)
}
# master function
predictNestingShifts<-function(oldNestingList,newNestingList){
oldRanges<-getRangesForNestingSpecies(oldNestingList)
newRanges<-getRangesForNestingSpecies(newNestingList)
#
nestShifts<-apply(oldRanges,1,findNew,newRanges=newRanges)
if(length(dim(nestShifts))!=2){
# need to add NAs when there are uneven number of possible species
# for different nests to potentially migrate to
maxNSlength<-max(sapply(nestShifts,length))
nestShifts<-sapply(nestShifts,function(x){
if(length(x)<maxNSlength){
res<-c(x,rep(NA,maxNSlength-length(x)))
}else{
res<-x
}
return(res)
})
}
nestShifts<-t(nestShifts)
#print(nestShifts)
nestShifts<-cbind(oldNestingSpecies=rownames(nestShifts),nestShifts)
colnames(nestShifts)[2:ncol(nestShifts)]<-paste0("NewNestingSpecies",
1:(ncol(nestShifts)-1))
rownames(nestShifts)<-NULL
return(nestShifts)
}
###################################################
nestShifts<-predictNestingShifts(
oldNestingList=oldNesting,
newNestingList=newNesting)
# get path
filename <- paste0(path, "nesting_species_predictions_",
filename, "_",
format(Sys.time(), "%m-%d-%y"))
# use knitr to convert the table of nest shifts to markdown
x<-knitr::kable(nestShifts)
cat(x,file=paste0(filename, ".txt"), sep = "\n")
rmarkdown::render(paste0(filename, ".txt"))
system(paste0("xdg-open ", filename, ".txt"))
system(paste0("xdg-open ", filename, ".html"))
#############################################
#nestShifts
# 05/17/2019: typical nesting list length is 88
# previous nesting list length
print(paste0("Old Nesting List Length: ", length(oldNesting)))
# new nesting list length
print(paste0("New Nesting List Length: ", length(newNesting)))
# full nesting list of all potentially nesting species
print(paste0("Full Nesting List Length: ", length(fullNestingList)))
@dwbapst
Copy link
Author

dwbapst commented Oct 3, 2019

Here's the forced migration table

oldNestingSpecies NewNestingSpecies1 NewNestingSpecies2
Bulbasaur Bulbasaur (100%) NA
Charmander Bulbasaur (1.1%) Charmander (98.9%)
Squirtle Charmander (2.1%) Squirtle (97.9%)
Pikachu Squirtle (3.2%) Pikachu (96.8%)
Clefairy Pikachu (4.3%) Clefairy (95.7%)
Vulpix Clefairy (5.3%) Vulpix (94.7%)
Oddish Vulpix (6.4%) Psyduck (93.6%)
Psyduck Psyduck (7.4%) Growlithe (92.6%)
Growlithe Growlithe (8.5%) Poliwag (91.5%)
Poliwag Poliwag (9.6%) Abra (90.4%)
Abra Abra (10.6%) Machop (89.4%)
Machop Machop (11.7%) Tentacool (88.3%)
Tentacool Tentacool (12.8%) Ponyta (87.2%)
Ponyta Ponyta (13.8%) Magnemite (86.2%)
Magnemite Magnemite (14.9%) Doduo (85.1%)
Doduo Doduo (16%) Seel (84%)
Seel Seel (17%) Shellder (83%)
Shellder Shellder (18.1%) Gastly (81.9%)
Gastly Gastly (19.1%) Onix (80.9%)
Onix Onix (20.2%) Voltorb (79.8%)
Voltorb Voltorb (21.3%) Exeggcute (78.7%)
Exeggcute Exeggcute (22.3%) Cubone (77.7%)
Cubone Cubone (23.4%) Rhyhorn (76.6%)
Rhyhorn Rhyhorn (24.5%) Horsea (75.5%)
Horsea Horsea (25.5%) Scyther (74.5%)
Scyther Scyther (26.6%) Jynx (73.4%)
Jynx Jynx (27.7%) Electabuzz (72.3%)
Electabuzz Electabuzz (28.7%) Magmar (71.3%)
Magmar Magmar (29.8%) Pinsir (70.2%)
Pinsir Pinsir (30.9%) Magikarp (69.1%)
Magikarp Magikarp (31.9%) Omanyte (68.1%)
Omanyte Omanyte (33%) Kabuto (67%)
Kabuto Kabuto (34%) Chikorita (66%)
Chikorita Chikorita (35.1%) Cyndaquil (64.9%)
Cyndaquil Cyndaquil (36.2%) Totodile (63.8%)
Totodile Totodile (37.2%) Chinchou (62.8%)
Chinchou Chinchou (38.3%) Sudowoodo (61.7%)
Sudowoodo Sudowoodo (39.4%) Aipom (60.6%)
Aipom Aipom (40.4%) Yanma (59.6%)
Yanma Yanma (41.5%) Misdreavus (58.5%)
Misdreavus Misdreavus (42.6%) Wobbuffet (57.4%)
Wobbuffet Wobbuffet (43.6%) Girafarig (56.4%)
Girafarig Girafarig (44.7%) Dunsparce (55.3%)
Dunsparce Dunsparce (45.7%) Snubbull (54.3%)
Snubbull Snubbull (46.8%) Qwilfish (53.2%)
Qwilfish Qwilfish (47.9%) Shuckle (52.1%)
Shuckle Shuckle (48.9%) Sneasel (51.1%)
Sneasel Sneasel (50%) Teddiursa (50%)
Teddiursa Teddiursa (51.1%) Swinub (48.9%)
Swinub Swinub (52.1%) Mantine (47.9%)
Mantine Mantine (53.2%) Skarmory (46.8%)
Skarmory Skarmory (54.3%) Phanpy (45.7%)
Phanpy Phanpy (55.3%) Stantler (44.7%)
Stantler Stantler (56.4%) Treecko (43.6%)
Treecko Treecko (57.4%) Torchic (42.6%)
Torchic Torchic (58.5%) Mudkip (41.5%)
Mudkip Mudkip (59.6%) Poochyena (40.4%)
Poochyena Poochyena (60.6%) Seedot (39.4%)
Seedot Seedot (61.7%) Wingull (38.3%)
Wingull Wingull (62.8%) Surskit (37.2%)
Surskit Surskit (63.8%) Shroomish (36.2%)
Shroomish Shroomish (64.9%) Makuhita (35.1%)
Makuhita Makuhita (66%) Nosepass (34%)
Nosepass Nosepass (67%) Skitty (33%)
Skitty Skitty (68.1%) Sableye (31.9%)
Sableye Sableye (69.1%) Meditite (30.9%)
Meditite Meditite (70.2%) Electrike (29.8%)
Electrike Electrike (71.3%) Plusle (28.7%)
Plusle Plusle (72.3%) Minun (27.7%)
Minun Minun (73.4%) Carvanha (26.6%)
Carvanha Carvanha (74.5%) Wailmer (25.5%)
Wailmer Wailmer (75.5%) Numel (24.5%)
Numel Numel (76.6%) Spoink (23.4%)
Spoink Spoink (77.7%) Swablu (22.3%)
Swablu Swablu (78.7%) Corphish (21.3%)
Corphish Corphish (79.8%) Baltoy (20.2%)
Baltoy Baltoy (80.9%) Lileep (19.1%)
Lileep Lileep (81.9%) Anorith (18.1%)
Anorith Anorith (83%) Shuppet (17%)
Shuppet Shuppet (84%) Duskull (16%)
Duskull Duskull (85.1%) Luvdisc (14.9%)
Luvdisc Luvdisc (86.2%) Turtwig (13.8%)
Turtwig Turtwig (87.2%) Chimchar (12.8%)
Chimchar Chimchar (88.3%) Piplup (11.7%)
Piplup Piplup (89.4%) Bidoof (10.6%)
Bidoof Bidoof (90.4%) Hippopotas (9.6%)
Hippopotas Hippopotas (91.5%) Snivy (8.5%)
Snivy Snivy (92.6%) Tepig (7.4%)
Tepig Tepig (93.6%) Oshawott (6.4%)
Oshawott Oshawott (94.7%) Patrat (5.3%)
Patrat Patrat (95.7%) Lillipup (4.3%)
Lillipup Lillipup (96.8%) Purrloin (3.2%)
Purrloin Purrloin (97.9%) Blitzle (2.1%)
Blitzle Blitzle (98.9%) Foongus (1.1%)
Foongus Foongus (100%) NA

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment