Last active
December 4, 2015 15:37
-
-
Save safferli/214a6dcf7afd9553f491 to your computer and use it in GitHub Desktop.
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
library(dplyr) | |
library(data.table) | |
library(xlsx) | |
# Define your workspace: "X:/xxx/" | |
wd <- "D:/gitlab/analytics/" | |
setwd(wd) | |
f.drop.players <- function(server.size = 1000, playtime = 90, dispersion = 0.7) { | |
t <- sort(rlnorm(server.size, log(playtime), dispersion)) | |
result <- data.frame(playtime = playtime, | |
dispersion = dispersion, | |
fully.empty = t[server.size]/60, | |
percent90.empty = t[ceiling(server.size*0.9)]/60) | |
return(result) | |
} | |
# playtime -- sequences of 15mins | |
x <- seq(45, 120, by = 15) | |
# run each draw 100 times | |
times <- 100 | |
result <- vector("list", times) | |
for (i in seq_len(times)) { | |
# this generates a list of lists: as.data.frame(t(mapply(f.drop.players, playtime = x))) | |
result[[i]] <- do.call(rbind, lapply(x,function(x){f.drop.players(playtime = x)})) | |
} | |
# bind into a single dataframe | |
result <- rbindlist(result) | |
# get results | |
dta <- result %>% | |
group_by(playtime, dispersion) %>% | |
summarise_each( | |
funs(mean, median, min, max) | |
) %>% | |
select( | |
playtime, dispersion, starts_with("fully"), starts_with("percent90") | |
) | |
# output to excel | |
write.xlsx(t(as.data.frame(dta)), "server-spindown.xlsx", col.names = FALSE) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment