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

feat: removing dependency from core analyzer lib! #2

Merged
merged 4 commits into from
Jul 8, 2024

Conversation

amindadgar
Copy link
Member

@amindadgar amindadgar commented Jul 8, 2024

Summary by CodeRabbit

  • New Features

    • Introduced comprehensive assessment functions for network analysis, including evaluation of active, connected, consistent, dropped, lurker, overlapping, remaining, and vital accounts.
    • Added EngagementAssessment class for assessing engagement levels of active members.
    • Added utility functions for computing interactions and generating graphs.
    • Introduced test cases for new functionalities.
  • Dependencies

    • Updated dependencies to use tc-neo4j-lib==2.0.1.
  • Bug Fixes

    • Corrected an issue in convert_back_to_old_schema function to use an empty set instead of an empty string.

Copy link
Contributor

coderabbitai bot commented Jul 8, 2024

Walkthrough

The update overhauls the tc_analyzer_lib by adding various assessment modules for network analysis, including functionalities to assess active, connected, consistent, lurker, and vital nodes among others. Additionally, it replaces tc-core-analyzer-lib with tc-neo4j-lib in requirements.txt and introduces supporting utilities and test files.

Changes

File Path Change Summary
requirements.txt Removed tc-core-analyzer-lib, added tc-neo4j-lib.
tc_analyzer_lib/algorithms/assessment/__init__.py New file: Imports multiple assessment functions related to network analysis.
Various assess_<type>.py files Introduced functions to assess different types of accounts: active, connected, consistent, dropped, lurker, overlap, remainder, still active, and vital nodes.
tc_analyzer_lib/algorithms/assessment/check_past.py New file: Function to analyze past account names.
tc_analyzer_lib/algorithms/assessment/check_prev_period.py New file: Function to check for values in previous periods.
tc_analyzer_lib/algorithms/assessment/utils/... New utility files: Classes for activity enums, functions for computing interactions per account, generating graphs.
tc_analyzer_lib/algorithms/assessment/engagement.py New file: Class EngagementAssessment for assessing engagement levels of active members.
tc_analyzer_lib/algorithms/assessment/utils/member_activity_history_utils.py Updated function: Sets empty set instead of empty string for a specific key in the dictionary.
tests/unit/test_enum_activity.py New file: Test cases for BaseActivity and DiscordActivity enums.
tests/unit/test_graph_creation.py New file: Test function to validate graph creation.

Poem

In the land of bytes and code,
Where networks weave and nodes explode,
The vital, lurker, and active clear,
Now assessed with wisdom and cheer! 🌟
Through engagement and graphs we tread,
With tc-neo4j-lib we forge ahead. 🚀


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 18

Outside diff range and nitpick comments (26)
tests/unit/test_assess_remainder_returned.py (3)

1-1: Consider adding a docstring for the test function.

Adding a docstring to the test function can help explain its purpose and the scenarios it covers.

"""
Test the assess_remainder function for returned users.
"""

5-9: Consider adding more diverse test data.

The current test data only includes a few users and periods. Adding more diverse data can help ensure the robustness of the assess_remainder function.

all_active = {
    "0": set(["user0", "user1", "user2", "user3", "user4"]),
    "1": set(["user0", "user1", "user2", "user3", "user4"]),
    "2": set(["user0", "user1", "user2", "user3", "user4", "user5"]),
    "3": set(["user6", "user7"]),
}

44-44: Ensure the assertion covers all edge cases.

The current assertion only checks for a specific case. Consider adding more assertions to cover different scenarios.

assert all_returned["2"] == set(["user5"])
assert all_returned["0"] == set([])
assert all_returned["1"] == set([])
tc_analyzer_lib/algorithms/assessment/assess_active.py (1)

1-1: Consider adding type hints for numpy imports.

Adding type hints for numpy imports can improve code readability and maintainability.

from numpy import intersect1d, ndarray
import numpy as np
tests/unit/test_assess_consistent.py (2)

4-7: Correct spelling errors in function name and docstring.

The function name and docstring contain spelling errors. "continuos" should be "continuous".

- def test_assess_consistent_continuos():
+ def test_assess_consistent_continuous():
  """
- test the assess_consistent module
+ Test the assess_consistent module
  """

32-35: Correct spelling errors in function name and docstring.

The function name and docstring contain spelling errors. "continuos" should be "continuous".

- def test_assess_consistent_different_periods():
  """
- test the assess_consistent module with not continuos periods
+ Test the assess_consistent module with non-continuous periods
  """
tc_analyzer_lib/algorithms/assessment/assess_dropped.py (1)

14-43: Correct spelling errors in docstring.

The docstring contains spelling errors. "occured" should be "occurred".

- containing a list of all account names that are active for first
+ containing a list of all account names that are active for the first
- periods to have been inactive
+ periods of inactivity
tc_analyzer_lib/algorithms/assessment/assess_still_active.py (1)

14-43: Correct spelling errors in docstring.

The docstring contains spelling errors. "occured" should be "occurred".

- containing a list of all account names that are active for first
+ containing a list of all account names that are active for the first
- periods to have been inactive
+ periods of inactivity
tests/integration/utils/mock_graph.py (1)

Line range hint 14-14:
Remove duplicate call to prepare_activity_params.

The call to prepare_activity_params is duplicated and can be removed.

- act_param = prepare_activity_params()
tests/unit/test_assess_vital.py (1)

4-7: Fix the docstring typos.

The docstring contains typographical errors.

-    test the assess_vital module in contnuos periods
+    test the assess_vital module in continuous periods
tests/integration/test_partially_consistently_active.py (1)

8-8: Fix typographical error in the docstring.

The docstring contains a typographical error. It should be "up to the first day of week 3".

-    the user is just active up the the first day of week 3
+    the user is just active up to the first day of week 3
tests/integration/test_consistently_active.py (1)

8-8: Fix typographical error in the docstring.

The docstring contains a typographical error. It should be "consistently active members category".

-    test conssitently_active members category
+    test consistently active members category
tests/integration/test_newly_active_continuous_period.py (1)

8-8: Fix typographical error in the docstring.

The docstring contains a typographical error. It should be "test the all_new_active members category in a continuous period".

-    test the all_new_active members category in a connected period
+    test the all_new_active members category in a continuous period
tests/integration/test_all_active_fourteen_period.py (1)

7-13: Fix typographical errors in the docstring.

There are typographical errors in the docstring. Consider updating it for better readability.

-    test the all active category for past 14 periods
+    Test the all-active category for the past 14 periods.

-    The interaction matrix is the represantative of window_d days
+    The interaction matrix is representative of WINDOW_D days,

-    so we should have the users as active for the interaction matrix
-    and not the window_d period here
+    so we should have the users as active for the interaction matrix,
+    and not the WINDOW_D period here.
tests/integration/test_newly_active_discontinued_period.py (1)

69-71: Fix typographical error in the comment.

There is a typographical error in the comment. Consider updating it for better readability.

-    # `user_1` intracting with `user_2`
+    # `user_1` interacting with `user_2`
tests/integration/test_mention_active_members_from_int_matrix.py (1)

7-11: Fix typographical errors in the docstring.

There are typographical errors in the docstring. Consider updating it for better readability.

-    test whether the people are being mentioned are active or not
+    Test whether the people being mentioned are active or not.

-    the shouldn't considered as active as we're not counting them
+    They shouldn't be considered as active as we're not counting them.

-    the interaction matrix is the starting point
+    The interaction matrix is the starting point.
tests/integration/test_disengaged_were_consistently_active.py (1)

68-70: Fix typographical error in the comment.

There is a typographical error in the comment. Consider updating it for better readability.

-    # `user_1` intracting with `user_2`
+    # `user_1` interacting with `user_2`
tests/integration/test_active_members.py (2)

12-12: Remove unnecessary conversion to numpy array.

The conversion of acc_names to a numpy array is unnecessary since it is initialized as an empty list and remains unchanged.

-    acc_names = np.array(acc_names)

115-115: Remove unnecessary conversion to numpy array.

The conversion of acc_names to a numpy array is unnecessary since it is initialized as a list and remains unchanged.

-    acc_names = np.array(acc_names)
tc_analyzer_lib/algorithms/assessment/assess_remainder.py (1)

112-112: Initialize empty set directly.

Instead of using set(""), initialize an empty set directly for clarity.

-        all_paused[str(w_i)] = set("")
+        all_paused[str(w_i)] = set()
tests/integration/test_lone_actions_all_active.py (3)

33-33: Remove unnecessary conversion to numpy array.

The conversion of acc_names to a numpy array is unnecessary since it is initialized as a list and remains unchanged.

-        acc_names = np.array(acc_names)

120-120: Remove unnecessary conversion to numpy array.

The conversion of acc_names to a numpy array is unnecessary since it is initialized as a list and remains unchanged.

-        acc_names = np.array(acc_names)

214-214: Remove unnecessary conversion to numpy array.

The conversion of acc_names to a numpy array is unnecessary since it is initialized as a list and remains unchanged.

-        acc_names = np.array(acc_names)
tests/integration/test_thr_actions_all_active.py (3)

27-119: Test logic looks good, but add comments for clarity.

The method correctly sets up the test scenario and asserts the expected outcomes. However, it lacks comments explaining the purpose of each step.

# Example of adding comments:
# Set up account names
acc_names = []
# Number of accounts
acc_count = 5
for i in range(5):
    acc_names.append(f"user{i}")

# Convert account names to numpy array
acc_names = np.array(acc_names)

# Initialize interaction matrix with zeros
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)),
    DiscordActivity.Lone_msg: np.zeros((acc_count, acc_count)),
    DiscordActivity.Thread_msg: np.zeros((acc_count, acc_count)),
}

# Set interaction for thread message
int_mat[DiscordActivity.Thread_msg][1, 1] = 2

# Initialize activity dictionary
activity_dict = {
    "all_joined": {"0": set()},
    "all_joined_day": {"0": set()},
    # ... (other keys)
}

# Window index
w_i = 0

# List of activities
activities = [
    DiscordActivity.Reaction,
    DiscordActivity.Mention,
    DiscordActivity.Reply,
    DiscordActivity.Lone_msg,
    DiscordActivity.Thread_msg,
]

# Initialize engagement assessment
engagement = EngagementAssessment(
    activities=activities,
    activities_ignore_0_axis=[
        DiscordActivity.Mention,
        DiscordActivity.Reaction,
        DiscordActivity.Reply,
    ],
    activities_ignore_1_axis=[],
)

# Compute engagement
(_, *computed_activities) = engagement.compute(
    int_mat=int_mat,
    w_i=w_i,
    acc_names=acc_names,
    act_param=self.action_params,
    WINDOW_D=self.window_days,
    **activity_dict,
)

# Convert computed activities to dictionary
computed_activities = dict(zip(activity_dict.keys(), computed_activities))

# Assert expected outcomes
assert computed_activities["all_joined"] == {"0": set()}
assert computed_activities["all_consistent"] == {"0": set()}
# ... (other assertions)

121-219: Test logic looks good, but add comments for clarity.

The method correctly sets up the test scenario and asserts the expected outcomes. However, it lacks comments explaining the purpose of each step.

# Example of adding comments:
# Set up account names
acc_names = []
# Number of accounts
acc_count = 5
for i in range(5):
    acc_names.append(f"user{i}")

# Convert account names to numpy array
acc_names = np.array(acc_names)

# Initialize interaction matrix with zeros
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)),
    DiscordActivity.Lone_msg: np.zeros((acc_count, acc_count)),
    DiscordActivity.Thread_msg: np.zeros((acc_count, acc_count)),
}

# Set interactions for thread message
int_mat[DiscordActivity.Thread_msg][1, 1] = 2
int_mat[DiscordActivity.Thread_msg][2, 2] = 3
int_mat[DiscordActivity.Thread_msg][3, 3] = 1

# Initialize activity dictionary
activity_dict = {
    "all_joined": {"0": set()},
    "all_joined_day": {"0": set()},
    # ... (other keys)
}

# Window index
w_i = 0

# List of activities
activities = [
    DiscordActivity.Reaction,
    DiscordActivity.Mention,
    DiscordActivity.Reply,
    DiscordActivity.Lone_msg,
    DiscordActivity.Thread_msg,
]

# Initialize engagement assessment
engagement = EngagementAssessment(
    activities=activities,
    activities_ignore_0_axis=[
        DiscordActivity.Mention,
        DiscordActivity.Reaction,
        DiscordActivity.Reply,
    ],
    activities_ignore_1_axis=[],
)

# Compute engagement
(_, *computed_activities) = engagement.compute(
    int_mat=int_mat,
    w_i=w_i,
    acc_names=acc_names,
    act_param=self.action_params,
    WINDOW_D=self.window_days,
    **activity_dict,
)

