Skip to content

Commit

Permalink
improv: Added test for all_inconsistent category!
Browse files Browse the repository at this point in the history
  • Loading branch information
amindadgar committed Oct 17, 2023
1 parent 8e6ca08 commit 39254e1
Showing 1 changed file with 158 additions and 0 deletions.
158 changes: 158 additions & 0 deletions tc_core_analyzer_lib/tests/integration/test_inconsistently_active.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
import numpy as np
from tc_core_analyzer_lib.assess_engagement import EngagementAssessment
from tc_core_analyzer_lib.utils.activity import DiscordActivity


def test_inconsistently_active():
"""
test conssitently_active members category
"""
acc_names = []
acc_count = 5
for i in range(5):
acc_names.append(f"user{i}")

acc_names = np.array(acc_names)

# four weeks
max_interval = 28

# preparing empty joined members dict
all_joined = dict(
zip(np.array(range(max_interval), dtype=str), np.repeat(set(), max_interval))
)

activity_dict = {
"all_joined": {},
"all_joined_day": all_joined,
"all_consistent": {},
"all_vital": {},
"all_active": {},
"all_connected": {},
"all_paused": {},
"all_new_disengaged": {},
"all_disengaged": {},
"all_unpaused": {},
"all_returned": {},
"all_new_active": {},
"all_still_active": {},
"all_dropped": {},
"all_disengaged_were_newly_active": {},
"all_disengaged_were_consistently_active": {},
"all_disengaged_were_vital": {},
"all_lurker": {},
"all_about_to_disengage": {},
"all_disengaged_in_past": {},
"all_inconsistent": {},
"all_new_consistent": {},
"all_new_vital": {},
"all_became_not_consistent": {},
"all_became_unvital": {},
}
memberactivities = activity_dict.keys()

INT_THR = 1 # minimum number of interactions to be active
UW_DEG_THR = 1 # minimum number of accounts interacted with to be active
PAUSED_T_THR = 1 # time period to remain paused
CON_T_THR = 4 # time period to be consistent active
CON_O_THR = 3 # time period to be consistent active
EDGE_STR_THR = 5 # minimum number of interactions for connected
UW_THR_DEG_THR = 5 # minimum number of accounts for connected
VITAL_T_THR = 4 # time period to assess for vital
VITAL_O_THR = 3 # times to be connected within VITAL_T_THR to be vital
STILL_T_THR = 2 # time period to assess for still active
STILL_O_THR = 2 # times to be active within STILL_T_THR to be still active
# time periods into the past (history) to be newly active for computing dropped
DROP_H_THR = 2
# consecutive time periods into the past to have not been active for computing
DROP_I_THR = 1

act_param = [
INT_THR,
UW_DEG_THR,
PAUSED_T_THR,
CON_T_THR,
CON_O_THR,
EDGE_STR_THR,
UW_THR_DEG_THR,
VITAL_T_THR,
VITAL_O_THR,
STILL_T_THR,
STILL_O_THR,
DROP_H_THR,
DROP_I_THR,
]

int_mat = {
DiscordActivity.Reply: np.zeros((acc_count, acc_count)),
DiscordActivity.Mention: np.zeros((acc_count, acc_count)),
DiscordActivity.Reaction: np.zeros((acc_count, acc_count)),
}

# `user_1` intracting with `user_2`
int_mat[DiscordActivity.Reaction][0, 1] = 2

activities = [
DiscordActivity.Reaction,
DiscordActivity.Mention,
DiscordActivity.Reply,
]

engagement = EngagementAssessment(
activities=activities, activities_ignore_0_axis=[], activities_ignore_1_axis=[]
)

# the analytics
for w_i in range(max_interval):
# time window
WINDOW_D = 7

(_, *activity_dict) = engagement.compute(
int_mat=int_mat,
w_i=w_i,
acc_names=acc_names,
act_param=act_param,
WINDOW_D=WINDOW_D,
**activity_dict,
)
if w_i == 14:
int_mat[DiscordActivity.Reaction][0, 1] = 0


activity_dict = dict(zip(memberactivities, activity_dict))

print("all_consistent:", activity_dict["all_consistent"])
print("all_paused:", activity_dict["all_paused"])
print("all_inconsistent:", activity_dict["all_inconsistent"])


assert activity_dict["all_inconsistent"] == {
"0": set(),
"1": set(),
"2": set(),
"3": set(),
"4": set(),
"5": set(),
"6": set(),
"7": {"user0", "user1"},
"8": {"user0", "user1"},
"9": {"user0", "user1"},
"10": {"user0", "user1"},
"11": {"user0", "user1"},
"12": {"user0", "user1"},
"13": {"user0", "user1"},
"14": set(), # was incluedd in all_paused here
"15": {"user0", "user1"},
"16": {"user0", "user1"},
"17": {"user0", "user1"},
"18": {"user0", "user1"},
"19": {"user0", "user1"},
"20": {"user0", "user1"},
"21": set(),
"22": set(),
"23": set(),
"24": set(),
"25": set(),
"26": set(),
"27": set(),
}

0 comments on commit 39254e1

Please sign in to comment.