Last active
October 3, 2019 13:08
-
-
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
This file contains hidden or 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 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))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Here's the forced migration table