# Convert computed activities to dictionary
computed_activities = dict(zip(activity_dict.keys(), computed_activities))

# Assert expected outcomes
assert computed_activities["all_joined"] == {"0": set()}
assert computed_activities["all_consistent"] == {"0": set()}
# ... (other assertions)

221-313: Test logic looks good, but add comments for clarity.

The method correctly sets up the test scenario and asserts the expected outcomes. However, it lacks comments explaining the purpose of each step.

# Example of adding comments:
# Set up account names
acc_names = []
# Number of accounts
acc_count = 5
for i in range(5):
    acc_names.append(f"user{i}")

# Convert account names to numpy array
acc_names = np.array(acc_names)

# Initialize interaction matrix with zeros
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)),
    DiscordActivity.Lone_msg: np.zeros((acc_count, acc_count)),
    DiscordActivity.Thread_msg: np.zeros((acc_count, acc_count)),
}

# Set interaction for thread message
int_mat[DiscordActivity.Thread_msg][1, 1] = 2

# Initialize activity dictionary
activity_dict = {
    "all_joined": {"0": set()},
    "all_joined_day": {"0": set()},
    # ... (other keys)
}

# Window index
w_i = 0

# List of activities
activities = [
    DiscordActivity.Reaction,
    DiscordActivity.Mention,
    DiscordActivity.Reply,
    DiscordActivity.Lone_msg,
    DiscordActivity.Thread_msg,
]

# Initialize engagement assessment
engagement = EngagementAssessment(
    activities=activities,
    activities_ignore_0_axis=[
        DiscordActivity.Mention,
        DiscordActivity.Reaction,
        DiscordActivity.Reply,
    ],
    activities_ignore_1_axis=[],
)

# Compute engagement
(_, *computed_activities) = engagement.compute(
    int_mat=int_mat,
    w_i=w_i,
    acc_names=acc_names,
    act_param=self.action_params,
    WINDOW_D=self.window_days,
    **activity_dict,
)

# Convert computed activities to dictionary
computed_activities = dict(zip(activity_dict.keys(), computed_activities))

# Assert expected outcomes
assert computed_activities["all_joined"] == {"0": set()}
assert computed_activities["all_consistent"] == {"0": set()}
# ... (other assertions)
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between b7e401b and 84a907c.

Files selected for processing (55)
  • requirements.txt (1 hunks)
  • tc_analyzer_lib/algorithms/assessment/init.py (1 hunks)
  • tc_analyzer_lib/algorithms/assessment/assess_active.py (1 hunks)
  • tc_analyzer_lib/algorithms/assessment/assess_connected.py (1 hunks)
  • tc_analyzer_lib/algorithms/assessment/assess_consistent.py (1 hunks)
  • tc_analyzer_lib/algorithms/assessment/assess_dropped.py (1 hunks)
  • tc_analyzer_lib/algorithms/assessment/assess_lurker.py (1 hunks)
  • tc_analyzer_lib/algorithms/assessment/assess_overlap.py (1 hunks)
  • tc_analyzer_lib/algorithms/assessment/assess_remainder.py (1 hunks)
  • tc_analyzer_lib/algorithms/assessment/assess_still_active.py (1 hunks)
  • tc_analyzer_lib/algorithms/assessment/assess_vital.py (1 hunks)
  • tc_analyzer_lib/algorithms/assessment/check_past.py (1 hunks)
  • tc_analyzer_lib/algorithms/assessment/check_prev_period.py (1 hunks)
  • tc_analyzer_lib/algorithms/assessment/engagement.py (1 hunks)
  • tc_analyzer_lib/algorithms/assessment/utils/activity.py (1 hunks)
  • tc_analyzer_lib/algorithms/assessment/utils/compute_interaction_per_acc.py (1 hunks)
  • tc_analyzer_lib/algorithms/assessment/utils/generate_graph.py (1 hunks)
  • tc_analyzer_lib/algorithms/utils/member_activity_utils.py (1 hunks)
  • tests/integration/test_active_members.py (1 hunks)
  • tests/integration/test_all_active_fourteen_period.py (1 hunks)
  • tests/integration/test_assess_mention.py (1 hunks)
  • tests/integration/test_assess_reactions.py (1 hunks)
  • tests/integration/test_assess_replies.py (1 hunks)
  • tests/integration/test_consistently_active.py (1 hunks)
  • tests/integration/test_disengaged_members.py (1 hunks)
  • tests/integration/test_disengaged_were_consistently_active.py (1 hunks)
  • tests/integration/test_disengaged_were_newly_active.py (1 hunks)
  • tests/integration/test_disengaged_were_vital.py (1 hunks)
  • tests/integration/test_lone_actions_all_active.py (1 hunks)
  • tests/integration/test_lone_thr_actions_active.py (1 hunks)
  • tests/integration/test_mention_active_members_from_int_matrix.py (1 hunks)
  • tests/integration/test_newly_active_continuous_period.py (1 hunks)
  • tests/integration/test_newly_active_discontinued_period.py (1 hunks)
  • tests/integration/test_non_consistently_active.py (1 hunks)
  • tests/integration/test_partially_consistently_active.py (1 hunks)
  • tests/integration/test_still_active.py (1 hunks)
  • tests/integration/test_thr_actions_all_active.py (1 hunks)
  • tests/integration/test_vital.py (1 hunks)
  • tests/integration/utils/mock_graph.py (1 hunks)
  • tests/unit/test_assess_active.py (1 hunks)
  • tests/unit/test_assess_connected.py (1 hunks)
  • tests/unit/test_assess_consistent.py (1 hunks)
  • tests/unit/test_assess_dropped.py (1 hunks)
  • tests/unit/test_assess_lurker.py (1 hunks)
  • tests/unit/test_assess_overlap.py (1 hunks)
  • tests/unit/test_assess_remainder_disengaged.py (1 hunks)
  • tests/unit/test_assess_remainder_paused.py (1 hunks)
  • tests/unit/test_assess_remainder_returned.py (1 hunks)
  • tests/unit/test_assess_remainder_unpaused.py (1 hunks)
  • tests/unit/test_assess_still_active.py (1 hunks)
  • tests/unit/test_assess_vital.py (1 hunks)
  • tests/unit/test_check_past.py (1 hunks)
  • tests/unit/test_check_prev_period.py (1 hunks)
  • tests/unit/test_enum_activity.py (1 hunks)
  • tests/unit/test_graph_creation.py (1 hunks)
Files skipped from review due to trivial changes (10)
  • requirements.txt
  • tc_analyzer_lib/algorithms/assessment/init.py
  • tc_analyzer_lib/algorithms/assessment/utils/activity.py
  • tc_analyzer_lib/algorithms/assessment/utils/generate_graph.py
  • tc_analyzer_lib/algorithms/utils/member_activity_utils.py
  • tests/unit/test_assess_connected.py
  • tests/unit/test_assess_dropped.py
  • tests/unit/test_check_past.py
  • tests/unit/test_enum_activity.py
  • tests/unit/test_graph_creation.py
Additional context used
Ruff
tc_analyzer_lib/algorithms/assessment/check_prev_period.py

21-21: Use key in dict instead of key in dict.keys()

Remove .keys()

(SIM118)

tests/unit/test_assess_overlap.py

19-19: Use key in dict instead of key in dict.keys()

Remove .keys()

(SIM118)

tc_analyzer_lib/algorithms/assessment/assess_overlap.py

39-39: Use key in dict instead of key in dict.keys()

Remove .keys()

(SIM118)

tc_analyzer_lib/algorithms/assessment/assess_remainder.py

77-77: Use key in dict instead of key in dict.keys()

Remove .keys()

(SIM118)


129-129: Use key in dict instead of key in dict.keys()

Remove .keys()

(SIM118)

tc_analyzer_lib/algorithms/assessment/engagement.py

253-253: Use key in dict instead of key in dict.keys()

Remove .keys()

(SIM118)

Additional comments not posted (57)
tests/unit/test_assess_active.py (1)

1-17: LGTM!

The test case for assess_active is well-defined and covers the basic functionality.

tests/unit/test_check_prev_period.py (2)

1-13: LGTM!

The test case for check_prev_period with available data is well-defined and covers the expected functionality.


16-25: LGTM!

The test case for check_prev_period with no available data is well-defined and covers the expected functionality.

tests/unit/test_assess_lurker.py (1)

1-27: LGTM!

The test case for assess_lurker is well-defined and covers the basic functionality.

tests/unit/test_assess_still_active.py (1)

1-36: LGTM! Consider adding more test cases.

The test function test_still_active looks good and covers a basic scenario. Consider adding more test cases to cover edge cases and different scenarios.

tc_analyzer_lib/algorithms/assessment/assess_connected.py (1)

1-39: LGTM! The function is well-documented and correct.

The function assess_connected looks good and is well-documented. The logic is correct and the performance is optimal.

tests/unit/test_assess_remainder_paused.py (1)

1-44: LGTM! Consider adding more test cases.

The test function test_assess_paused looks good and covers a basic scenario. Consider adding more test cases to cover edge cases and different scenarios.

tc_analyzer_lib/algorithms/assessment/assess_vital.py (1)

1-1: Ensure the helper function check_past is tested.

The function relies on check_past. Ensure that check_past is thoroughly tested to avoid potential issues.

Verification successful

Verified: The check_past function is tested.

The function check_past is indeed tested in the file tests/unit/test_check_past.py.

  • tests/unit/test_check_past.py
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that the function check_past is tested.

# Test: Search for test cases for check_past. Expect: At least one test case.
rg --type python $'check_past'

Length of output: 60


Script:

#!/bin/bash
# Description: Verify that the function check_past is tested.

# Test: Search for test cases for check_past. Expect: At least one test case.
rg --type py 'check_past'

Length of output: 1953

tests/unit/test_assess_remainder_unpaused.py (1)

4-66: LGTM!

The unit test function test_assess_unpaused is well-structured and logically correct.

tests/integration/utils/mock_graph.py (1)

5-6: LGTM! Imports are correctly updated.

The imports have been correctly updated to use EngagementAssessment and DiscordActivity from tc_analyzer_lib.

tests/unit/test_assess_vital.py (2)

33-36: LGTM!

The test function correctly tests the assess_vital function for different periods.


63-66: LGTM!

The test function correctly tests the assess_vital function for different periods not starting from the first period.

tests/integration/test_assess_replies.py (2)

9-25: LGTM!

The setUp method correctly initializes the necessary parameters for the test class.


27-100: LGTM!

The test method correctly tests the EngagementAssessment class for a single reply interaction.

tests/integration/test_assess_mention.py (2)

9-25: LGTM!

The setUp method correctly initializes the necessary parameters for the test class.


27-100: LGTM!

The test method correctly tests the EngagementAssessment class for a single mention interaction.

tests/integration/test_assess_reactions.py (2)

9-25: LGTM!

The setUp method correctly initializes the necessary parameters for the test class.


27-100: LGTM!

The test method correctly tests the EngagementAssessment class for a single reaction interaction.

tests/unit/test_assess_remainder_disengaged.py (2)

4-52: LGTM! Verify the function parameters.

The test setup and assertions appear correct.

However, ensure that all parameters passed to assess_remainder are correctly defined and used.

Verification successful

Verification successful. The function parameters are correctly defined and used in the test.

  • The test setup and assertions match the parameters of the assess_remainder function.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the function parameters for `assess_remainder`.

# Test: Search for the function definition. Expect: Parameters match those used in the test.
rg --type python $'def assess_remainder'

Length of output: 72


Script:

#!/bin/bash
# Description: Verify the function parameters for `assess_remainder`.

# Test: Search for the function definition. Expect: Parameters match those used in the test.
rg 'def assess_remainder' --glob '*.py'

Length of output: 121


Script:

#!/bin/bash
# Description: Extract the full function signature for `assess_remainder`.

# Extract the function signature for `assess_remainder` from the specified file.
rg 'def assess_remainder' -A 10 tc_analyzer_lib/algorithms/assessment/assess_remainder.py

Length of output: 448


Script:

#!/bin/bash
# Description: Extract the full function signature for `assess_remainder`.

# Extract more lines to capture the complete function signature for `assess_remainder`.
rg 'def assess_remainder' -A 20 tc_analyzer_lib/algorithms/assessment/assess_remainder.py

Length of output: 687


54-101: LGTM! Verify the function parameters.

The test setup and assertions appear correct.

However, ensure that all parameters passed to assess_remainder are correctly defined and used.

Verification successful

Function parameters are correctly defined and used.

The parameters in the test test_assess_disengaged_with_past_disengaged match the parameters in the function definition of assess_remainder.

  • tc_analyzer_lib/algorithms/assessment/assess_remainder.py
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the function parameters for `assess_remainder`.

