Advertisement
Guest User

Untitled

a guest
Mar 5th, 2022
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.68 KB | None | 0 0
  1. # Individual mob loot analyzer
  2. # IGN: Iena Dark13 Sol
  3. # Twitch: wizzard117
  4.  
  5. shift <- function(x, n, invert=FALSE, default=NA){
  6. stopifnot(length(x)>=n)
  7. if(n==0){
  8. return(x)
  9. }
  10. n <- ifelse(invert, n*(-1), n)
  11. if(n<0){
  12. n <- abs(n)
  13. forward=FALSE
  14. }else{
  15. forward=TRUE
  16. }
  17. if(forward){
  18. return(c(rep(default, n), x[seq_len(length(x)-n)]))
  19. }
  20. if(!forward){
  21. return(c(x[seq_len(length(x)-n)+n], rep(default, n)))
  22. }
  23. }
  24.  
  25. clearlog <- function(df_log) {
  26. df_log$looted <- NULL
  27. df_log$damage <- NULL
  28. df_log$dmgtaken <- NULL
  29. df_log$blocked <- NULL
  30. df_log$avoided <- NULL
  31. df_log$missedyou <- NULL
  32. return (df_log)
  33. }
  34.  
  35. #parses decimal value in a string
  36. extract_decimal <- function(s) {
  37. return (regmatches(s,gregexpr("[-+]?[0-9]*\\.?[0-9]+([eE][-+]?[0-9]+)?",s)) )
  38. }
  39.  
  40. #parses anything between parentheses in a string
  41. extract__ <- function(j) {
  42. return (sub("\\).*", "", sub(".*\\(", "", j)) )
  43. }
  44.  
  45. #simply filters dataframe by boolean value
  46. prepare <- function(flag) {
  47. df_ <- logg[flag,]
  48. df_ <- clearlog(df_)
  49. return (df_)
  50. }
  51.  
  52. parse_simple <- function (flag) {
  53. df_ <- prepare (flag)
  54. df_$chatlog <- NULL
  55. return (df_)
  56. }
  57.  
  58. #parses the fact of critical hit (dealt by you or by mob) into a separate column
  59. parse_crits <- function (flag) {
  60. df_ <- prepare (flag)
  61. crit <- grepl("Critical hit", df_$chatlog, fixed = "TRUE")
  62. df_ <- cbind(df_, crit)
  63. df_$value <- as.numeric(extract_decimal(df_$chatlog))
  64. df_$chatlog <- NULL
  65. crit <- NULL
  66. return (df_)
  67. }
  68.  
  69. #treat sequence of shots/evades/misses as belonging to next loot event
  70. assign_lootevent <- function(df_) {
  71. r <- data.frame()
  72. n <- 1
  73. for (row in 1:nrow(df_)) {
  74. row_d <- df_[row,]
  75. row_l <- df_lootevents[n,]
  76. while (row_d$timestamp>df_lootevents[n,]$current) {n <- n+1}
  77. r<-rbind(r,df_lootevents[n,]$current)
  78. }
  79. names(r)[1]<-"lootevent"
  80. df_$lootevent <- r$lootevent
  81. r <- NULL
  82. n <- NULL
  83. return(df_)
  84. }
  85.  
  86. #unix times for when hunting starts / stops
  87. starts <- 1646318608
  88. stops <- 1646500000
  89.  
  90. path <- "C:/Users/Crazzy/Documents/Entropia Universe/chat.log"
  91. target <- "Rare Pleak Wing"
  92.  
  93. chatlog <- readLines (paste(path, sep = ""),)
  94.  
  95. # looted items
  96. looted <- grepl("You received", chatlog, fixed = "TRUE")
  97.  
  98. #damage dealt
  99. damage <- grepl("You inflicted", chatlog, fixed = "TRUE")
  100.  
  101. #damage taken
  102. dmgtaken <- grepl("You took", chatlog, fixed = "TRUE")
  103.  
  104. #mob evaded/dodged/jammed
  105. blocked <- grepl("your attack", chatlog, fixed = "TRUE")
  106.  
  107. #you evaded/dodged
  108. avoided <- grepl("the attack", chatlog, fixed = "TRUE")
  109.  
  110. #mob missed
  111. missedyou <- grepl("The attack missed you", chatlog, fixed = "TRUE")
  112.  
  113. logg <- as.data.frame(chatlog)
  114.  
  115. #extracting datetime string from chat log
  116. logg$datetime <- (substr(logg$chatlog, 1 ,19))
  117. logg$chatlog <- substr(logg$chatlog, 21 ,nchar(logg$chatlog))
  118.  
  119. #we only need data from our own system chat
  120. sys_chat <- startsWith( logg$chatlog, "[System] []")
  121.  
  122. logg <- cbind(logg,sys_chat)
  123. logg <- cbind(logg,looted)
  124. logg <- cbind(logg,damage)
  125. logg <- cbind(logg,dmgtaken)
  126. logg <- cbind(logg,blocked)
  127. logg <- cbind(logg,avoided)
  128. logg <- cbind(logg,missedyou)
  129.  
  130. sys_chat <- NULL
  131. chatlog <- NULL
  132.  
  133. #leave only needed chat log entries which in our case is system chat only
  134. logg <- logg[logg$sys_chat=="TRUE",]
  135. logg$sys_chat <- NULL
  136.  
  137. #we need only some events from the system chat
  138. logg$need <- logg$looted | logg$damage | logg$dmgtaken | logg$blocked | logg$avoided | logg$missedyou
  139.  
  140. #can purge everything else just to speed up further calculations and free some memory
  141. logg <- logg[logg$need,]
  142. logg$need <- NULL;
  143.  
  144. #convert datetime string to unix time
  145. logg$timestamp <- as.numeric(as.POSIXct(logg$datetime))
  146. logg$datetime <- NULL;
  147.  
  148. #filter by timestamps
  149. logg <- logg[logg$timestamp > starts & logg$timestamp < stops,]
  150.  
  151. #parse events where we only need timestamps of when it happened
  152. df_blocked <- parse_simple(logg$blocked)
  153. df_avoided <- parse_simple(logg$avoided)
  154. df_missedyou <- parse_simple(logg$missedyou)
  155.  
  156. #parse damage received and dealt with extra column displaying if it was crit
  157. df_dmgtaken <- parse_crits(logg$dmgtaken)
  158. df_damage <- parse_crits(logg$damage)
  159.  
  160. #parse loot events: item name, amount received and ped value in separate columns
  161. df_looted <- logg[logg$looted,]
  162. df_looted <- clearlog(df_looted)
  163. df_looted$amount <- as.numeric(extract__ (df_looted$chatlog))
  164. df_looted$chatlog <- gsub("\\[System\\] \\[\\] You received", "", df_looted$chatlog)
  165. df_looted$chatlog <- gsub("\\s*\\([^\\)]+\\)","",as.character(df_looted$chatlog))
  166. df_looted$chatlog <- gsub(" x ","|", df_looted$chatlog)
  167. item <- sub("\\|.*", "", df_looted$chatlog)
  168. df_looted <- cbind (df_looted,item)
  169. df_looted$chatlog <- gsub(".*\\|","", df_looted$chatlog)
  170. val <- unlist(extract_decimal(df_looted$chatlog))
  171. df_looted$value <- as.numeric(val)
  172. df_looted$chatlog <- NULL
  173. df_looted$item <- trimws(df_looted$item)
  174.  
  175. logg <- NULL
  176.  
  177. looted <- NULL
  178. damage <- NULL
  179. dmgtaken <- NULL
  180. blocked <- NULL
  181. avoided <- NULL
  182. missedyou <- NULL
  183. crit <- NULL
  184. val <- NULL
  185. item <- NULL
  186.  
  187.  
  188. #create loot event timestamps
  189. current <- unique(df_looted$timestamp)
  190. df_lootevents <- as.data.frame(current)
  191. prev <- shift(current, 1, default = starts)
  192. df_lootevents <- cbind(df_lootevents, prev)
  193.  
  194. current <- NULL
  195. prev <- NULL
  196.  
  197. #assign lootevents to all things happening
  198. df_avoided$stub = 0
  199. df_missedyou$stub = 0
  200. df_blocked$stub = 0
  201.  
  202. df_damage <- assign_lootevent(df_damage)
  203. #df_dmgtaken <- assign_lootevent(df_dmgtaken)
  204. #df_avoided <- assign_lootevent(df_avoided)
  205. df_blocked <- assign_lootevent(df_blocked)
  206. #df_missedyou <- assign_lootevent(df_missedyou)
  207.  
  208. df_avoided$stub <- NULL
  209. df_missedyou$stub <- NULL
  210. df_blocked$stub <- NULL
  211.  
  212. #new dataset that contains only data when we've looted desired item
  213. item_data <- df_looted[df_looted$item==target,]
  214. names(item_data)[1]<-"lootevent"
  215. item_data[4] <- NULL
  216.  
  217. #how many times has every mob evaded/dodged/jammed our attacks before killing him
  218. block_count <- aggregate(df_blocked$timestamp, by=list(lootevent=df_blocked$lootevent), FUN=function(x){NROW(x)})
  219.  
  220. #how many times have we dealt damage to every mob before killing him
  221. shots_landed <- aggregate(df_damage$timestamp, by=list(lootevent=df_damage$lootevent), FUN=function(x){NROW(x)})
  222.  
  223. #the amount of damage we dealt to every killed mob
  224. damage_dealt <- aggregate(df_damage$value, by=list(lootevent=df_damage$lootevent), FUN=sum)
  225.  
  226. crit <- unique(df_damage[df_damage$crit,])
  227.  
  228. #merge everything into one big single table
  229.  
  230. #merging total damage and number of shots
  231. big_data <- merge (x = shots_landed, y=damage_dealt, by.x = "lootevent", by.y = "lootevent")
  232. names(big_data)[2]<-"shots_landed"
  233. names(big_data)[3]<-"damage"
  234.  
  235. #adding how many times mob blocked our damage
  236. big_data = merge (x = big_data, y=block_count, all.x="TRUE")
  237. names(big_data)[4]<-"blocks"
  238. big_data[is.na(big_data)] <- 0
  239.  
  240. #total number of shots fired on each mob
  241. big_data$total <- big_data$shots_landed + big_data$blocks
  242.  
  243. #have we ever made a crit while killing each single mob
  244. big_data = merge (x = big_data, y=crit, by.x = "lootevent", by.y = "lootevent", all.x="TRUE")
  245. big_data[8] <- NULL
  246. big_data[6] <- NULL
  247. big_data[is.na(big_data)] <- FALSE
  248.  
  249. #have we acquired our desired item after looting mob
  250. big_data = merge (x = big_data, y=item_data, by.x = "lootevent", by.y = "lootevent", all.x="TRUE")
  251. big_data[is.na(big_data)] <- 0
  252.  
  253. #hypothesis testing time
  254.  
  255. acceptance <- 0.025
  256.  
  257. ftest <- function(df, col1, col2) {
  258.  
  259.  
  260. c1 <- nrow (df[col1 & col2,])
  261. c2 <- nrow (df[col1 & !col2,])
  262. c3 <- nrow (df[!col1 & col2,])
  263. c4 <- nrow (df[!col1 & !col2,])
  264.  
  265. dat <- data.frame(c(c1, c2),c(c3, c4))
  266. val <- fisher.test(dat)$p.value
  267. res <- ifelse(val >= acceptance , "NO" , "YES")
  268. return (res)
  269.  
  270. }
  271.  
  272. results <- data.frame(matrix(ncol = 2, nrow = 0))
  273.  
  274. #both must be boolean
  275. big_data$col1 = big_data$item==target
  276. big_data$col2 = big_data$damage<11
  277. results <- rbind (results, c ("10% or more damage is overkill",ftest(big_data, big_data$col1, big_data$col2)))
  278.  
  279. big_data$col2 = big_data$damage<12.5
  280. results <- rbind (results, c ("25% or more damage is overkill",ftest(big_data, big_data$col1, big_data$col2)))
  281. big_data$col2 = big_data$damage<15
  282. results <- rbind (results, c ("50% or more damage is overkill",ftest(big_data, big_data$col1, big_data$col2)))
  283. big_data$col2 = big_data$crit
  284. results <- rbind (results, c ("We've dealt critical strike at least once",ftest(big_data, big_data$col1, big_data$col2)))
  285. big_data$col2 = big_data$total==2
  286. results <- rbind (results, c ("We've killed the mob in exactly 2 shots",ftest(big_data, big_data$col1, big_data$col2)))
  287. big_data$col2 = big_data$total==3
  288. results <- rbind (results, c ("We've killed the mob in exactly 3 shots",ftest(big_data, big_data$col1, big_data$col2)))
  289. big_data$col2 = big_data$total==4
  290. results <- rbind (results, c ("We've killed the mob in exactly 4 shots",ftest(big_data, big_data$col1, big_data$col2)))
  291. big_data$col2 = big_data$total>=5
  292. results <- rbind (results, c ("We've killed the mob in 5 or more shots",ftest(big_data, big_data$col1, big_data$col2)))
  293. big_data$col2 = big_data$blocks==0
  294. results <- rbind (results, c ("We've landed all shots on the mob",ftest(big_data, big_data$col1, big_data$col2)))
  295. big_data$col2 = big_data$blocks>=1
  296. results <- rbind (results, c ("The mob evaded/dodged/jammed our attack at least once",ftest(big_data, big_data$col1, big_data$col2)))
  297. big_data$col2 = big_data$blocks>=2
  298. results <- rbind (results, c ("The mob evaded/dodged/jammed our attack at least twice",ftest(big_data, big_data$col1, big_data$col2)))
  299.  
  300. 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