Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Add 5 new member activity analysis #13

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

setup(
name="tc-core-analyzer-lib",
version="1.1.0",
version="1.2.0",
author="Mohammad Amin Dadgar, TogetherCrew",
maintainer="Mohammad Amin Dadgar",
maintainer_email="[email protected]",
Expand Down
36 changes: 36 additions & 0 deletions tc_core_analyzer_lib/assess_engagement.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
assess_remainder,
assess_still_active,
assess_vital,
assess_inconsistent,
)
from .utils.compute_interaction_per_acc import thr_int

Expand Down Expand Up @@ -74,6 +75,11 @@ def compute(
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,
):
"""
Assess engagment levels for all active members in a time period
Expand Down Expand Up @@ -244,6 +250,11 @@ def compute(
all_paused[str(w_i)] - all_consistent[str(w_i)]
)

# # # INCONSISTENT
all_inconsistent[str(w_i)] = assess_inconsistent(
all_active, all_paused, all_new_active, all_consistent, w_i
)

# # # SUBDIVIDE DISENGAGED TYPES # # #

# make temporary dictionary for remaining disengaged members
Expand Down Expand Up @@ -290,6 +301,26 @@ def compute(
all_disengaged_were_consistently_active[str(w_i)] = set()
all_disengaged_were_newly_active[str(w_i)] = set()

# # # DETECT CHANGES SINCE LAST PERIOD # # #
if w_i - WINDOW_D >= 0:
all_new_consistent[str(w_i)] = (
all_consistent[str(w_i)] - all_consistent[str(w_i - WINDOW_D)]
)
all_new_vital[str(w_i)] = (
all_vital[str(w_i)] - all_vital[str(w_i - WINDOW_D)]
)
all_became_not_consistent[str(w_i)] = (
all_consistent[str(w_i - WINDOW_D)] - all_consistent[str(w_i)]
)
all_became_unvital[str(w_i)] = (
all_vital[str(w_i - WINDOW_D)] - all_vital[str(w_i)]
)
else:
all_new_consistent[str(w_i)] = set()
all_new_vital[str(w_i)] = set()
all_became_not_consistent[str(w_i)] = set()
all_became_unvital[str(w_i)] = set()

return (
graph,
all_joined,
Expand All @@ -312,4 +343,9 @@ def compute(
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,
)
10 changes: 10 additions & 0 deletions tc_core_analyzer_lib/tests/integration/test_active_members.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ def test_no_active():
"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": {},
}

WINDOW_D = 7
Expand Down Expand Up @@ -142,6 +147,11 @@ def test_single_active():
"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": {},
}
# time window
WINDOW_D = 7
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ def test_all_active_fourteen_period():
"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": {},
}

WINDOW_D = 7
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
# test all_active members using the interaction matrix
import numpy as np
from tc_core_analyzer_lib.assess_engagement import EngagementAssessment
from tc_core_analyzer_lib.utils.activity import DiscordActivity


def test_became_not_consistent():
acc_names = []
acc_count = 10

act_param = {
"INT_THR": 1,
"UW_DEG_THR": 1,
"PAUSED_T_THR": 1,
"CON_T_THR": 4,
"CON_O_THR": 3,
"EDGE_STR_THR": 5,
"UW_THR_DEG_THR": 5,
"VITAL_T_THR": 4,
"VITAL_O_THR": 3,
"STILL_T_THR": 2,
"STILL_O_THR": 2,
"DROP_H_THR": 2,
"DROP_I_THR": 1,
}

for i in range(acc_count):
acc_names.append(f"user{i}")

acc_names = np.array(acc_names)

# four weeks
max_interval = 35

# 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": {},
}
memberactivites = activity_dict.keys()

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)),
}
int_mat[DiscordActivity.Reaction][0, 1] = 6

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
int_mat[DiscordActivity.Reaction][0, 2] = 0
int_mat[DiscordActivity.Reaction][0, 3] = 0
int_mat[DiscordActivity.Reaction][0, 4] = 0
int_mat[DiscordActivity.Reaction][0, 5] = 0
int_mat[DiscordActivity.Reaction][0, 6] = 0

activity_dict = dict(zip(memberactivites, activity_dict))

print("all_consistent:", activity_dict["all_consistent"])
print("all_became_not_consistent:", activity_dict["all_became_not_consistent"])

assert activity_dict["all_became_not_consistent"] == {
"0": set(),
"1": set(),
"2": set(),
"3": set(),
"4": set(),
"5": set(),
"6": set(),
"7": set(),
"8": set(),
"9": set(),
"10": set(),
"11": set(),
"12": set(),
"13": set(),
"14": set(),
"15": set(),
"16": set(),
"17": set(),
"18": set(),
"19": set(),
"20": set(),
"21": set(),
"22": set(),
"23": set(),
"24": set(),
"25": set(),
"26": set(),
"27": set(),
"28": {"user0", "user1"},
"29": set(),
"30": set(),
"31": set(),
"32": set(),
"33": set(),
"34": set(),
}
Loading