<jupyter_start><jupyter_text>Sample summary table stats<jupyter_code># passive reverts = times when bot was reverted by someone else
# active reverts = times when bot reverts someone else
%reload_ext autoreload
%autoreload 2
%matplotlib inline
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

from datetime import datetime
df = pd.read_csv('revs_scored_jan.tsv', sep='\t', header=0)
days = df.rev_timestamp.map(lambda ts: datetime.utcfromtimestamp(ts).day)
df['day'] = days
df_sample = df[df.day<22]
df_bots = df_sample[df_sample.user_is_bot]
df_reverters = df[df.is_revert]

df_reverted = df[df.is_reverted]
df_reverted.seconds_to_revert = df_reverted.seconds_to_revert.astype('str').astype('int')
df_reverted = df_reverted[df_reverted.seconds_to_revert < 86400]
df_reverted.revert_id = df_reverted.revert_id.astype('int')
# merging df_reverted and df_reverters to get dataset of all reverted edits

all_reverted_edits = pd.merge(df_reverted, df_reverters, 
             how='inner', 
             left_on='revert_id', 
             right_on='rev_id', 
             suffixes=('', '_reverter')
)
df_bot_active_reverts = all_reverted_edits[all_reverted_edits.user_is_bot_reverter == True]
df_bot_passive_reverts = all_reverted_edits[all_reverted_edits.user_is_bot == True]
df_human_active_reverts = all_reverted_edits[all_reverted_edits.user_is_bot_reverter == False]
df_human_passive_reverts = all_reverted_edits[all_reverted_edits.user_is_bot == False]
# current variable summary:
#   df_sample = all edits in our time frame
#   df_bots = all edits made by bots in time frame
#   df_reverters = all reverting edits in dataset (not limited to time frame)
#   df_reverted = all revisions that were reverted w/in 24 hours in time frame
#   all_reverted_edits = every edit reverted w/in 24 hours with reverted and revert edit info, within time frame
#     df_bot_active_reverts = all active reverts by bots of humans and bots in time frame
#     df_bot_passive_reverts = all revisions by bots which were reverted (by humans or bots), with reverting user info merged, in time frame
#     df_human_active_reverts
#     df_human_passive_reverts<jupyter_output><empty_output><jupyter_text>total edits<jupyter_code># total edits in sample
len(df_sample)
# total bot edits
len(df_bots)
# percent bot edits
len(df_bots) / len(df_sample)
# total human edits
len(df_sample[df_sample.user_is_bot == False])<jupyter_output><empty_output><jupyter_text>bot edits / bot passive reverts<jupyter_code># total reverts
len(df_bot_passive_reverts)
# reverts by bots
len(df_bot_passive_reverts[df_bot_passive_reverts.user_is_bot_reverter == True])
# reverts by humans
len(df_bot_passive_reverts[df_bot_passive_reverts.user_is_bot_reverter == False])
# self-reverts
len(df_bot_passive_reverts[df_bot_passive_reverts.user_text == df_bot_passive_reverts.user_text_reverter])<jupyter_output><empty_output><jupyter_text>human edits / human passive reverts<jupyter_code># total reverts
len(df_human_passive_reverts)
# reverts by bots
len(df_human_passive_reverts[df_human_passive_reverts.user_is_bot_reverter == True])
# reverts by humans
len(df_human_passive_reverts[df_human_passive_reverts.user_is_bot_reverter == False])
# self-reverts
len(df_human_passive_reverts[df_human_passive_reverts.user_text == df_human_passive_reverts.user_text_reverter])<jupyter_output><empty_output><jupyter_text>bot reverts / bot active reverts<jupyter_code># total bot reverts
len(df_bot_active_reverts.groupby("revert_id").count())
# bot reverts of other bots
a = df_bot_active_reverts[df_bot_active_reverts.user_is_bot == True]
len(a.groupby("revert_id").count())
# bot reverts of humans
a = df_bot_active_reverts[df_bot_active_reverts.user_is_bot == False]
len(a.groupby("revert_id").count())
# bot self-reverts
a = df_bot_active_reverts[df_bot_active_reverts.user_text == df_bot_active_reverts.user_text_reverter]
len(a.groupby("revert_id").count())<jupyter_output><empty_output><jupyter_text>human reverts / human active reverts<jupyter_code># total reverts
len(df_human_active_reverts.groupby("revert_id").count())
# human reverts of bots
a = df_human_active_reverts[df_human_active_reverts.user_is_bot == True]
len(a.groupby("revert_id").count())
# human reverts of other humans
a = df_human_active_reverts[df_human_active_reverts.user_is_bot == False]
len(a.groupby("revert_id").count())
# human reverts of other humans
a = df_human_active_reverts[df_human_active_reverts.user_text == df_human_active_reverts.user_text_reverter]
len(a.groupby("revert_id").count())<jupyter_output><empty_output><jupyter_text>Average revert set size<jupyter_code># bot passive reverts
df_bot_passive_reverts.revert_set_size_reverter.astype('int').mean()
# human passive reverts
df_human_passive_reverts.revert_set_size_reverter.astype('int').mean()
# bot active reverts
a = df_bot_active_reverts.groupby(["revert_id", "revert_set_size_reverter"], as_index = False).count()
a.revert_set_size_reverter.astype('int').mean()
# human active reverts
a = df_human_active_reverts.groupby(["revert_id", "revert_set_size_reverter"], as_index = False).count()
a.revert_set_size_reverter.astype('int').mean()
# human active bot reverts
a = df_human_active_reverts[df_human_active_reverts.user_is_bot == True]
a = a.groupby(["revert_id", "revert_set_size_reverter"], as_index = False).count()
a.revert_set_size_reverter.astype('int').mean()
# human active human reverts
a = df_human_active_reverts[df_human_active_reverts.user_is_bot == False]
a = a.groupby(["revert_id", "revert_set_size_reverter"], as_index = False).count()
a.revert_set_size_reverter.astype('int').mean()<jupyter_output><empty_output><jupyter_text>percentage of reverts reverting multiple edits<jupyter_code>len(df[(df.is_revert) & (df.revert_set_size == "1")]) / len(df[df.is_revert])<jupyter_output><empty_output><jupyter_text>percentage of bot edits reverted by human which were reverted with a human edit<jupyter_code>reverts_h = df_bot_passive_reverts.groupby('revert_id', as_index=False).count()[["revert_id"]]
sdf1 = df.loc[df.is_reverted] 
sdf1.revert_id = sdf1.revert_id.astype('str').astype('int')

sdf2 = reverts_h
reverts_h = pd.merge(sdf1, sdf2, 
             how='inner', 
             left_on='revert_id', 
             right_on='revert_id', 
             suffixes=('', '')
)
a = reverts_h.groupby(["revert_id", "user_is_bot"], as_index=False).count()
# percentage of anomie's human passive reverts reverted with a human edit
#    (found by dividing the amount of reverts that reverted a human by the ones reverting anomie)

len(a[a.user_is_bot==False]) / len(a[a.user_is_bot==True])<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10459873760144274, 'fraction_numerical': 0.003005710850616171, 'mean_word_length': 7.175675675675675, 'pattern_counts': {'":': 0, '<': 39, '<?xml version=': 0, '>': 37, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '9', 'dir': 'jupyter-structured-clean-dedup', 'id': '395087', 'license': 'MIT', 'n_tokens_mistral': 2498, 'n_tokens_neox': 2470, 'n_words': 441, 'path': 'reu2021/summary_stats.ipynb', 'repo_name': 'levon003/wiki-ores-feedback', 'size': '6654'}