Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Individual mob loot analyzer
- # IGN: Iena Dark13 Sol
- # Twitch: wizzard117
- shift <- function(x, n, invert=FALSE, default=NA){
- stopifnot(length(x)>=n)
- if(n==0){
- return(x)
- }
- n <- ifelse(invert, n*(-1), n)
- if(n<0){
- n <- abs(n)
- forward=FALSE
- }else{
- forward=TRUE
- }
- if(forward){
- return(c(rep(default, n), x[seq_len(length(x)-n)]))
- }
- if(!forward){
- return(c(x[seq_len(length(x)-n)+n], rep(default, n)))
- }
- }
- clearlog <- function(df_log) {
- df_log$looted <- NULL
- df_log$damage <- NULL
- df_log$dmgtaken <- NULL
- df_log$blocked <- NULL
- df_log$avoided <- NULL
- df_log$missedyou <- NULL
- return (df_log)
- }
- #parses decimal value in a string
- extract_decimal <- function(s) {
- return (regmatches(s,gregexpr("[-+]?[0-9]*\\.?[0-9]+([eE][-+]?[0-9]+)?",s)) )
- }
- #parses anything between parentheses in a string
- extract__ <- function(j) {
- return (sub("\\).*", "", sub(".*\\(", "", j)) )
- }
- #simply filters dataframe by boolean value
- prepare <- function(flag) {
- df_ <- logg[flag,]
- df_ <- clearlog(df_)
- return (df_)
- }
- parse_simple <- function (flag) {
- df_ <- prepare (flag)
- df_$chatlog <- NULL
- return (df_)
- }
- #parses the fact of critical hit (dealt by you or by mob) into a separate column
- parse_crits <- function (flag) {
- df_ <- prepare (flag)
- crit <- grepl("Critical hit", df_$chatlog, fixed = "TRUE")
- df_ <- cbind(df_, crit)
- df_$value <- as.numeric(extract_decimal(df_$chatlog))
- df_$chatlog <- NULL
- crit <- NULL
- return (df_)
- }
- #treat sequence of shots/evades/misses as belonging to next loot event
- assign_lootevent <- function(df_) {
- r <- data.frame()
- n <- 1
- for (row in 1:nrow(df_)) {
- row_d <- df_[row,]
- row_l <- df_lootevents[n,]
- while (row_d$timestamp>df_lootevents[n,]$current) {n <- n+1}
- r<-rbind(r,df_lootevents[n,]$current)
- }
- names(r)[1]<-"lootevent"
- df_$lootevent <- r$lootevent
- r <- NULL
- n <- NULL
- return(df_)
- }
- #unix times for when hunting starts / stops
- starts <- 1646318608
- stops <- 1646500000
- path <- "C:/Users/Crazzy/Documents/Entropia Universe/chat.log"
- target <- "Rare Pleak Wing"
- chatlog <- readLines (paste(path, sep = ""),)
- # looted items
- looted <- grepl("You received", chatlog, fixed = "TRUE")
- #damage dealt
- damage <- grepl("You inflicted", chatlog, fixed = "TRUE")
- #damage taken
- dmgtaken <- grepl("You took", chatlog, fixed = "TRUE")
- #mob evaded/dodged/jammed
- blocked <- grepl("your attack", chatlog, fixed = "TRUE")
- #you evaded/dodged
- avoided <- grepl("the attack", chatlog, fixed = "TRUE")
- #mob missed
- missedyou <- grepl("The attack missed you", chatlog, fixed = "TRUE")
- logg <- as.data.frame(chatlog)
- #extracting datetime string from chat log
- logg$datetime <- (substr(logg$chatlog, 1 ,19))
- logg$chatlog <- substr(logg$chatlog, 21 ,nchar(logg$chatlog))
- #we only need data from our own system chat
- sys_chat <- startsWith( logg$chatlog, "[System] []")
- logg <- cbind(logg,sys_chat)
- logg <- cbind(logg,looted)
- logg <- cbind(logg,damage)
- logg <- cbind(logg,dmgtaken)
- logg <- cbind(logg,blocked)
- logg <- cbind(logg,avoided)
- logg <- cbind(logg,missedyou)
- sys_chat <- NULL
- chatlog <- NULL
- #leave only needed chat log entries which in our case is system chat only
- logg <- logg[logg$sys_chat=="TRUE",]
- logg$sys_chat <- NULL
- #we need only some events from the system chat
- logg$need <- logg$looted | logg$damage | logg$dmgtaken | logg$blocked | logg$avoided | logg$missedyou
- #can purge everything else just to speed up further calculations and free some memory
- logg <- logg[logg$need,]
- logg$need <- NULL;
- #convert datetime string to unix time
- logg$timestamp <- as.numeric(as.POSIXct(logg$datetime))
- logg$datetime <- NULL;
- #filter by timestamps
- logg <- logg[logg$timestamp > starts & logg$timestamp < stops,]
- #parse events where we only need timestamps of when it happened
- df_blocked <- parse_simple(logg$blocked)
- df_avoided <- parse_simple(logg$avoided)
- df_missedyou <- parse_simple(logg$missedyou)
- #parse damage received and dealt with extra column displaying if it was crit
- df_dmgtaken <- parse_crits(logg$dmgtaken)
- df_damage <- parse_crits(logg$damage)
- #parse loot events: item name, amount received and ped value in separate columns
- df_looted <- logg[logg$looted,]
- df_looted <- clearlog(df_looted)
- df_looted$amount <- as.numeric(extract__ (df_looted$chatlog))
- df_looted$chatlog <- gsub("\\[System\\] \\[\\] You received", "", df_looted$chatlog)
- df_looted$chatlog <- gsub("\\s*\\([^\\)]+\\)","",as.character(df_looted$chatlog))
- df_looted$chatlog <- gsub(" x ","|", df_looted$chatlog)
- item <- sub("\\|.*", "", df_looted$chatlog)
- df_looted <- cbind (df_looted,item)
- df_looted$chatlog <- gsub(".*\\|","", df_looted$chatlog)
- val <- unlist(extract_decimal(df_looted$chatlog))
- df_looted$value <- as.numeric(val)
- df_looted$chatlog <- NULL
- df_looted$item <- trimws(df_looted$item)
- logg <- NULL
- looted <- NULL
- damage <- NULL
- dmgtaken <- NULL
- blocked <- NULL
- avoided <- NULL
- missedyou <- NULL
- crit <- NULL
- val <- NULL
- item <- NULL
- #create loot event timestamps
- current <- unique(df_looted$timestamp)
- df_lootevents <- as.data.frame(current)
- prev <- shift(current, 1, default = starts)
- df_lootevents <- cbind(df_lootevents, prev)
- current <- NULL
- prev <- NULL
- #assign lootevents to all things happening
- df_avoided$stub = 0
- df_missedyou$stub = 0
- df_blocked$stub = 0
- df_damage <- assign_lootevent(df_damage)
- #df_dmgtaken <- assign_lootevent(df_dmgtaken)
- #df_avoided <- assign_lootevent(df_avoided)
- df_blocked <- assign_lootevent(df_blocked)
- #df_missedyou <- assign_lootevent(df_missedyou)
- df_avoided$stub <- NULL
- df_missedyou$stub <- NULL
- df_blocked$stub <- NULL
- #new dataset that contains only data when we've looted desired item
- item_data <- df_looted[df_looted$item==target,]
- names(item_data)[1]<-"lootevent"
- item_data[4] <- NULL
- #how many times has every mob evaded/dodged/jammed our attacks before killing him
- block_count <- aggregate(df_blocked$timestamp, by=list(lootevent=df_blocked$lootevent), FUN=function(x){NROW(x)})
- #how many times have we dealt damage to every mob before killing him
- shots_landed <- aggregate(df_damage$timestamp, by=list(lootevent=df_damage$lootevent), FUN=function(x){NROW(x)})
- #the amount of damage we dealt to every killed mob
- damage_dealt <- aggregate(df_damage$value, by=list(lootevent=df_damage$lootevent), FUN=sum)
- crit <- unique(df_damage[df_damage$crit,])
- #merge everything into one big single table
- #merging total damage and number of shots
- big_data <- merge (x = shots_landed, y=damage_dealt, by.x = "lootevent", by.y = "lootevent")
- names(big_data)[2]<-"shots_landed"
- names(big_data)[3]<-"damage"
- #adding how many times mob blocked our damage
- big_data = merge (x = big_data, y=block_count, all.x="TRUE")
- names(big_data)[4]<-"blocks"
- big_data[is.na(big_data)] <- 0
- #total number of shots fired on each mob
- big_data$total <- big_data$shots_landed + big_data$blocks
- #have we ever made a crit while killing each single mob
- big_data = merge (x = big_data, y=crit, by.x = "lootevent", by.y = "lootevent", all.x="TRUE")
- big_data[8] <- NULL
- big_data[6] <- NULL
- big_data[is.na(big_data)] <- FALSE
- #have we acquired our desired item after looting mob
- big_data = merge (x = big_data, y=item_data, by.x = "lootevent", by.y = "lootevent", all.x="TRUE")
- big_data[is.na(big_data)] <- 0
- #hypothesis testing time
- acceptance <- 0.025
- ftest <- function(df, col1, col2) {
- c1 <- nrow (df[col1 & col2,])
- c2 <- nrow (df[col1 & !col2,])
- c3 <- nrow (df[!col1 & col2,])
- c4 <- nrow (df[!col1 & !col2,])
- dat <- data.frame(c(c1, c2),c(c3, c4))
- val <- fisher.test(dat)$p.value
- res <- ifelse(val >= acceptance , "NO" , "YES")
- return (res)
- }
- results <- data.frame(matrix(ncol = 2, nrow = 0))
- #both must be boolean
- big_data$col1 = big_data$item==target
- big_data$col2 = big_data$damage<11
- results <- rbind (results, c ("10% or more damage is overkill",ftest(big_data, big_data$col1, big_data$col2)))
- big_data$col2 = big_data$damage<12.5
- results <- rbind (results, c ("25% or more damage is overkill",ftest(big_data, big_data$col1, big_data$col2)))
- big_data$col2 = big_data$damage<15
- results <- rbind (results, c ("50% or more damage is overkill",ftest(big_data, big_data$col1, big_data$col2)))
- big_data$col2 = big_data$crit
- results <- rbind (results, c ("We've dealt critical strike at least once",ftest(big_data, big_data$col1, big_data$col2)))
- big_data$col2 = big_data$total==2
- results <- rbind (results, c ("We've killed the mob in exactly 2 shots",ftest(big_data, big_data$col1, big_data$col2)))
- big_data$col2 = big_data$total==3
- results <- rbind (results, c ("We've killed the mob in exactly 3 shots",ftest(big_data, big_data$col1, big_data$col2)))
- big_data$col2 = big_data$total==4
- results <- rbind (results, c ("We've killed the mob in exactly 4 shots",ftest(big_data, big_data$col1, big_data$col2)))
- big_data$col2 = big_data$total>=5
- results <- rbind (results, c ("We've killed the mob in 5 or more shots",ftest(big_data, big_data$col1, big_data$col2)))
- big_data$col2 = big_data$blocks==0
- results <- rbind (results, c ("We've landed all shots on the mob",ftest(big_data, big_data$col1, big_data$col2)))
- big_data$col2 = big_data$blocks>=1
- results <- rbind (results, c ("The mob evaded/dodged/jammed our attack at least once",ftest(big_data, big_data$col1, big_data$col2)))
- big_data$col2 = big_data$blocks>=2
- results <- rbind (results, c ("The mob evaded/dodged/jammed our attack at least twice",ftest(big_data, big_data$col1, big_data$col2)))
- colnames(results) <- c(paste("Do we have different chance of looting ",target," if"), paste ("Answer can be wrong with",acceptance*100,"% chance"))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement