Code for importing packages
import pandas as pd
from rcounting import side_threads, thread_navigation as tn
We start with some imports, which aren’t particularly interesting, so they’ve been folded.
import pandas as pd
from rcounting import side_threads, thread_navigation as tn
The rcounting
tools have various pieces of functionality to validate the side threads it knows about, both in terms of whether the counts follow the expected format, and whether the thread obeys any special rules that might apply. Here’s an example of what that looks like in a python script.
# Pick a comment early in a chain
= pd.DataFrame(tn.fetch_comments("gja0ehe"))
comments = side_threads.get_side_thread('slowestest')
side_thread print("The thread is valid!" if side_thread.is_valid_thread(comments) else "The thread is invalid")
The thread is valid!
The thread is valid - excellent! There’s also a script that you can run from the command line to validate the most common threads. Try typing rcounting validate -h
in a terminal to see how to use it.
The rcounting tools also have functionality to do some network analysis. The following snippet will generate the (comment, replying to, weight) graph for the top 250 counters. The heavy lifting is done by the response graph [[file:../rcounting/analysis.py::def response_graph(df, n=250, username_column=“username”):][response_graph]] function in analysis.py.
from rcounting import analysis, counters
import sqlite3
from pathlib import Path
= Path("../data")
data_directory = sqlite3.connect(data_directory / "counting.sqlite")
db = pd.read_sql("select comments.username "
counts "from comments join submissions "
"on comments.submission_id = submissions.submission_id "
"where comments.position > 0 "
"order by submissions.timestamp, comments.position", db)
"username"] = counts["username"].apply(counters.apply_alias)
counts[= 250
n = analysis.response_graph(counts, n, username_column="username")
graph =False, by="Weight").head() graph.sort_values(ascending
Source | Target | Weight | |
---|---|---|---|
853 | Antichess | Countletics | 109808 |
1633 | Countletics | Antichess | 109793 |
14934 | thephilsblogbar2 | GarlicoinAccount | 98844 |
2943 | GarlicoinAccount | thephilsblogbar2 | 98821 |
12825 | nonsensy | Countletics | 93082 |