# Test: Search for the function definition. Expect: Parameters match those used in the test.
rg --type python $'def assess_remainder'

Length of output: 72


Script:

#!/bin/bash
# Description: Verify the function parameters for `assess_remainder`.

# Test: Search for the function definition. Expect: Parameters match those used in the test.
ast-grep --lang python --pattern $'def assess_remainder($_, $_, $_, $_, $_, $_, $_, $_, $_, $_, $_, $_, $_):'

Length of output: 110


Script:

#!/bin/bash
# Description: Verify the function parameters for `assess_remainder`.

# Test: Search for the function definition using a more flexible pattern.
ast-grep --lang python --pattern $'def assess_remainder($_):'

# Test: Search for the function definition using rg.
rg 'def assess_remainder'

Length of output: 170


Script:

#!/bin/bash
# Description: Extract the function definition and parameters for `assess_remainder`.

# Extract the function definition and parameters.
ast-grep --lang python --pattern $'def assess_remainder($_):' tc_analyzer_lib/algorithms/assessment/assess_remainder.py

Length of output: 120


Script:

#!/bin/bash
# Description: Extract the content of the file containing `assess_remainder` function.

# Extract the content of the file.
rg 'def assess_remainder' -A 20 tc_analyzer_lib/algorithms/assessment/assess_remainder.py

Length of output: 687

tests/integration/test_still_active.py (1)

7-135: LGTM! Verify the interaction matrix setup.

The test setup and assertions appear correct.

However, ensure that the interaction matrix setup and parameters passed to compute are correctly defined and used.

Verification successful

Interaction matrix setup and parameters passed to compute are correctly defined and used.

The test setup and assertions appear correct. The compute method's parameters match those used in the test function.

  • int_mat
  • w_i
  • acc_names
  • act_param
  • WINDOW_D
  • Various activity dictionaries
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the interaction matrix setup for `EngagementAssessment`.

# Test: Search for the `compute` method definition. Expect: Parameters match those used in the test.
rg --type python $'def compute'

Length of output: 63


Script:

#!/bin/bash
# Description: Verify the interaction matrix setup for `EngagementAssessment`.

# Test: Search for the `compute` method definition.
rg 'def compute'

Length of output: 2425


Script:

#!/bin/bash
# Description: Extract the definition and parameters of the `compute` method in `tc_analyzer_lib/algorithms/assessment/engagement.py`.

# Extract the `compute` method definition along with its parameters.
rg -A 20 'def compute' tc_analyzer_lib/algorithms/assessment/engagement.py

Length of output: 510

tests/integration/test_vital.py (1)

7-133: LGTM! Verify the interaction matrix setup.

The test setup and assertions appear correct.

However, ensure that the interaction matrix setup and parameters passed to compute are correctly defined and used.

Verification successful

Verification Successful: Interaction Matrix Setup

The interaction matrix setup and parameters passed to the compute method in the EngagementAssessment class are correctly defined and used in the test case.

  • tc_analyzer_lib/algorithms/assessment/engagement.py: compute method implementation
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the interaction matrix setup for `EngagementAssessment`.

# Test: Search for the `compute` method definition. Expect: Parameters match those used in the test.
rg --type python $'def compute'

Length of output: 63


Script:

#!/bin/bash
# Description: Verify the interaction matrix setup for `EngagementAssessment`.

# Test: Search for the `compute` method definition.
rg 'def compute'

# Test: Search for the `EngagementAssessment` class definition.
rg 'class EngagementAssessment'

Length of output: 2539


Script:

#!/bin/bash
# Description: Extract the implementation of the `compute` method from `EngagementAssessment` class.

# Extract the `compute` method implementation from the `EngagementAssessment` class.
ast-grep --lang python --pattern $'class EngagementAssessment {
  $$$
  def compute($_, $_, $_, $_, $_, $$$):
    $$$
  $$$
}' tc_analyzer_lib/algorithms/assessment/engagement.py

Length of output: 692


Script:

#!/bin/bash
# Description: Extract the implementation of the `compute` method from `EngagementAssessment` class.

# Extract the `compute` method implementation from the `EngagementAssessment` class.
ast-grep --lang python --pattern 'class EngagementAssessment {
  def compute($_, $_, $_, $_, $_, $$$):
    $$$
}' tc_analyzer_lib/algorithms/assessment/engagement.py

Length of output: 668


Script:

#!/bin/bash
# Description: Extract the implementation of the `compute` method from `EngagementAssessment` class.

# Extract the `compute` method implementation from the `EngagementAssessment` class.
ast-grep --lang python --pattern 'def compute($_, $_, $_, $_, $_, $$$):
    $$$' tc_analyzer_lib/algorithms/assessment/engagement.py

Length of output: 23263

tests/integration/test_non_consistently_active.py (1)

6-136: LGTM! Verify the interaction matrix setup.

The test setup and assertions appear correct.

However, ensure that the interaction matrix setup and parameters passed to compute are correctly defined and used.

Verification successful

Verification Successful: Interaction matrix setup and parameters are correctly defined and used.

The parameters passed to the compute method in the test function test_two_consistently_active_non match the method's definition in tc_analyzer_lib/algorithms/assessment/engagement.py. The test setup and assertions appear to be correctly implemented.

  • int_mat
  • w_i
  • acc_names
  • act_param
  • WINDOW_D
  • all_joined
  • all_joined_day
  • 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_vital
  • all_disengaged_were_newly_active
  • all_disengaged_were_consistently_active
  • all_lurker
  • all_about_to_disengage
  • all_disengaged_in_past
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the interaction matrix setup for `EngagementAssessment`.

# Test: Search for the `compute` method definition. Expect: Parameters match those used in the test.
rg --type python $'def compute'

Length of output: 63


Script:

#!/bin/bash
# Description: Verify the interaction matrix setup for `EngagementAssessment`.

# Test: Search for the `compute` method definition. Expect: Parameters match those used in the test.
rg 'def compute'

Length of output: 2425


Script:

#!/bin/bash
# Description: Extract the `compute` method definition from `tc_analyzer_lib/algorithms/assessment/engagement.py`.

# Extract the `compute` method definition and its parameters.
rg --context 10 --max-count 1 'def compute' tc_analyzer_lib/algorithms/assessment/engagement.py

Length of output: 674


Script:

