Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- library('tidyverse')
- library('lubridate')
- read_weechatlog <- function(file_name, parse_dates=TRUE, messages_only=TRUE,
- sanitize_names=TRUE) {
- pattern <- "(\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2})\t(.+)\t(.+)"
- lines <- readLines(file_name) %>%
- str_match_all(pattern)
- # using do.call(...) is WAY faster than calling
- # rbind() for some reason...?
- data <- do.call("rbind", lines) %>%
- as.data.frame(stringsAsFactors=FALSE) %>%
- transmute(date = V2, name = V3, message = V4)
- if (parse_dates) {
- date_format = "%Y-%m-%d %H:%M:%S"
- data$date = parse_datetime(data$date, date_format)
- }
- if (messages_only) {
- weechat_operators = c("--", "<--", "-->", " *")
- data <- data %>%
- filter(!name %in% weechat_operators)
- }
- if (sanitize_names) {
- irc_usermodes = "[~&@%]"
- data <- data %>%
- mutate(name = str_replace_all(name, irc_usermodes, ""))
- }
- return(data)
- }
- log <- read_weechatlog("#trollhour.weechatlog")
- selected_day = as.POSIXct("2018-7-20")
- data <- log %>%
- filter(year(date) == 2018 & month(date) == 7 & day(date) == 20) %>%
- mutate(date = hour(date))
- ggplot(data, aes(x=as.factor(date), group=name, color=name)) +
- labs(x="Hour", y="Message count",
- title=paste("Activity in #trollhour on", selected_day)) +
- geom_smooth(stat="count", show.legend=FALSE) +
- geom_point(stat="count")
Add Comment
Please, Sign In to add comment