From 46de41f5fd1523fe1084a8ed070f1bce674974b1 Mon Sep 17 00:00:00 2001 From: Mohammad Amin Date: Mon, 16 Oct 2023 09:42:50 +0330 Subject: [PATCH 01/14] feat: added inconsistent member computation to pipeline --- tc_core_analyzer_lib/assess_engagement.py | 8 +++ .../tests/unit/test_assess_inconsistent.py | 58 +++++++++++++++++++ .../utils/assessments/__init__.py | 1 + .../utils/assessments/assess_inconsistent.py | 39 +++++++++++++ 4 files changed, 106 insertions(+) create mode 100644 tc_core_analyzer_lib/tests/unit/test_assess_inconsistent.py create mode 100644 tc_core_analyzer_lib/utils/assessments/assess_inconsistent.py diff --git a/tc_core_analyzer_lib/assess_engagement.py b/tc_core_analyzer_lib/assess_engagement.py index 0dc09dd..468a96d 100644 --- a/tc_core_analyzer_lib/assess_engagement.py +++ b/tc_core_analyzer_lib/assess_engagement.py @@ -15,6 +15,7 @@ assess_remainder, assess_still_active, assess_vital, + assess_inconsistent, ) from .utils.compute_interaction_per_acc import thr_int @@ -74,6 +75,7 @@ def compute( all_lurker, all_about_to_disengage, all_disengaged_in_past, + all_inconsistent, ): """ Assess engagment levels for all active members in a time period @@ -233,6 +235,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 @@ -292,4 +299,5 @@ def compute( all_lurker, all_about_to_disengage, all_disengaged_in_past, + all_inconsistent, ) diff --git a/tc_core_analyzer_lib/tests/unit/test_assess_inconsistent.py b/tc_core_analyzer_lib/tests/unit/test_assess_inconsistent.py new file mode 100644 index 0000000..27a6704 --- /dev/null +++ b/tc_core_analyzer_lib/tests/unit/test_assess_inconsistent.py @@ -0,0 +1,58 @@ +import unittest + +from tc_core_analyzer_lib.utils.assessments.assess_inconsistent import ( + assess_inconsistent, +) + + +class TestAssessInconsistent(unittest.TestCase): + def test_inconsistent_members_empty_inputs(self): + all_active = {"0": set()} + all_paused = {"0": set()} + all_new_active = {"0": set()} + all_consistent = {"0": set()} + + all_inconsistent = assess_inconsistent( + all_active=all_active, + all_paused=all_paused, + all_new_active=all_new_active, + all_consistent=all_consistent, + w_i=0, + ) + + self.assertEqual(all_inconsistent, set()) + + def test_inconsistent_members_paused_members(self): + all_active = {"0": set(["User1", "User2"])} + all_paused = {"0": set(["User3", "User4"])} + all_new_active = {"0": set(["User1", "User2"])} + all_consistent = {"0": set()} + + all_inconsistent = assess_inconsistent( + all_active=all_active, + all_paused=all_paused, + all_new_active=all_new_active, + all_consistent=all_consistent, + w_i=0, + ) + + self.assertEqual(all_inconsistent, set(["User3", "User4"])) + + def test_inconsistent_members_active_members(self): + all_active = {"0": set(["User1", "User2"]), "1": set(["User1", "User2"])} + all_paused = {"0": set(["User3", "User4"]), "1": set()} + all_new_active = { + "0": set(["User1", "User2"]), + "1": set([]), + } + all_consistent = {"0": set(), "1": set()} + + all_inconsistent = assess_inconsistent( + all_active=all_active, + all_paused=all_paused, + all_new_active=all_new_active, + all_consistent=all_consistent, + w_i=1, + ) + + self.assertEqual(all_inconsistent, set(["User1", "User2"])) diff --git a/tc_core_analyzer_lib/utils/assessments/__init__.py b/tc_core_analyzer_lib/utils/assessments/__init__.py index b5ee417..5c95d6f 100644 --- a/tc_core_analyzer_lib/utils/assessments/__init__.py +++ b/tc_core_analyzer_lib/utils/assessments/__init__.py @@ -8,3 +8,4 @@ from .assess_remainder import assess_remainder from .assess_still_active import assess_still_active from .assess_vital import assess_vital +from .assess_inconsistent import assess_inconsistent diff --git a/tc_core_analyzer_lib/utils/assessments/assess_inconsistent.py b/tc_core_analyzer_lib/utils/assessments/assess_inconsistent.py new file mode 100644 index 0000000..92c846d --- /dev/null +++ b/tc_core_analyzer_lib/utils/assessments/assess_inconsistent.py @@ -0,0 +1,39 @@ +def assess_inconsistent( + all_active: dict[str, set[str]], + all_paused: dict[str, set[str]], + all_new_active: dict[str, set[str]], + all_consistent: dict[str, set[str]], + w_i: int, +) -> dict[str, set[str]]: + """ + assess inconsistently active members base on the given input sets + + Parameters + ------------ + all_active : dict[str, set[str]] + dictionary with keys w_i and values + containing a set of all account names that are active + all_paused : dict[str, set[str]] + dictionary with keys w_i and values + containing a set of all account names that are paused + all_new_active : dict[str, set[str]] + dictionary with keys w_i and values + containing a set of all account names that are active for first time + all_consistent : dict[str, set[str]] + dictionary with keys w_i and values + containing a set of all account names that are consistently active + w_i : int + index of sliding time window + + Returns + --------- + all_inconsistent : set[str] + containing a set of all account names that are inconsistently active + """ + all_inconsistent = ( + all_active[str(w_i)].union(all_paused[str(w_i)]) + - all_new_active[str(w_i)] + - all_consistent[str(w_i)] + ) + + return all_inconsistent From 6533be3f2d5e721270e81c99b8fc3b8b8f454528 Mon Sep 17 00:00:00 2001 From: Mohammad Amin Date: Mon, 16 Oct 2023 09:43:24 +0330 Subject: [PATCH 02/14] Update: tests updated with new inconsistent analysis! - We needed to feed the new inconsistent type in analysis pipeline. --- tc_core_analyzer_lib/tests/integration/test_active_members.py | 2 ++ .../tests/integration/test_all_active_fourteen_period.py | 1 + .../tests/integration/test_consistently_active.py | 1 + .../tests/integration/test_disengaged_members.py | 1 + .../integration/test_disengaged_were_consistently_active.py | 1 + .../tests/integration/test_disengaged_were_newly_active.py | 1 + .../tests/integration/test_disengaged_were_vital.py | 1 + .../integration/test_mention_active_members_from_int_matrix.py | 1 + .../tests/integration/test_newly_active_continuous_period.py | 1 + .../tests/integration/test_newly_active_discontinued_period.py | 1 + .../tests/integration/test_non_consistently_active.py | 1 + .../tests/integration/test_partially_consistently_active.py | 1 + tc_core_analyzer_lib/tests/integration/test_still_active.py | 1 + tc_core_analyzer_lib/tests/integration/test_vital.py | 1 + 14 files changed, 15 insertions(+) diff --git a/tc_core_analyzer_lib/tests/integration/test_active_members.py b/tc_core_analyzer_lib/tests/integration/test_active_members.py index 8000982..4828372 100644 --- a/tc_core_analyzer_lib/tests/integration/test_active_members.py +++ b/tc_core_analyzer_lib/tests/integration/test_active_members.py @@ -38,6 +38,7 @@ def test_no_active(): "all_lurker": {}, "all_about_to_disengage": {}, "all_disengaged_in_past": {}, + "all_inconsistent": {}, } WINDOW_D = 7 @@ -160,6 +161,7 @@ def test_single_active(): "all_lurker": {}, "all_about_to_disengage": {}, "all_disengaged_in_past": {}, + "all_inconsistent": {}, } # time window WINDOW_D = 7 diff --git a/tc_core_analyzer_lib/tests/integration/test_all_active_fourteen_period.py b/tc_core_analyzer_lib/tests/integration/test_all_active_fourteen_period.py index 4250b6d..9abb08a 100644 --- a/tc_core_analyzer_lib/tests/integration/test_all_active_fourteen_period.py +++ b/tc_core_analyzer_lib/tests/integration/test_all_active_fourteen_period.py @@ -72,6 +72,7 @@ def test_all_active_fourteen_period(): "all_lurker": {}, "all_about_to_disengage": {}, "all_disengaged_in_past": {}, + "all_inconsistent": {}, } WINDOW_D = 7 diff --git a/tc_core_analyzer_lib/tests/integration/test_consistently_active.py b/tc_core_analyzer_lib/tests/integration/test_consistently_active.py index 90e65fe..046a8c4 100644 --- a/tc_core_analyzer_lib/tests/integration/test_consistently_active.py +++ b/tc_core_analyzer_lib/tests/integration/test_consistently_active.py @@ -43,6 +43,7 @@ def test_two_consistently_active(): "all_lurker": {}, "all_about_to_disengage": {}, "all_disengaged_in_past": {}, + "all_inconsistent": {}, } memberactivities = activity_dict.keys() diff --git a/tc_core_analyzer_lib/tests/integration/test_disengaged_members.py b/tc_core_analyzer_lib/tests/integration/test_disengaged_members.py index d9f891d..c852989 100644 --- a/tc_core_analyzer_lib/tests/integration/test_disengaged_members.py +++ b/tc_core_analyzer_lib/tests/integration/test_disengaged_members.py @@ -40,6 +40,7 @@ def test_disengaged_members(): "all_lurker": {}, "all_about_to_disengage": {}, "all_disengaged_in_past": {}, + "all_inconsistent": {}, } memberactivities = activity_dict.keys() diff --git a/tc_core_analyzer_lib/tests/integration/test_disengaged_were_consistently_active.py b/tc_core_analyzer_lib/tests/integration/test_disengaged_were_consistently_active.py index face901..597e504 100644 --- a/tc_core_analyzer_lib/tests/integration/test_disengaged_were_consistently_active.py +++ b/tc_core_analyzer_lib/tests/integration/test_disengaged_were_consistently_active.py @@ -40,6 +40,7 @@ def test_disengaged_were_consistent(): "all_lurker": {}, "all_about_to_disengage": {}, "all_disengaged_in_past": {}, + "all_inconsistent": {}, } memberactivities = activity_dict.keys() diff --git a/tc_core_analyzer_lib/tests/integration/test_disengaged_were_newly_active.py b/tc_core_analyzer_lib/tests/integration/test_disengaged_were_newly_active.py index 39d042d..6c2c9c9 100644 --- a/tc_core_analyzer_lib/tests/integration/test_disengaged_were_newly_active.py +++ b/tc_core_analyzer_lib/tests/integration/test_disengaged_were_newly_active.py @@ -73,6 +73,7 @@ def test_disengaged_newly_active(): "all_lurker": {}, "all_about_to_disengage": {}, "all_disengaged_in_past": {}, + "all_inconsistent": {}, } memberactivities = activity_dict.keys() diff --git a/tc_core_analyzer_lib/tests/integration/test_disengaged_were_vital.py b/tc_core_analyzer_lib/tests/integration/test_disengaged_were_vital.py index b58ea13..2c3de1a 100644 --- a/tc_core_analyzer_lib/tests/integration/test_disengaged_were_vital.py +++ b/tc_core_analyzer_lib/tests/integration/test_disengaged_were_vital.py @@ -73,6 +73,7 @@ def test_disengaged_were_vital(): "all_lurker": {}, "all_about_to_disengage": {}, "all_disengaged_in_past": {}, + "all_inconsistent": {}, } memberactivities = activity_dict.keys() diff --git a/tc_core_analyzer_lib/tests/integration/test_mention_active_members_from_int_matrix.py b/tc_core_analyzer_lib/tests/integration/test_mention_active_members_from_int_matrix.py index 07f8f91..5467e98 100644 --- a/tc_core_analyzer_lib/tests/integration/test_mention_active_members_from_int_matrix.py +++ b/tc_core_analyzer_lib/tests/integration/test_mention_active_members_from_int_matrix.py @@ -78,6 +78,7 @@ def test_mention_active_members_from_int_matrix(): "all_lurker": {}, "all_about_to_disengage": {}, "all_disengaged_in_past": {}, + "all_inconsistent": {}, } memberactivities = activity_dict.keys() diff --git a/tc_core_analyzer_lib/tests/integration/test_newly_active_continuous_period.py b/tc_core_analyzer_lib/tests/integration/test_newly_active_continuous_period.py index 419df31..a02aa56 100644 --- a/tc_core_analyzer_lib/tests/integration/test_newly_active_continuous_period.py +++ b/tc_core_analyzer_lib/tests/integration/test_newly_active_continuous_period.py @@ -43,6 +43,7 @@ def test_newly_active_continuous_period(): "all_lurker": {}, "all_about_to_disengage": {}, "all_disengaged_in_past": {}, + "all_inconsistent": {}, } memberactivities = activity_dict.keys() diff --git a/tc_core_analyzer_lib/tests/integration/test_newly_active_discontinued_period.py b/tc_core_analyzer_lib/tests/integration/test_newly_active_discontinued_period.py index 604b9a7..c8cfd93 100644 --- a/tc_core_analyzer_lib/tests/integration/test_newly_active_discontinued_period.py +++ b/tc_core_analyzer_lib/tests/integration/test_newly_active_discontinued_period.py @@ -73,6 +73,7 @@ def test_newly_active_discontinued_period(): "all_lurker": {}, "all_about_to_disengage": {}, "all_disengaged_in_past": {}, + "all_inconsistent": {}, } memberactivities = activity_dict.keys() diff --git a/tc_core_analyzer_lib/tests/integration/test_non_consistently_active.py b/tc_core_analyzer_lib/tests/integration/test_non_consistently_active.py index 7b1f03a..896e5be 100644 --- a/tc_core_analyzer_lib/tests/integration/test_non_consistently_active.py +++ b/tc_core_analyzer_lib/tests/integration/test_non_consistently_active.py @@ -45,6 +45,7 @@ def test_two_consistently_active_non(): "all_lurker": {}, "all_about_to_disengage": {}, "all_disengaged_in_past": {}, + "all_inconsistent": {}, } memberactivities = activity_dict.keys() diff --git a/tc_core_analyzer_lib/tests/integration/test_partially_consistently_active.py b/tc_core_analyzer_lib/tests/integration/test_partially_consistently_active.py index 99a872c..28a0c00 100644 --- a/tc_core_analyzer_lib/tests/integration/test_partially_consistently_active.py +++ b/tc_core_analyzer_lib/tests/integration/test_partially_consistently_active.py @@ -43,6 +43,7 @@ def test_two_consistently_active_partially(): "all_lurker": {}, "all_about_to_disengage": {}, "all_disengaged_in_past": {}, + "all_inconsistent": {}, } memberactivities = activity_dict.keys() diff --git a/tc_core_analyzer_lib/tests/integration/test_still_active.py b/tc_core_analyzer_lib/tests/integration/test_still_active.py index 0d05e8d..39386fe 100644 --- a/tc_core_analyzer_lib/tests/integration/test_still_active.py +++ b/tc_core_analyzer_lib/tests/integration/test_still_active.py @@ -74,6 +74,7 @@ def test_still_active_members(): "all_lurker": {}, "all_about_to_disengage": {}, "all_disengaged_in_past": {}, + "all_inconsistent": {}, } memberactivities = activity_dict.keys() diff --git a/tc_core_analyzer_lib/tests/integration/test_vital.py b/tc_core_analyzer_lib/tests/integration/test_vital.py index fa00b94..f86bf77 100644 --- a/tc_core_analyzer_lib/tests/integration/test_vital.py +++ b/tc_core_analyzer_lib/tests/integration/test_vital.py @@ -74,6 +74,7 @@ def test_one_vital(): "all_lurker": {}, "all_about_to_disengage": {}, "all_disengaged_in_past": {}, + "all_inconsistent": {}, } memberactivites = activity_dict.keys() From 87ab264d43fe51421dd580ee3d1e1392d01f48e9 Mon Sep 17 00:00:00 2001 From: Mohammad Amin Date: Mon, 16 Oct 2023 09:51:32 +0330 Subject: [PATCH 03/14] fix: linter issues based on superlinter rules! --- tc_core_analyzer_lib/utils/assessments/__init__.py | 2 +- tc_core_analyzer_lib/utils/assessments/assess_inconsistent.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tc_core_analyzer_lib/utils/assessments/__init__.py b/tc_core_analyzer_lib/utils/assessments/__init__.py index 5c95d6f..8e7c7e7 100644 --- a/tc_core_analyzer_lib/utils/assessments/__init__.py +++ b/tc_core_analyzer_lib/utils/assessments/__init__.py @@ -3,9 +3,9 @@ from .assess_connected import assess_connected from .assess_consistent import assess_consistent from .assess_dropped import assess_dropped +from .assess_inconsistent import assess_inconsistent from .assess_lurker import assess_lurker from .assess_overlap import assess_overlap from .assess_remainder import assess_remainder from .assess_still_active import assess_still_active from .assess_vital import assess_vital -from .assess_inconsistent import assess_inconsistent diff --git a/tc_core_analyzer_lib/utils/assessments/assess_inconsistent.py b/tc_core_analyzer_lib/utils/assessments/assess_inconsistent.py index 92c846d..a1f953e 100644 --- a/tc_core_analyzer_lib/utils/assessments/assess_inconsistent.py +++ b/tc_core_analyzer_lib/utils/assessments/assess_inconsistent.py @@ -4,7 +4,7 @@ def assess_inconsistent( all_new_active: dict[str, set[str]], all_consistent: dict[str, set[str]], w_i: int, -) -> dict[str, set[str]]: +) -> set[str]: """ assess inconsistently active members base on the given input sets From 02f21d05f5f8addc901f935aa1efc05219585e99 Mon Sep 17 00:00:00 2001 From: Mohammad Amin Date: Mon, 16 Oct 2023 10:08:28 +0330 Subject: [PATCH 04/14] update: lib version increase! --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 3520d5a..b934283 100644 --- a/setup.py +++ b/setup.py @@ -6,7 +6,7 @@ setup( name="tc-core-analyzer-lib", - version="1.0.2", + version="1.1.0", author="Mohammad Amin Dadgar, TogetherCrew", maintainer="Mohammad Amin Dadgar", maintainer_email="dadgaramin96@gmail.com", From a23a6986c5b55087651521cce1361845c31a28e6 Mon Sep 17 00:00:00 2001 From: Mohammad Amin Date: Mon, 16 Oct 2023 16:05:09 +0330 Subject: [PATCH 05/14] feat: added 4 more activity types! - all_new_consistent - all_new_vital - all_became_inconsistent - all_became_unvital --- tc_core_analyzer_lib/assess_engagement.py | 28 +++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/tc_core_analyzer_lib/assess_engagement.py b/tc_core_analyzer_lib/assess_engagement.py index 468a96d..7e46c35 100644 --- a/tc_core_analyzer_lib/assess_engagement.py +++ b/tc_core_analyzer_lib/assess_engagement.py @@ -76,6 +76,10 @@ def compute( all_about_to_disengage, all_disengaged_in_past, all_inconsistent, + all_new_consistent, + all_new_vital, + all_became_inconsistent, + all_became_unvital, ): """ Assess engagment levels for all active members in a time period @@ -277,6 +281,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_inconsistent[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_inconsistent[str(w_i)] = set() + all_became_unvital[str(w_i)] = set() + return ( graph, all_joined, @@ -300,4 +324,8 @@ def compute( all_about_to_disengage, all_disengaged_in_past, all_inconsistent, + all_new_consistent, + all_new_vital, + all_became_inconsistent, + all_became_unvital, ) From 3b28ea5b613113b498d3f6a113bd09428ba13415 Mon Sep 17 00:00:00 2001 From: Mohammad Amin Date: Mon, 16 Oct 2023 16:16:44 +0330 Subject: [PATCH 06/14] fix: updated tests for the 4 new activities! --- .../tests/integration/test_active_members.py | 8 ++++++++ .../tests/integration/test_all_active_fourteen_period.py | 4 ++++ .../tests/integration/test_consistently_active.py | 4 ++++ .../tests/integration/test_disengaged_members.py | 4 ++++ .../test_disengaged_were_consistently_active.py | 4 ++++ .../integration/test_disengaged_were_newly_active.py | 4 ++++ .../tests/integration/test_disengaged_were_vital.py | 4 ++++ .../test_mention_active_members_from_int_matrix.py | 4 ++++ .../integration/test_newly_active_continuous_period.py | 4 ++++ .../integration/test_newly_active_discontinued_period.py | 5 +++++ .../tests/integration/test_non_consistently_active.py | 5 +++++ .../integration/test_partially_consistently_active.py | 5 +++++ .../tests/integration/test_still_active.py | 5 +++++ tc_core_analyzer_lib/tests/integration/test_vital.py | 5 +++++ 14 files changed, 65 insertions(+) diff --git a/tc_core_analyzer_lib/tests/integration/test_active_members.py b/tc_core_analyzer_lib/tests/integration/test_active_members.py index 4828372..88b5ac2 100644 --- a/tc_core_analyzer_lib/tests/integration/test_active_members.py +++ b/tc_core_analyzer_lib/tests/integration/test_active_members.py @@ -39,6 +39,10 @@ def test_no_active(): "all_about_to_disengage": {}, "all_disengaged_in_past": {}, "all_inconsistent": {}, + "all_new_consistent": {}, + "all_new_vital": {}, + "all_became_inconsistent": {}, + "all_became_unvital": {}, } WINDOW_D = 7 @@ -162,6 +166,10 @@ def test_single_active(): "all_about_to_disengage": {}, "all_disengaged_in_past": {}, "all_inconsistent": {}, + "all_new_consistent": {}, + "all_new_vital": {}, + "all_became_inconsistent": {}, + "all_became_unvital": {}, } # time window WINDOW_D = 7 diff --git a/tc_core_analyzer_lib/tests/integration/test_all_active_fourteen_period.py b/tc_core_analyzer_lib/tests/integration/test_all_active_fourteen_period.py index 9abb08a..4a0f727 100644 --- a/tc_core_analyzer_lib/tests/integration/test_all_active_fourteen_period.py +++ b/tc_core_analyzer_lib/tests/integration/test_all_active_fourteen_period.py @@ -73,6 +73,10 @@ def test_all_active_fourteen_period(): "all_about_to_disengage": {}, "all_disengaged_in_past": {}, "all_inconsistent": {}, + "all_new_consistent": {}, + "all_new_vital": {}, + "all_became_inconsistent": {}, + "all_became_unvital": {}, } WINDOW_D = 7 diff --git a/tc_core_analyzer_lib/tests/integration/test_consistently_active.py b/tc_core_analyzer_lib/tests/integration/test_consistently_active.py index 046a8c4..0376d51 100644 --- a/tc_core_analyzer_lib/tests/integration/test_consistently_active.py +++ b/tc_core_analyzer_lib/tests/integration/test_consistently_active.py @@ -44,6 +44,10 @@ def test_two_consistently_active(): "all_about_to_disengage": {}, "all_disengaged_in_past": {}, "all_inconsistent": {}, + "all_new_consistent": {}, + "all_new_vital": {}, + "all_became_inconsistent": {}, + "all_became_unvital": {}, } memberactivities = activity_dict.keys() diff --git a/tc_core_analyzer_lib/tests/integration/test_disengaged_members.py b/tc_core_analyzer_lib/tests/integration/test_disengaged_members.py index c852989..4019e91 100644 --- a/tc_core_analyzer_lib/tests/integration/test_disengaged_members.py +++ b/tc_core_analyzer_lib/tests/integration/test_disengaged_members.py @@ -41,6 +41,10 @@ def test_disengaged_members(): "all_about_to_disengage": {}, "all_disengaged_in_past": {}, "all_inconsistent": {}, + "all_new_consistent": {}, + "all_new_vital": {}, + "all_became_inconsistent": {}, + "all_became_unvital": {}, } memberactivities = activity_dict.keys() diff --git a/tc_core_analyzer_lib/tests/integration/test_disengaged_were_consistently_active.py b/tc_core_analyzer_lib/tests/integration/test_disengaged_were_consistently_active.py index 597e504..15be31b 100644 --- a/tc_core_analyzer_lib/tests/integration/test_disengaged_were_consistently_active.py +++ b/tc_core_analyzer_lib/tests/integration/test_disengaged_were_consistently_active.py @@ -41,6 +41,10 @@ def test_disengaged_were_consistent(): "all_about_to_disengage": {}, "all_disengaged_in_past": {}, "all_inconsistent": {}, + "all_new_consistent": {}, + "all_new_vital": {}, + "all_became_inconsistent": {}, + "all_became_unvital": {}, } memberactivities = activity_dict.keys() diff --git a/tc_core_analyzer_lib/tests/integration/test_disengaged_were_newly_active.py b/tc_core_analyzer_lib/tests/integration/test_disengaged_were_newly_active.py index 6c2c9c9..ee5fad1 100644 --- a/tc_core_analyzer_lib/tests/integration/test_disengaged_were_newly_active.py +++ b/tc_core_analyzer_lib/tests/integration/test_disengaged_were_newly_active.py @@ -74,6 +74,10 @@ def test_disengaged_newly_active(): "all_about_to_disengage": {}, "all_disengaged_in_past": {}, "all_inconsistent": {}, + "all_new_consistent": {}, + "all_new_vital": {}, + "all_became_inconsistent": {}, + "all_became_unvital": {}, } memberactivities = activity_dict.keys() diff --git a/tc_core_analyzer_lib/tests/integration/test_disengaged_were_vital.py b/tc_core_analyzer_lib/tests/integration/test_disengaged_were_vital.py index 2c3de1a..477b4dc 100644 --- a/tc_core_analyzer_lib/tests/integration/test_disengaged_were_vital.py +++ b/tc_core_analyzer_lib/tests/integration/test_disengaged_were_vital.py @@ -74,6 +74,10 @@ def test_disengaged_were_vital(): "all_about_to_disengage": {}, "all_disengaged_in_past": {}, "all_inconsistent": {}, + "all_new_consistent": {}, + "all_new_vital": {}, + "all_became_inconsistent": {}, + "all_became_unvital": {}, } memberactivities = activity_dict.keys() diff --git a/tc_core_analyzer_lib/tests/integration/test_mention_active_members_from_int_matrix.py b/tc_core_analyzer_lib/tests/integration/test_mention_active_members_from_int_matrix.py index 5467e98..889c3e8 100644 --- a/tc_core_analyzer_lib/tests/integration/test_mention_active_members_from_int_matrix.py +++ b/tc_core_analyzer_lib/tests/integration/test_mention_active_members_from_int_matrix.py @@ -79,6 +79,10 @@ def test_mention_active_members_from_int_matrix(): "all_about_to_disengage": {}, "all_disengaged_in_past": {}, "all_inconsistent": {}, + "all_new_consistent": {}, + "all_new_vital": {}, + "all_became_inconsistent": {}, + "all_became_unvital": {}, } memberactivities = activity_dict.keys() diff --git a/tc_core_analyzer_lib/tests/integration/test_newly_active_continuous_period.py b/tc_core_analyzer_lib/tests/integration/test_newly_active_continuous_period.py index a02aa56..c2c9c26 100644 --- a/tc_core_analyzer_lib/tests/integration/test_newly_active_continuous_period.py +++ b/tc_core_analyzer_lib/tests/integration/test_newly_active_continuous_period.py @@ -44,6 +44,10 @@ def test_newly_active_continuous_period(): "all_about_to_disengage": {}, "all_disengaged_in_past": {}, "all_inconsistent": {}, + "all_new_consistent": {}, + "all_new_vital": {}, + "all_became_inconsistent": {}, + "all_became_unvital": {}, } memberactivities = activity_dict.keys() diff --git a/tc_core_analyzer_lib/tests/integration/test_newly_active_discontinued_period.py b/tc_core_analyzer_lib/tests/integration/test_newly_active_discontinued_period.py index c8cfd93..13f1951 100644 --- a/tc_core_analyzer_lib/tests/integration/test_newly_active_discontinued_period.py +++ b/tc_core_analyzer_lib/tests/integration/test_newly_active_discontinued_period.py @@ -74,6 +74,11 @@ def test_newly_active_discontinued_period(): "all_about_to_disengage": {}, "all_disengaged_in_past": {}, "all_inconsistent": {}, + "all_inconsistent": {}, + "all_new_consistent": {}, + "all_new_vital": {}, + "all_became_inconsistent": {}, + "all_became_unvital": {}, } memberactivities = activity_dict.keys() diff --git a/tc_core_analyzer_lib/tests/integration/test_non_consistently_active.py b/tc_core_analyzer_lib/tests/integration/test_non_consistently_active.py index 896e5be..b3c4a12 100644 --- a/tc_core_analyzer_lib/tests/integration/test_non_consistently_active.py +++ b/tc_core_analyzer_lib/tests/integration/test_non_consistently_active.py @@ -46,6 +46,11 @@ def test_two_consistently_active_non(): "all_about_to_disengage": {}, "all_disengaged_in_past": {}, "all_inconsistent": {}, + "all_inconsistent": {}, + "all_new_consistent": {}, + "all_new_vital": {}, + "all_became_inconsistent": {}, + "all_became_unvital": {}, } memberactivities = activity_dict.keys() diff --git a/tc_core_analyzer_lib/tests/integration/test_partially_consistently_active.py b/tc_core_analyzer_lib/tests/integration/test_partially_consistently_active.py index 28a0c00..a8879f0 100644 --- a/tc_core_analyzer_lib/tests/integration/test_partially_consistently_active.py +++ b/tc_core_analyzer_lib/tests/integration/test_partially_consistently_active.py @@ -44,6 +44,11 @@ def test_two_consistently_active_partially(): "all_about_to_disengage": {}, "all_disengaged_in_past": {}, "all_inconsistent": {}, + "all_inconsistent": {}, + "all_new_consistent": {}, + "all_new_vital": {}, + "all_became_inconsistent": {}, + "all_became_unvital": {}, } memberactivities = activity_dict.keys() diff --git a/tc_core_analyzer_lib/tests/integration/test_still_active.py b/tc_core_analyzer_lib/tests/integration/test_still_active.py index 39386fe..2caecd7 100644 --- a/tc_core_analyzer_lib/tests/integration/test_still_active.py +++ b/tc_core_analyzer_lib/tests/integration/test_still_active.py @@ -75,6 +75,11 @@ def test_still_active_members(): "all_about_to_disengage": {}, "all_disengaged_in_past": {}, "all_inconsistent": {}, + "all_inconsistent": {}, + "all_new_consistent": {}, + "all_new_vital": {}, + "all_became_inconsistent": {}, + "all_became_unvital": {}, } memberactivities = activity_dict.keys() diff --git a/tc_core_analyzer_lib/tests/integration/test_vital.py b/tc_core_analyzer_lib/tests/integration/test_vital.py index f86bf77..6036781 100644 --- a/tc_core_analyzer_lib/tests/integration/test_vital.py +++ b/tc_core_analyzer_lib/tests/integration/test_vital.py @@ -75,6 +75,11 @@ def test_one_vital(): "all_about_to_disengage": {}, "all_disengaged_in_past": {}, "all_inconsistent": {}, + "all_inconsistent": {}, + "all_new_consistent": {}, + "all_new_vital": {}, + "all_became_inconsistent": {}, + "all_became_unvital": {}, } memberactivites = activity_dict.keys() From 8e6ca08c5c80cb90556b3ebf1452e7cf03ea59e5 Mon Sep 17 00:00:00 2001 From: Mohammad Amin Date: Mon, 16 Oct 2023 16:25:58 +0330 Subject: [PATCH 07/14] fix: removed reapeated values reported by linters! --- .../tests/integration/test_newly_active_discontinued_period.py | 1 - .../tests/integration/test_non_consistently_active.py | 1 - .../tests/integration/test_partially_consistently_active.py | 1 - tc_core_analyzer_lib/tests/integration/test_still_active.py | 1 - tc_core_analyzer_lib/tests/integration/test_vital.py | 1 - 5 files changed, 5 deletions(-) diff --git a/tc_core_analyzer_lib/tests/integration/test_newly_active_discontinued_period.py b/tc_core_analyzer_lib/tests/integration/test_newly_active_discontinued_period.py index 13f1951..0f95cf9 100644 --- a/tc_core_analyzer_lib/tests/integration/test_newly_active_discontinued_period.py +++ b/tc_core_analyzer_lib/tests/integration/test_newly_active_discontinued_period.py @@ -74,7 +74,6 @@ def test_newly_active_discontinued_period(): "all_about_to_disengage": {}, "all_disengaged_in_past": {}, "all_inconsistent": {}, - "all_inconsistent": {}, "all_new_consistent": {}, "all_new_vital": {}, "all_became_inconsistent": {}, diff --git a/tc_core_analyzer_lib/tests/integration/test_non_consistently_active.py b/tc_core_analyzer_lib/tests/integration/test_non_consistently_active.py index b3c4a12..a8fc52f 100644 --- a/tc_core_analyzer_lib/tests/integration/test_non_consistently_active.py +++ b/tc_core_analyzer_lib/tests/integration/test_non_consistently_active.py @@ -46,7 +46,6 @@ def test_two_consistently_active_non(): "all_about_to_disengage": {}, "all_disengaged_in_past": {}, "all_inconsistent": {}, - "all_inconsistent": {}, "all_new_consistent": {}, "all_new_vital": {}, "all_became_inconsistent": {}, diff --git a/tc_core_analyzer_lib/tests/integration/test_partially_consistently_active.py b/tc_core_analyzer_lib/tests/integration/test_partially_consistently_active.py index a8879f0..eda1e56 100644 --- a/tc_core_analyzer_lib/tests/integration/test_partially_consistently_active.py +++ b/tc_core_analyzer_lib/tests/integration/test_partially_consistently_active.py @@ -44,7 +44,6 @@ def test_two_consistently_active_partially(): "all_about_to_disengage": {}, "all_disengaged_in_past": {}, "all_inconsistent": {}, - "all_inconsistent": {}, "all_new_consistent": {}, "all_new_vital": {}, "all_became_inconsistent": {}, diff --git a/tc_core_analyzer_lib/tests/integration/test_still_active.py b/tc_core_analyzer_lib/tests/integration/test_still_active.py index 2caecd7..5d41967 100644 --- a/tc_core_analyzer_lib/tests/integration/test_still_active.py +++ b/tc_core_analyzer_lib/tests/integration/test_still_active.py @@ -75,7 +75,6 @@ def test_still_active_members(): "all_about_to_disengage": {}, "all_disengaged_in_past": {}, "all_inconsistent": {}, - "all_inconsistent": {}, "all_new_consistent": {}, "all_new_vital": {}, "all_became_inconsistent": {}, diff --git a/tc_core_analyzer_lib/tests/integration/test_vital.py b/tc_core_analyzer_lib/tests/integration/test_vital.py index 6036781..f0336b1 100644 --- a/tc_core_analyzer_lib/tests/integration/test_vital.py +++ b/tc_core_analyzer_lib/tests/integration/test_vital.py @@ -75,7 +75,6 @@ def test_one_vital(): "all_about_to_disengage": {}, "all_disengaged_in_past": {}, "all_inconsistent": {}, - "all_inconsistent": {}, "all_new_consistent": {}, "all_new_vital": {}, "all_became_inconsistent": {}, From 39254e1c9af182984893b91e03c7e42a134b60fb Mon Sep 17 00:00:00 2001 From: Mohammad Amin Date: Tue, 17 Oct 2023 09:54:33 +0330 Subject: [PATCH 08/14] improv: Added test for all_inconsistent category! --- .../integration/test_inconsistently_active.py | 158 ++++++++++++++++++ 1 file changed, 158 insertions(+) create mode 100644 tc_core_analyzer_lib/tests/integration/test_inconsistently_active.py diff --git a/tc_core_analyzer_lib/tests/integration/test_inconsistently_active.py b/tc_core_analyzer_lib/tests/integration/test_inconsistently_active.py new file mode 100644 index 0000000..fc526eb --- /dev/null +++ b/tc_core_analyzer_lib/tests/integration/test_inconsistently_active.py @@ -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(), + } From a02de735edf45df2f335e070e29ab6182f17efb7 Mon Sep 17 00:00:00 2001 From: Mohammad Amin Date: Tue, 17 Oct 2023 09:55:01 +0330 Subject: [PATCH 09/14] update: all_became_inconsistent to all_became_not_consistent! --- tc_core_analyzer_lib/assess_engagement.py | 8 ++++---- .../tests/integration/test_active_members.py | 4 ++-- .../tests/integration/test_all_active_fourteen_period.py | 2 +- .../tests/integration/test_consistently_active.py | 2 +- .../tests/integration/test_disengaged_members.py | 2 +- .../test_disengaged_were_consistently_active.py | 2 +- .../integration/test_disengaged_were_newly_active.py | 2 +- .../tests/integration/test_disengaged_were_vital.py | 2 +- .../test_mention_active_members_from_int_matrix.py | 2 +- .../integration/test_newly_active_continuous_period.py | 2 +- .../integration/test_newly_active_discontinued_period.py | 2 +- .../tests/integration/test_non_consistently_active.py | 2 +- .../integration/test_partially_consistently_active.py | 2 +- .../tests/integration/test_still_active.py | 2 +- tc_core_analyzer_lib/tests/integration/test_vital.py | 2 +- 15 files changed, 19 insertions(+), 19 deletions(-) diff --git a/tc_core_analyzer_lib/assess_engagement.py b/tc_core_analyzer_lib/assess_engagement.py index 7e46c35..08fa421 100644 --- a/tc_core_analyzer_lib/assess_engagement.py +++ b/tc_core_analyzer_lib/assess_engagement.py @@ -78,7 +78,7 @@ def compute( all_inconsistent, all_new_consistent, all_new_vital, - all_became_inconsistent, + all_became_not_consistent, all_became_unvital, ): """ @@ -289,7 +289,7 @@ def compute( all_new_vital[str(w_i)] = ( all_vital[str(w_i)] - all_vital[str(w_i - WINDOW_D)] ) - all_became_inconsistent[str(w_i)] = ( + 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)] = ( @@ -298,7 +298,7 @@ def compute( else: all_new_consistent[str(w_i)] = set() all_new_vital[str(w_i)] = set() - all_became_inconsistent[str(w_i)] = set() + all_became_not_consistent[str(w_i)] = set() all_became_unvital[str(w_i)] = set() return ( @@ -326,6 +326,6 @@ def compute( all_inconsistent, all_new_consistent, all_new_vital, - all_became_inconsistent, + all_became_not_consistent, all_became_unvital, ) diff --git a/tc_core_analyzer_lib/tests/integration/test_active_members.py b/tc_core_analyzer_lib/tests/integration/test_active_members.py index 88b5ac2..c9b9837 100644 --- a/tc_core_analyzer_lib/tests/integration/test_active_members.py +++ b/tc_core_analyzer_lib/tests/integration/test_active_members.py @@ -41,7 +41,7 @@ def test_no_active(): "all_inconsistent": {}, "all_new_consistent": {}, "all_new_vital": {}, - "all_became_inconsistent": {}, + "all_became_not_consistent": {}, "all_became_unvital": {}, } @@ -168,7 +168,7 @@ def test_single_active(): "all_inconsistent": {}, "all_new_consistent": {}, "all_new_vital": {}, - "all_became_inconsistent": {}, + "all_became_not_consistent": {}, "all_became_unvital": {}, } # time window diff --git a/tc_core_analyzer_lib/tests/integration/test_all_active_fourteen_period.py b/tc_core_analyzer_lib/tests/integration/test_all_active_fourteen_period.py index 4a0f727..a67be1a 100644 --- a/tc_core_analyzer_lib/tests/integration/test_all_active_fourteen_period.py +++ b/tc_core_analyzer_lib/tests/integration/test_all_active_fourteen_period.py @@ -75,7 +75,7 @@ def test_all_active_fourteen_period(): "all_inconsistent": {}, "all_new_consistent": {}, "all_new_vital": {}, - "all_became_inconsistent": {}, + "all_became_not_consistent": {}, "all_became_unvital": {}, } diff --git a/tc_core_analyzer_lib/tests/integration/test_consistently_active.py b/tc_core_analyzer_lib/tests/integration/test_consistently_active.py index 0376d51..c5878c0 100644 --- a/tc_core_analyzer_lib/tests/integration/test_consistently_active.py +++ b/tc_core_analyzer_lib/tests/integration/test_consistently_active.py @@ -46,7 +46,7 @@ def test_two_consistently_active(): "all_inconsistent": {}, "all_new_consistent": {}, "all_new_vital": {}, - "all_became_inconsistent": {}, + "all_became_not_consistent": {}, "all_became_unvital": {}, } memberactivities = activity_dict.keys() diff --git a/tc_core_analyzer_lib/tests/integration/test_disengaged_members.py b/tc_core_analyzer_lib/tests/integration/test_disengaged_members.py index 4019e91..72312f4 100644 --- a/tc_core_analyzer_lib/tests/integration/test_disengaged_members.py +++ b/tc_core_analyzer_lib/tests/integration/test_disengaged_members.py @@ -43,7 +43,7 @@ def test_disengaged_members(): "all_inconsistent": {}, "all_new_consistent": {}, "all_new_vital": {}, - "all_became_inconsistent": {}, + "all_became_not_consistent": {}, "all_became_unvital": {}, } memberactivities = activity_dict.keys() diff --git a/tc_core_analyzer_lib/tests/integration/test_disengaged_were_consistently_active.py b/tc_core_analyzer_lib/tests/integration/test_disengaged_were_consistently_active.py index 15be31b..8cc444d 100644 --- a/tc_core_analyzer_lib/tests/integration/test_disengaged_were_consistently_active.py +++ b/tc_core_analyzer_lib/tests/integration/test_disengaged_were_consistently_active.py @@ -43,7 +43,7 @@ def test_disengaged_were_consistent(): "all_inconsistent": {}, "all_new_consistent": {}, "all_new_vital": {}, - "all_became_inconsistent": {}, + "all_became_not_consistent": {}, "all_became_unvital": {}, } memberactivities = activity_dict.keys() diff --git a/tc_core_analyzer_lib/tests/integration/test_disengaged_were_newly_active.py b/tc_core_analyzer_lib/tests/integration/test_disengaged_were_newly_active.py index ee5fad1..7e3afa7 100644 --- a/tc_core_analyzer_lib/tests/integration/test_disengaged_were_newly_active.py +++ b/tc_core_analyzer_lib/tests/integration/test_disengaged_were_newly_active.py @@ -76,7 +76,7 @@ def test_disengaged_newly_active(): "all_inconsistent": {}, "all_new_consistent": {}, "all_new_vital": {}, - "all_became_inconsistent": {}, + "all_became_not_consistent": {}, "all_became_unvital": {}, } memberactivities = activity_dict.keys() diff --git a/tc_core_analyzer_lib/tests/integration/test_disengaged_were_vital.py b/tc_core_analyzer_lib/tests/integration/test_disengaged_were_vital.py index 477b4dc..acfc456 100644 --- a/tc_core_analyzer_lib/tests/integration/test_disengaged_were_vital.py +++ b/tc_core_analyzer_lib/tests/integration/test_disengaged_were_vital.py @@ -76,7 +76,7 @@ def test_disengaged_were_vital(): "all_inconsistent": {}, "all_new_consistent": {}, "all_new_vital": {}, - "all_became_inconsistent": {}, + "all_became_not_consistent": {}, "all_became_unvital": {}, } memberactivities = activity_dict.keys() diff --git a/tc_core_analyzer_lib/tests/integration/test_mention_active_members_from_int_matrix.py b/tc_core_analyzer_lib/tests/integration/test_mention_active_members_from_int_matrix.py index 889c3e8..17127dd 100644 --- a/tc_core_analyzer_lib/tests/integration/test_mention_active_members_from_int_matrix.py +++ b/tc_core_analyzer_lib/tests/integration/test_mention_active_members_from_int_matrix.py @@ -81,7 +81,7 @@ def test_mention_active_members_from_int_matrix(): "all_inconsistent": {}, "all_new_consistent": {}, "all_new_vital": {}, - "all_became_inconsistent": {}, + "all_became_not_consistent": {}, "all_became_unvital": {}, } memberactivities = activity_dict.keys() diff --git a/tc_core_analyzer_lib/tests/integration/test_newly_active_continuous_period.py b/tc_core_analyzer_lib/tests/integration/test_newly_active_continuous_period.py index c2c9c26..35d0d94 100644 --- a/tc_core_analyzer_lib/tests/integration/test_newly_active_continuous_period.py +++ b/tc_core_analyzer_lib/tests/integration/test_newly_active_continuous_period.py @@ -46,7 +46,7 @@ def test_newly_active_continuous_period(): "all_inconsistent": {}, "all_new_consistent": {}, "all_new_vital": {}, - "all_became_inconsistent": {}, + "all_became_not_consistent": {}, "all_became_unvital": {}, } memberactivities = activity_dict.keys() diff --git a/tc_core_analyzer_lib/tests/integration/test_newly_active_discontinued_period.py b/tc_core_analyzer_lib/tests/integration/test_newly_active_discontinued_period.py index 0f95cf9..f113d23 100644 --- a/tc_core_analyzer_lib/tests/integration/test_newly_active_discontinued_period.py +++ b/tc_core_analyzer_lib/tests/integration/test_newly_active_discontinued_period.py @@ -76,7 +76,7 @@ def test_newly_active_discontinued_period(): "all_inconsistent": {}, "all_new_consistent": {}, "all_new_vital": {}, - "all_became_inconsistent": {}, + "all_became_not_consistent": {}, "all_became_unvital": {}, } memberactivities = activity_dict.keys() diff --git a/tc_core_analyzer_lib/tests/integration/test_non_consistently_active.py b/tc_core_analyzer_lib/tests/integration/test_non_consistently_active.py index a8fc52f..81061d9 100644 --- a/tc_core_analyzer_lib/tests/integration/test_non_consistently_active.py +++ b/tc_core_analyzer_lib/tests/integration/test_non_consistently_active.py @@ -48,7 +48,7 @@ def test_two_consistently_active_non(): "all_inconsistent": {}, "all_new_consistent": {}, "all_new_vital": {}, - "all_became_inconsistent": {}, + "all_became_not_consistent": {}, "all_became_unvital": {}, } memberactivities = activity_dict.keys() diff --git a/tc_core_analyzer_lib/tests/integration/test_partially_consistently_active.py b/tc_core_analyzer_lib/tests/integration/test_partially_consistently_active.py index eda1e56..fb0404d 100644 --- a/tc_core_analyzer_lib/tests/integration/test_partially_consistently_active.py +++ b/tc_core_analyzer_lib/tests/integration/test_partially_consistently_active.py @@ -46,7 +46,7 @@ def test_two_consistently_active_partially(): "all_inconsistent": {}, "all_new_consistent": {}, "all_new_vital": {}, - "all_became_inconsistent": {}, + "all_became_not_consistent": {}, "all_became_unvital": {}, } memberactivities = activity_dict.keys() diff --git a/tc_core_analyzer_lib/tests/integration/test_still_active.py b/tc_core_analyzer_lib/tests/integration/test_still_active.py index 5d41967..c10ebfc 100644 --- a/tc_core_analyzer_lib/tests/integration/test_still_active.py +++ b/tc_core_analyzer_lib/tests/integration/test_still_active.py @@ -77,7 +77,7 @@ def test_still_active_members(): "all_inconsistent": {}, "all_new_consistent": {}, "all_new_vital": {}, - "all_became_inconsistent": {}, + "all_became_not_consistent": {}, "all_became_unvital": {}, } memberactivities = activity_dict.keys() diff --git a/tc_core_analyzer_lib/tests/integration/test_vital.py b/tc_core_analyzer_lib/tests/integration/test_vital.py index f0336b1..d70d36a 100644 --- a/tc_core_analyzer_lib/tests/integration/test_vital.py +++ b/tc_core_analyzer_lib/tests/integration/test_vital.py @@ -77,7 +77,7 @@ def test_one_vital(): "all_inconsistent": {}, "all_new_consistent": {}, "all_new_vital": {}, - "all_became_inconsistent": {}, + "all_became_not_consistent": {}, "all_became_unvital": {}, } memberactivites = activity_dict.keys() From ccc19f21766469597113b7cd0d3f980677d88bd0 Mon Sep 17 00:00:00 2001 From: Mohammad Amin Date: Tue, 17 Oct 2023 10:59:36 +0330 Subject: [PATCH 10/14] improv: added tests for the other 4 categories! - all_new_consistent - all_new_vital - all_became_not_consistent - all_became_unvital also we fixed the linter issues related to test_inconsistently_active.py --- .../test_all_became_not_consistent.py | 165 +++++++++++++++++ .../integration/test_all_became_unvital.py | 171 ++++++++++++++++++ .../integration/test_all_new_consistent.py | 156 ++++++++++++++++ .../tests/integration/test_all_new_vital.py | 164 +++++++++++++++++ .../integration/test_inconsistently_active.py | 4 +- 5 files changed, 657 insertions(+), 3 deletions(-) create mode 100644 tc_core_analyzer_lib/tests/integration/test_all_became_not_consistent.py create mode 100644 tc_core_analyzer_lib/tests/integration/test_all_became_unvital.py create mode 100644 tc_core_analyzer_lib/tests/integration/test_all_new_consistent.py create mode 100644 tc_core_analyzer_lib/tests/integration/test_all_new_vital.py diff --git a/tc_core_analyzer_lib/tests/integration/test_all_became_not_consistent.py b/tc_core_analyzer_lib/tests/integration/test_all_became_not_consistent.py new file mode 100644 index 0000000..55b3978 --- /dev/null +++ b/tc_core_analyzer_lib/tests/integration/test_all_became_not_consistent.py @@ -0,0 +1,165 @@ +# 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 + + 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, + ] + + 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(), + } diff --git a/tc_core_analyzer_lib/tests/integration/test_all_became_unvital.py b/tc_core_analyzer_lib/tests/integration/test_all_became_unvital.py new file mode 100644 index 0000000..e917bca --- /dev/null +++ b/tc_core_analyzer_lib/tests/integration/test_all_became_unvital.py @@ -0,0 +1,171 @@ +# 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_all_became_unvital(): + acc_names = [] + acc_count = 10 + + 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, + ] + + 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)), + } + # `user_0` intracting with `user_1`, `user_2`, `user_3`, `user_4`, `user_5` + int_mat[DiscordActivity.Reaction][0, 1] = 6 + int_mat[DiscordActivity.Reaction][0, 2] = 6 + int_mat[DiscordActivity.Reaction][0, 3] = 6 + int_mat[DiscordActivity.Reaction][0, 4] = 6 + int_mat[DiscordActivity.Reaction][0, 5] = 6 + int_mat[DiscordActivity.Reaction][0, 6] = 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", "user2", "user3", "user4", "user5", "user6"}, + "29": set(), + "30": set(), + "31": set(), + "32": set(), + "33": set(), + "34": set(), + } diff --git a/tc_core_analyzer_lib/tests/integration/test_all_new_consistent.py b/tc_core_analyzer_lib/tests/integration/test_all_new_consistent.py new file mode 100644 index 0000000..98ffdb3 --- /dev/null +++ b/tc_core_analyzer_lib/tests/integration/test_all_new_consistent.py @@ -0,0 +1,156 @@ +import numpy as np +from tc_core_analyzer_lib.assess_engagement import EngagementAssessment +from tc_core_analyzer_lib.utils.activity import DiscordActivity + + +def test_all_new_consistent(): + """ + test all_new_consistent 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_new_consistent:", activity_dict["all_new_consistent"]) + + assert activity_dict["all_new_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": {"user0", "user1"}, + "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(), + } diff --git a/tc_core_analyzer_lib/tests/integration/test_all_new_vital.py b/tc_core_analyzer_lib/tests/integration/test_all_new_vital.py new file mode 100644 index 0000000..494ec27 --- /dev/null +++ b/tc_core_analyzer_lib/tests/integration/test_all_new_vital.py @@ -0,0 +1,164 @@ +# 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_new_vital(): + acc_names = [] + acc_count = 10 + + 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, + ] + + 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)), + } + # `user_0` intracting with `user_1`, `user_2`, `user_3`, `user_4`, `user_5` + # at least 5 times was needed + int_mat[DiscordActivity.Reaction][0, 1] = 6 + int_mat[DiscordActivity.Reaction][0, 2] = 6 + int_mat[DiscordActivity.Reaction][0, 3] = 6 + int_mat[DiscordActivity.Reaction][0, 4] = 6 + int_mat[DiscordActivity.Reaction][0, 5] = 6 + int_mat[DiscordActivity.Reaction][0, 6] = 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, + ) + + activity_dict = dict(zip(memberactivites, activity_dict)) + + print("all_vital:", activity_dict["all_vital"]) + print("all_new_vital:", activity_dict["all_new_vital"]) + + assert activity_dict["all_new_vital"] == { + "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": {"user0"}, + "22": {"user0"}, + "23": {"user0"}, + "24": {"user0"}, + "25": {"user0"}, + "26": {"user0"}, + "27": {"user0"}, + "28": set(), # user0 is vital but new_vital + "29": set(), + "30": set(), + "31": set(), + "32": set(), + "33": set(), + "34": set(), + } diff --git a/tc_core_analyzer_lib/tests/integration/test_inconsistently_active.py b/tc_core_analyzer_lib/tests/integration/test_inconsistently_active.py index fc526eb..dd62ff7 100644 --- a/tc_core_analyzer_lib/tests/integration/test_inconsistently_active.py +++ b/tc_core_analyzer_lib/tests/integration/test_inconsistently_active.py @@ -118,14 +118,12 @@ def test_inconsistently_active(): 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(), @@ -141,7 +139,7 @@ def test_inconsistently_active(): "11": {"user0", "user1"}, "12": {"user0", "user1"}, "13": {"user0", "user1"}, - "14": set(), # was incluedd in all_paused here + "14": set(), # was incluedd in all_paused here "15": {"user0", "user1"}, "16": {"user0", "user1"}, "17": {"user0", "user1"}, From fd48a1eda80919e9afd75b7471c9dc92f61e1676 Mon Sep 17 00:00:00 2001 From: Mohammad Amin Date: Tue, 17 Oct 2023 19:33:43 +0330 Subject: [PATCH 11/14] fix: removed wrong comment! --- .../tests/integration/test_inconsistently_active.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tc_core_analyzer_lib/tests/integration/test_inconsistently_active.py b/tc_core_analyzer_lib/tests/integration/test_inconsistently_active.py index dd62ff7..cea9b55 100644 --- a/tc_core_analyzer_lib/tests/integration/test_inconsistently_active.py +++ b/tc_core_analyzer_lib/tests/integration/test_inconsistently_active.py @@ -139,7 +139,7 @@ def test_inconsistently_active(): "11": {"user0", "user1"}, "12": {"user0", "user1"}, "13": {"user0", "user1"}, - "14": set(), # was incluedd in all_paused here + "14": set(), "15": {"user0", "user1"}, "16": {"user0", "user1"}, "17": {"user0", "user1"}, @@ -154,3 +154,4 @@ def test_inconsistently_active(): "26": set(), "27": set(), } + assert False is True From be8522078e1a04c9f86c4a00de2e1572bffc5c23 Mon Sep 17 00:00:00 2001 From: Mohammad Amin Date: Tue, 17 Oct 2023 19:37:14 +0330 Subject: [PATCH 12/14] fix: removed wrong assertion! --- .../tests/integration/test_inconsistently_active.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tc_core_analyzer_lib/tests/integration/test_inconsistently_active.py b/tc_core_analyzer_lib/tests/integration/test_inconsistently_active.py index cea9b55..296da18 100644 --- a/tc_core_analyzer_lib/tests/integration/test_inconsistently_active.py +++ b/tc_core_analyzer_lib/tests/integration/test_inconsistently_active.py @@ -154,4 +154,3 @@ def test_inconsistently_active(): "26": set(), "27": set(), } - assert False is True From 15ca7a6bbdd5c489a17dc60909dfe9e0d52f2b79 Mon Sep 17 00:00:00 2001 From: Mohammad Amin Date: Thu, 30 Nov 2023 10:43:51 +0330 Subject: [PATCH 13/14] update: lib version due to adding inconsistent members! --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index b934283..e23d073 100644 --- a/setup.py +++ b/setup.py @@ -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="dadgaramin96@gmail.com", From 0383d206cde58bc3665e05e889d1b097fb3c9da0 Mon Sep 17 00:00:00 2001 From: Mohammad Amin Date: Thu, 30 Nov 2023 10:50:00 +0330 Subject: [PATCH 14/14] update: tests with the new action param type! --- .../test_all_became_not_consistent.py | 46 ++++++------------- .../integration/test_all_became_unvital.py | 46 ++++++------------- .../integration/test_all_new_consistent.py | 46 ++++++------------- .../tests/integration/test_all_new_vital.py | 46 ++++++------------- .../integration/test_inconsistently_active.py | 46 ++++++------------- 5 files changed, 75 insertions(+), 155 deletions(-) diff --git a/tc_core_analyzer_lib/tests/integration/test_all_became_not_consistent.py b/tc_core_analyzer_lib/tests/integration/test_all_became_not_consistent.py index 55b3978..12caad3 100644 --- a/tc_core_analyzer_lib/tests/integration/test_all_became_not_consistent.py +++ b/tc_core_analyzer_lib/tests/integration/test_all_became_not_consistent.py @@ -8,37 +8,21 @@ def test_became_not_consistent(): acc_names = [] acc_count = 10 - 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, - ] + 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}") diff --git a/tc_core_analyzer_lib/tests/integration/test_all_became_unvital.py b/tc_core_analyzer_lib/tests/integration/test_all_became_unvital.py index e917bca..1c355c2 100644 --- a/tc_core_analyzer_lib/tests/integration/test_all_became_unvital.py +++ b/tc_core_analyzer_lib/tests/integration/test_all_became_unvital.py @@ -8,37 +8,21 @@ def test_all_became_unvital(): acc_names = [] acc_count = 10 - 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, - ] + 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}") diff --git a/tc_core_analyzer_lib/tests/integration/test_all_new_consistent.py b/tc_core_analyzer_lib/tests/integration/test_all_new_consistent.py index 98ffdb3..8e49ece 100644 --- a/tc_core_analyzer_lib/tests/integration/test_all_new_consistent.py +++ b/tc_core_analyzer_lib/tests/integration/test_all_new_consistent.py @@ -51,37 +51,21 @@ def test_all_new_consistent(): } 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, - ] + 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, + } int_mat = { DiscordActivity.Reply: np.zeros((acc_count, acc_count)), diff --git a/tc_core_analyzer_lib/tests/integration/test_all_new_vital.py b/tc_core_analyzer_lib/tests/integration/test_all_new_vital.py index 494ec27..fccdf4e 100644 --- a/tc_core_analyzer_lib/tests/integration/test_all_new_vital.py +++ b/tc_core_analyzer_lib/tests/integration/test_all_new_vital.py @@ -8,37 +8,21 @@ def test_new_vital(): acc_names = [] acc_count = 10 - 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, - ] + 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}") diff --git a/tc_core_analyzer_lib/tests/integration/test_inconsistently_active.py b/tc_core_analyzer_lib/tests/integration/test_inconsistently_active.py index 296da18..53ee525 100644 --- a/tc_core_analyzer_lib/tests/integration/test_inconsistently_active.py +++ b/tc_core_analyzer_lib/tests/integration/test_inconsistently_active.py @@ -51,37 +51,21 @@ def test_inconsistently_active(): } 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, - ] + 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, + } int_mat = { DiscordActivity.Reply: np.zeros((acc_count, acc_count)),