#!/bin/bash
# Description: Extract the complete `compute` method definition from `tc_analyzer_lib/algorithms/assessment/engagement.py`.

# Extract the `compute` method definition with more context to capture all parameters.
rg --context 20 --max-count 1 'def compute' tc_analyzer_lib/algorithms/assessment/engagement.py

Length of output: 1295


Script:

#!/bin/bash
# Description: Extract the complete `compute` method definition from `tc_analyzer_lib/algorithms/assessment/engagement.py`.

# Extract the `compute` method definition with more context to capture all parameters.
rg --context 30 --max-count 1 'def compute' tc_analyzer_lib/algorithms/assessment/engagement.py

Length of output: 1807

tests/integration/test_partially_consistently_active.py (2)

65-73: LGTM! Interaction matrix setup is correct.

The interaction matrix is properly configured to simulate interactions between users.


103-136: Verify the logic of the assertions.

Ensure that the expected values in the assertions correctly reflect the intended test scenario. The assertions seem to be correct, but a double-check is recommended.

tests/integration/test_consistently_active.py (2)

65-73: LGTM! Interaction matrix setup is correct.

The interaction matrix is properly configured to simulate interactions between users.


103-134: Verify the logic of the assertions.

Ensure that the expected values in the assertions correctly reflect the intended test scenario. The assertions seem to be correct, but a double-check is recommended.

tests/integration/test_newly_active_continuous_period.py (2)

65-73: LGTM! Interaction matrix setup is correct.

The interaction matrix is properly configured to simulate interactions between users.


106-135: Verify the logic of the assertions.

Ensure that the expected values in the assertions correctly reflect the intended test scenario. The assertions seem to be correct, but a double-check is recommended.

Verification successful

Verify the logic of the assertions.

The assertions in test_newly_active_continuous_period.py appear to correctly reflect the intended test scenario. The expected values match the continuous activity pattern described in the test.

  • tests/integration/test_newly_active_continuous_period.py, lines 106-135
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the logic of the assertions in `test_newly_active_continuous_period`.

# Test: Ensure the expected values match the intended test scenario.
rg --type python $'assert activity_dict["all_new_active"]'

Length of output: 90


Script:

#!/bin/bash
# Description: Verify the logic of the assertions in `test_newly_active_continuous_period.py`.

# Test: Ensure the expected values match the intended test scenario.
ast-grep --lang python --pattern $'assert activity_dict["all_new_active"] == $_'

Length of output: 5458

tests/integration/test_disengaged_were_newly_active.py (2)

63-71: LGTM! Interaction matrix setup is correct.

The interaction matrix is properly configured to simulate interactions between users.


108-137: Verify the logic of the assertions.

Ensure that the expected values in the assertions correctly reflect the intended test scenario. The assertions seem to be correct, but a double-check is recommended.

Verification successful

Verify the logic of the assertions.

The logic of the assertions in test_disengaged_newly_active is correctly implemented. The expected values in the assertions reflect the intended test scenario, where user0 and user1 are newly active and then disengaged.

  • tests/integration/test_disengaged_were_newly_active.py: Lines 108-137
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the logic of the assertions in `test_disengaged_newly_active`.

# Test: Ensure the expected values match the intended test scenario.
rg --type python $'assert activity_dict["all_disengaged_were_newly_active"]'

Length of output: 108


Script:

#!/bin/bash
# Description: Locate the `test_disengaged_newly_active` function and extract the assertions.

# Find the file containing the `test_disengaged_newly_active` function definition.
rg 'def test_disengaged_newly_active' --glob '*.py'

# Extract the lines containing the assertions within the `test_disengaged_newly_active` function.
rg 'assert activity_dict\["all_disengaged_were_newly_active"\]' --glob '*.py'

Length of output: 345


Script:

#!/bin/bash
# Description: Extract the complete `test_disengaged_newly_active` function definition.

# Extract the complete function definition for `test_disengaged_newly_active`.
rg -A 50 'def test_disengaged_newly_active' tests/integration/test_disengaged_were_newly_active.py

Length of output: 1402


Script:

#!/bin/bash
# Description: Extract the complete `test_disengaged_newly_active` function definition with more lines.

# Extract the complete function definition for `test_disengaged_newly_active`.
rg -A 100 'def test_disengaged_newly_active' tests/integration/test_disengaged_were_newly_active.py

Length of output: 2899

tests/integration/test_all_active_fourteen_period.py (1)

120-135: Ensure the test assertion covers all possible cases.

The test assertion seems comprehensive. Ensure that it covers all possible cases for the all_active category.

Verification successful

The test assertion covers all possible cases for the all_active category.

The provided test assertion includes all indices from 0 to 13 with appropriate user sets or empty sets, ensuring comprehensive coverage for the all_active category.

  • File: tests/integration/test_all_active_fourteen_period.py
  • Lines: 120-135
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that the test assertion covers all possible cases for the `all_active` category.

# Test: Check if any cases are missing in the test assertion.
rg 'assert activity_dict\["all_active"\] == \{' -A 20 tests/integration/test_all_active_fourteen_period.py

Length of output: 468


Script:

#!/bin/bash
# Description: Find the definition and population logic of `activity_dict["all_active"]` to understand its possible values.

# Search for the definition of `activity_dict`
rg 'activity_dict' -A 10

# Search for the population logic of `activity_dict["all_active"]`
rg 'activity_dict\["all_active"\]' -A 10

Length of output: 107276

tests/integration/test_newly_active_discontinued_period.py (1)

107-136: Ensure the test assertion covers all possible cases.

The test assertion seems comprehensive. Ensure that it covers all possible cases for the all_new_active category.

Verification successful

The test assertion covers all possible cases for the all_new_active category.

The test assertion comprehensively includes all keys from "0" to "27", ensuring that no cases are missing for the all_new_active category.

  • tests/integration/test_newly_active_discontinued_period.py lines 107-136
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that the test assertion covers all possible cases for the `all_new_active` category.

# Test: Check if any cases are missing in the test assertion.
rg 'assert activity_dict\["all_new_active"\] == \{' -A 20 tests/integration/test_newly_active_discontinued_period.py

Length of output: 745


Script:

#!/bin/bash
# Description: Verify that the test assertion covers all possible cases for the `all_new_active` category.

# Test: Check the complete test assertion block for the `all_new_active` category.
rg 'assert activity_dict\["all_new_active"\] == \{' -A 30 tests/integration/test_newly_active_discontinued_period.py

Length of output: 932

