Are there software tools for analysing forum threads?

This forum is for discussion related to the game.
Samson23
Samson23
Watcher
Samson23
Watcher
Watcher
Posts: 0
Joined: April 18, 2020

Are there software tools for analysing forum threads?

Post Post #0 (isolation #0) » Sat Apr 18, 2020 10:13 am

Post by Samson23 »

I have just started a Mafia style game, and my first thought is that it would be useful to have some sort of software tools that could read forum threads, and produce output such as posting rates and "who voted for who" networks. Do any such things exist? Would the use of such be considered bad sportsmanship?
Samson23
Samson23
Watcher
Samson23
Watcher
Watcher
Posts: 0
Joined: April 18, 2020

Post Post #2 (isolation #1) » Sun Apr 19, 2020 4:26 am

Post by Samson23 »

That is a question I have not yet got an answer to. However, it seems to me that it would increase the fun if one is able to have various statistics to hand. Below is my first go at an analysis tool for my game, but it is on another forum so the xpath expersions would have to change to work here. The current output is:

How many posts has each user made:

Name 1 Name 2 Name 3 Name 4 Name 5 Name 6 Name 7 Name 8 Name 9 Name 10 Name 11 Name 12
2 7 13 7 13 6 1 11 4 6 8 3
Name 13 Name 14 Name 15 Name 16
4 5 1 1

How many votes has each user ever had:

Name 1 Name 2 Name 3 Name 4 Name 5 Name 6 Name 7 Name 8 Name 9 Name 10 Name 11 Name 12
2 1 0 2 1 3 1 2 1 1 1 1
Name 13 Name 14
1 2

I can load the output file into cytoscape and get a "who voted for who" network:

Image

As I say, this is my first game so I do not know what use this will be, but some seems likely.

Spoiler:

Code: Select all

library(xml2)
setwd("E:/hugh/games/mafia")

use_cache <- T
no_pages <- 5
page_stub <- "https://some_forum/page-"

one_thread <- data.frame(author = character(), voted = character(), date_str = character(), time_str = character())

for(page_itr in 1:no_pages) {
  uri <- paste0(page_stub, page_itr)
  print(uri)
  
  page <- read_html(uri)

  divs <- xml_find_all(page, "//div[@class='messageInfo primaryContent']")
  length(divs)
  head(divs)
  
  for(post_itr in 1:length(divs)) {
  
    author_nodeset <- xml_find_all(divs[post_itr], "div/div/span/span/a")
    length(author_nodeset)
    author_nodeset
    author_str <- xml_text(author_nodeset)
    
    voted_nodeset <- xml_find_all(divs[post_itr], "div/article/blockquote/b")
    length(voted_nodeset)
    voted_nodeset
    voted_raw <- xml_text(voted_nodeset)
    # If has Vote:, use first such instance, else first bolded text
    definatly_voted <- voted_raw[grep("[vV]ote:.*", voted_raw)]
    if(length(definatly_voted) == 1) {
      voted_str <- trimws(sub(".*vote:", "", definatly_voted[1], ignore.case = T))
    } else if(length(definatly_voted) == 0) {
      if(length(definatly_voted) == 0) {
        voted_str <- ""
      } else {
        voted_str <- trimws(sub(".*vote:", "", voted_raw[1], ignore.case = T))
      }
    } else {
      voted_str <- trimws(sub(".*vote:", "", definatly_voted[1], ignore.case = T))
    }
    
    date_nodeset <- xml_find_all(divs[post_itr], "div/div/span/a/abbr")
    length(date_nodeset)
    date_nodeset
    date_str <- xml_attr(date_nodeset, "data-datestring")
    time_str <- xml_attr(date_nodeset, "data-timestring")
    datetime_str <- paste(date_str, time_str)
    
    
    one_post <- data.frame(author = author_str, voted = voted_str, date_str = date_str, time_str = time_str)
    
    if(nrow(one_post) > 1) {
      print(paste("page", page_itr,"post",post_itr,"has",nrow(one_post)))
      print(one_post)
    }
    
    one_thread <- rbind(one_thread, one_post)
    
  }
  
}

one_thread

print(paste("postcount", nrow(one_thread)))

print(table(one_thread$author))
print(table(one_thread$voted))

one_thread$date_obj <- as.Date(one_thread$date_str,format="%b %d, %y")

last_nights_last_post <- 1
last_night_date <- one_thread[last_nights_last_post,]$date_obj

#todays_votes <- one_thread[one_thread$voted != "" & one_thread$date_obj > last_night_date,]
todays_votes <- one_thread[one_thread$voted != "" ,]

# from https://stackoverflow.com/questions/8203818/how-to-select-the-first-and-last-row-within-a-grouping-variable-in-a-data-frame
active_votes <- aggregate(todays_votes, by=list(todays_votes$author), FUN = function(x) {  last = tail(x,1) } )

print(active_votes)
print(table(active_votes$voted))

all_votes <- aggregate(date_obj ~ author + voted, one_thread[one_thread$voted != "",], FUN = length)

write.csv(all_votes, file = "all_votes.csv")

# Anonymise

levels(one_thread$author) <- paste("Name",1:16)
one_thread[one_thread$voted == "","voted"] <- NA_character_
levels(one_thread$voted) <- paste("Name", 1:14)

Return to “Mafia Discussion”