Guest User

Untitled

a guest
Jul 22nd, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1. library('tidyverse')
  2. library('lubridate')
  3.  
  4. read_weechatlog <- function(file_name, parse_dates=TRUE, messages_only=TRUE,
  5. sanitize_names=TRUE) {
  6. pattern <- "(\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2})\t(.+)\t(.+)"
  7.  
  8. lines <- readLines(file_name) %>%
  9. str_match_all(pattern)
  10.  
  11. # using do.call(...) is WAY faster than calling
  12. # rbind() for some reason...?
  13. data <- do.call("rbind", lines) %>%
  14. as.data.frame(stringsAsFactors=FALSE) %>%
  15. transmute(date = V2, name = V3, message = V4)
  16.  
  17. if (parse_dates) {
  18. date_format = "%Y-%m-%d %H:%M:%S"
  19.  
  20. data$date = parse_datetime(data$date, date_format)
  21. }
  22.  
  23. if (messages_only) {
  24. weechat_operators = c("--", "<--", "-->", " *")
  25.  
  26. data <- data %>%
  27. filter(!name %in% weechat_operators)
  28. }
  29.  
  30. if (sanitize_names) {
  31. irc_usermodes = "[~&@%]"
  32.  
  33. data <- data %>%
  34. mutate(name = str_replace_all(name, irc_usermodes, ""))
  35. }
  36.  
  37. return(data)
  38. }
  39.  
  40. log <- read_weechatlog("#trollhour.weechatlog")
  41.  
  42. selected_day = as.POSIXct("2018-7-20")
  43.  
  44. data <- log %>%
  45. filter(year(date) == 2018 & month(date) == 7 & day(date) == 20) %>%
  46. mutate(date = hour(date))
  47.  
  48. ggplot(data, aes(x=as.factor(date), group=name, color=name)) +
  49. labs(x="Hour", y="Message count",
  50. title=paste("Activity in #trollhour on", selected_day)) +
  51. geom_smooth(stat="count", show.legend=FALSE) +
  52. geom_point(stat="count")
Add Comment
Please, Sign In to add comment