tests/integration/test_mention_active_members_from_int_matrix.py (1)

110-139: Ensure the test assertion covers all possible cases.

The test assertion seems comprehensive. Ensure that it covers all possible cases for the all_active category.

tests/integration/test_disengaged_were_consistently_active.py (1)

107-150: Ensure the test assertion covers all possible cases.

The test assertion seems comprehensive. Ensure that it covers all possible cases for the all_disengaged_were_consistently_active category.

Verification successful

Verification Successful: The test assertion covers all possible cases for the all_disengaged_were_consistently_active category.

  • The assertion includes keys from "0" to "41".
  • Keys "36" to "41" have the set {"user0", "user1"}.
  • All other keys have empty sets.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that the test assertion covers all possible cases for the `all_disengaged_were_consistently_active` category.

# Test: Check if any cases are missing in the test assertion.
rg 'assert activity_dict\["all_disengaged_were_consistently_active"\] == \{' -A 20 tests/integration/test_disengaged_were_consistently_active.py

Length of output: 629


Script:

#!/bin/bash
# Description: Verify that the test assertion covers all possible cases for the `all_disengaged_were_consistently_active` category.

# Test: Check if any cases are missing in the test assertion by extending the range of lines retrieved.
rg 'assert activity_dict\["all_disengaged_were_consistently_active"\] == \{' -A 50 tests/integration/test_disengaged_were_consistently_active.py

Length of output: 1175

tests/integration/test_disengaged_members.py (5)

1-3: LGTM! Imports are correct.

The imports are necessary and correct for the test.


6-20: LGTM! Setup is appropriate.

The initial setup of the test function correctly initializes account names and parameters.


22-60: LGTM! Activity dictionary and parameter setup are comprehensive.

The setup of the activity dictionary and parameters is comprehensive and well-structured.


62-79: LGTM! Interaction matrix and engagement assessment setup are correct.

The initialization of the interaction matrix and the setup of the engagement assessment are correct and necessary for the test.


81-157: LGTM! Analytics loop and assertions are logical.

The loop and assertions correctly validate the disengaged members over multiple time windows.

tests/integration/test_disengaged_were_vital.py (5)

1-3: LGTM! Imports are correct.

The imports are necessary and correct for the test.


6-29: LGTM! Setup is appropriate.

The initial setup of the test function correctly initializes account names and parameters.


39-60: LGTM! Activity dictionary and parameter setup are comprehensive.

The setup of the activity dictionary and parameters is comprehensive and well-structured.


63-85: LGTM! Interaction matrix and engagement assessment setup are correct.

The initialization of the interaction matrix and the setup of the engagement assessment are correct and necessary for the test.


87-161: LGTM! Analytics loop and assertions are logical.

The loop and assertions correctly validate the disengaged members over multiple time windows.

tests/integration/test_lone_thr_actions_active.py (5)

1-5: LGTM! Imports are correct.

The imports are necessary and correct for the test.


9-25: LGTM! Setup method is appropriate.

The setup method correctly initializes parameters for the test.


27-41: LGTM! Initial setup of the test method is appropriate.

The test method correctly initializes account names and sets up the interaction matrix.


50-91: LGTM! Activity dictionary and engagement assessment setup are comprehensive.

The setup of the activity dictionary and the initialization of the engagement assessment are comprehensive and well-structured.


93-128: LGTM! Engagement computation and assertions are logical.

The engagement computation and assertions correctly validate the engagement scenarios.

tc_analyzer_lib/algorithms/assessment/utils/compute_interaction_per_acc.py (3)

10-118: LGTM! Function thr_int is well-structured.

The function correctly computes the number of interactions and connections per account.


121-135: LGTM! Function remove_edges_below_threshold is well-structured.

The function correctly removes edges from a graph that have a weight below a specified threshold.


138-186: LGTM! Function get_analysis_vector is well-structured.

The function correctly computes an analysis vector based on given matrices.

tc_analyzer_lib/algorithms/assessment/engagement.py (2)

22-48: LGTM!

The __init__ method is well-formed with clear documentation.


50-315: LGTM!

The compute method is well-formed with clear documentation.

Tools
Ruff

253-253: Use key in dict instead of key in dict.keys()

Remove .keys()

(SIM118)

tests/integration/test_thr_actions_all_active.py (2)

1-5: Imports look good.

The import statements are correct and necessary for the functionality of the test cases.


8-25: Initialization looks good.

The setUp method correctly initializes the necessary parameters for the test cases.

tc_analyzer_lib/algorithms/assessment/check_prev_period.py Outdated Show resolved Hide resolved
tc_analyzer_lib/algorithms/assessment/assess_consistent.py Outdated Show resolved Hide resolved
tc_analyzer_lib/algorithms/assessment/assess_consistent.py Outdated Show resolved Hide resolved
tc_analyzer_lib/algorithms/assessment/assess_overlap.py Outdated Show resolved Hide resolved
tests/unit/test_assess_overlap.py Outdated Show resolved Hide resolved
Comment on lines +38 to +59
activity_dict = {
"all_joined": {},
"all_joined_day": all_joined_day,
"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": {},
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider initializing activity_dict with a helper function.

To improve readability and maintainability, consider extracting the initialization of activity_dict into a helper function.

def initialize_activity_dict(all_joined_day):
    return {
        "all_joined": {},
        "all_joined_day": all_joined_day,
        "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": {},
    }

# Usage
activity_dict = initialize_activity_dict(all_joined_day)

Comment on lines +93 to +106
# two weeks represantative of 14 days
for day_i in range(14):
if day_i == 1:
int_mat[DiscordActivity.Reaction][0, 1] = 0
int_mat[DiscordActivity.Reaction][1, 0] = 0

if day_i == 3:
int_mat[DiscordActivity.Reaction][2, 3] = 2
int_mat[DiscordActivity.Reaction][3, 2] = 4

if day_i == 4:
int_mat[DiscordActivity.Reaction][2, 3] = 0
int_mat[DiscordActivity.Reaction][3, 2] = 0

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider using a switch-case structure for updating int_mat within the loop.

To improve readability and maintainability, consider using a switch-case structure (or equivalent) for updating int_mat within the loop.

for day_i in range(14):
    match day_i:
        case 1:
            int_mat[DiscordActivity.Reaction][0, 1] = 0
            int_mat[DiscordActivity.Reaction][1, 0] = 0
        case 3:
            int_mat[DiscordActivity.Reaction][2, 3] = 2
            int_mat[DiscordActivity.Reaction][3, 2] = 4
        case 4:
            int_mat[DiscordActivity.Reaction][2, 3] = 0
            int_mat[DiscordActivity.Reaction][3, 2] = 0

Comment on lines +39 to +60
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": {},
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider initializing activity_dict with a helper function.

To improve readability and maintainability, consider extracting the initialization of activity_dict into a helper function.

def initialize_activity_dict(all_joined_day):
    return {
        "all_joined": {},
        "all_joined_day": all_joined_day,
        "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": {},
    }

# Usage
activity_dict = initialize_activity_dict(all_joined_day)

Comment on lines +39 to +65
# 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": {},
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider initializing activity_dict with a helper function.

To improve readability and maintainability, consider extracting the initialization of activity_dict into a helper function.

def initialize_activity_dict(all_joined_day):
    return {
        "all_joined": {},
        "all_joined_day": all_joined_day,
        "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": {},
    }

# Usage
activity_dict = initialize_activity_dict(all_joined_day)

Comment on lines +18 to +43
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": {},
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider initializing activity_dict with a helper function.

To improve readability and maintainability, consider extracting the initialization of activity_dict into a helper function.

def initialize_activity_dict(all_joined_day):
    return {
        "all_joined": {},
        "all_joined_day": all_joined_day,
        "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": {},
    }

# Usage
activity_dict = initialize_activity_dict(all_joined_day)

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 84a907c and 807acb8.

Files selected for processing (3)
  • tc_analyzer_lib/algorithms/utils/member_activity_utils.py (1 hunks)
  • tests/unit/test_enum_activity.py (1 hunks)
  • tests/unit/test_graph_creation.py (1 hunks)
Files skipped from review as they are similar to previous changes (3)
  • tc_analyzer_lib/algorithms/utils/member_activity_utils.py
  • tests/unit/test_enum_activity.py
  • tests/unit/test_graph_creation.py

@amindadgar amindadgar requested a review from cyri113 July 8, 2024 12:48
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 807acb8 and e0080f0.

Files selected for processing (12)
  • setup.py (1 hunks)
  • tc_analyzer_lib/algorithms/assessment/assess_consistent.py (1 hunks)
  • tc_analyzer_lib/algorithms/assessment/assess_dropped.py (1 hunks)
  • tc_analyzer_lib/algorithms/assessment/assess_lurker.py (1 hunks)
  • tc_analyzer_lib/algorithms/assessment/assess_overlap.py (1 hunks)
  • tc_analyzer_lib/algorithms/assessment/assess_remainder.py (1 hunks)
  • tc_analyzer_lib/algorithms/assessment/assess_still_active.py (1 hunks)
  • tc_analyzer_lib/algorithms/assessment/assess_vital.py (1 hunks)
  • tc_analyzer_lib/algorithms/assessment/check_prev_period.py (1 hunks)
  • tc_analyzer_lib/algorithms/assessment/engagement.py (1 hunks)
  • tc_analyzer_lib/algorithms/utils/member_activity_history_utils.py (1 hunks)
  • tests/unit/test_assess_overlap.py (1 hunks)
Files skipped from review due to trivial changes (2)
  • setup.py
  • tc_analyzer_lib/algorithms/utils/member_activity_history_utils.py
Files skipped from review as they are similar to previous changes (7)
  • tc_analyzer_lib/algorithms/assessment/assess_consistent.py
  • tc_analyzer_lib/algorithms/assessment/assess_dropped.py
  • tc_analyzer_lib/algorithms/assessment/assess_lurker.py
  • tc_analyzer_lib/algorithms/assessment/assess_overlap.py
  • tc_analyzer_lib/algorithms/assessment/assess_still_active.py
  • tc_analyzer_lib/algorithms/assessment/assess_vital.py
  • tests/unit/test_assess_overlap.py
Additional context used
Ruff
tc_analyzer_lib/algorithms/assessment/check_prev_period.py

21-24: Use ternary operator temp_set = set(engagement_dict[time_str]) if time_str in engagement_dict else set() instead of if-else-block

Replace if-else-block with temp_set = set(engagement_dict[time_str]) if time_str in engagement_dict else set()

(SIM108)

Additional comments not posted (1)
tc_analyzer_lib/algorithms/assessment/engagement.py (1)

22-49: LGTM!

The __init__ method is straightforward and initializes the class correctly.

Comment on lines +21 to +24
if time_str in engagement_dict:
temp_set = set(engagement_dict[time_str])
else:
temp_set = set()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use a ternary operator for better readability.

The if-else block can be replaced with a ternary operator to make the code more concise and readable.

-    if time_str in engagement_dict:
-        temp_set = set(engagement_dict[time_str])
-    else:
-        temp_set = set()
+    temp_set = set(engagement_dict[time_str]) if time_str in engagement_dict else set()
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if time_str in engagement_dict:
temp_set = set(engagement_dict[time_str])
else:
temp_set = set()
temp_set = set(engagement_dict[time_str]) if time_str in engagement_dict else set()
Tools
Ruff

21-24: Use ternary operator temp_set = set(engagement_dict[time_str]) if time_str in engagement_dict else set() instead of if-else-block

Replace if-else-block with temp_set = set(engagement_dict[time_str]) if time_str in engagement_dict else set()

(SIM108)

"""

# if data from previous period is available
if (w_i - WINDOW_D >= 0) and (str(w_i - WINDOW_D) in all_active):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optimize dictionary key checks.

The key in dict.keys() can be simplified to key in dict for better readability and performance.

-    if (w_i - WINDOW_D >= 0) and (str(w_i - WINDOW_D) in all_active.keys()):
+    if (w_i - WINDOW_D >= 0) and (str(w_i - WINDOW_D) in all_active):

-            if str(w_i - WINDOW_D) in all_disengaged.keys():
+            if str(w_i - WINDOW_D) in all_disengaged:

Also applies to: 129-129

rem_new_disengaged = {}

# if there is any disengagement data
if str(w_i) in all_new_disengaged:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optimize dictionary key checks.

The key in dict.keys() can be simplified to key in dict for better readability and performance.

-        if str(w_i) in all_new_disengaged.keys():
+        if str(w_i) in all_new_disengaged:
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if str(w_i) in all_new_disengaged:
if str(w_i) in all_new_disengaged:

@cyri113 cyri113 merged commit 0c68eb2 into main Jul 8, 2024
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants