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

Update action param type #31

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 30 additions & 40 deletions discord_analyzer/analysis/compute_member_activity.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,46 +56,36 @@ def compute_member_activity(
(Currently these values will be default values,
in the future, the user might be able to set these in the
extraction settings page)
act_param: [int] -
entry 1: INT_THR - int :
minimum number of interactions to be active.
Default = 1
entry 2: UW_DEG_THR - int :
minimum number of connections to be active.
Default = 1
entry 3: PAUSED_T_THR - int :
time period to remain paused.
Default = 1
entry 4: CON_T_THR - int :
time period to assess consistently active.
Default = 4
entry 5: CON_O_THR - int :
times to be active within CON_T_THR to be consistently active.
Default = 3
entry 6: EDGE_STR_THR - int :
minimum number of interactions for connected.
Default = 5
entry 7: UW_THR_DEG_THR - int :
minimum number of accounts for connected.
Default = 5
entry 8: VITAL_T_THR - int :
time period to assess for vital.
Default = 4
entry 9: VITAL_O_THR - int :
times to be connected within VITAL_T_THR to be vital.
Default = 3
entry 10: STILL_T_THR - int :
time period to assess for still active.
Default = 3
entry 11: STILL_O_THR - int :
times to be active within STILL_T_THR to be still active.
Default = 2
entry 12: DROP_H_THR - int:
Default = 2
entry 13: DROP_I_THR - int:
Default = 1
(Currently these values will be default values,
in the future, the user might be able to adjust these)
act_param : dict[str, int]
parameters for activity types:
keys are listed below
- INT_THR : int
minimum number of interactions to be active
- UW_DEG_THR : int
minimum number of connections to be active
- EDGE_STR_THR : int
minimum number of interactions for connected
- UW_THR_DEG_THR : int
minimum number of accounts for connected
- CON_T_THR : int
time period to assess consistently active
- CON_O_THR : int
times to be active within CON_T_THR to be
consistently active
- VITAL_T_THR : int
time period to assess for vital
- VITAL_O_THR : int
times to be connected within VITAL_T_THR to be vital
- PAUSED_T_THR : int
time period to remain paused
- STILL_T_THR : int
time period to assess for still active
- STILL_O_THR : int
times to be active within STILL_T_THR to be still active
- DROP_H_THR : int
time periods in the past to have been newly active
- DROP_I_THR : int
time periods to have been inactive

Output
network_dict: {datetime:networkx obj} -
Expand Down
34 changes: 19 additions & 15 deletions discord_analyzer/analyzer/analyzer_memberactivities.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import logging
from datetime import datetime, timedelta

from discord_analyzer.analysis.compute_member_activity import compute_member_activity
Expand All @@ -6,11 +7,9 @@
from discord_analyzer.models.RawInfoModel import RawInfoModel


class Member_activities:
def __init__(self, DB_connections, logging) -> None:
class MemberActivities:
def __init__(self, DB_connections) -> None:
self.DB_connections = DB_connections
self.logging = logging

self.utils = MemberActivityUtils(DB_connections)

def analysis_member_activity(self, guildId, mongo_connection_str, from_start=False):
Expand Down Expand Up @@ -43,17 +42,17 @@ def analysis_member_activity(self, guildId, mongo_connection_str, from_start=Fal

# check current guild is exist
if guildId not in client.list_database_names():
self.logging.error(f"{guild_msg} Database {guildId} doesn't exist")
self.logging.error(f"{guild_msg} No such databse!")
self.logging.info(f"{guild_msg} Continuing")
logging.error(f"{guild_msg} Database {guildId} doesn't exist")
logging.error(f"{guild_msg} No such databse!")
logging.info(f"{guild_msg} Continuing")
return (None, None)

member_activity_c = MemberActivityModel(client[guildId])
rawinfo_c = RawInfoModel(client[guildId])

# Testing if there are entries in the rawinfo collection
if rawinfo_c.count() == 0:
self.logging.warning(
logging.warning(
f"No entries in the collection 'rawinfos' in {guildId} databse"
)
return (None, None)
Expand All @@ -76,7 +75,7 @@ def analysis_member_activity(self, guildId, mongo_connection_str, from_start=Fal
# get date range to be analyzed
today = datetime.now().replace(hour=0, minute=0, second=0, microsecond=0)

self.logging.info(f"{guild_msg} memberactivities Analysis started!")
logging.info(f"{guild_msg} memberactivities Analysis started!")

# initialize
load_past_data = False
Expand All @@ -93,19 +92,24 @@ def analysis_member_activity(self, guildId, mongo_connection_str, from_start=Fal

first_date = period
if first_date is None:
self.logging.error(f"No guild: {guildId} available in RnDAO.guilds!")
logging.error(f"No guild: {guildId} available in RnDAO.guilds!")
return None, None

last_date = today - timedelta(days=1)

date_range = [first_date, last_date]

if load_past_data:
# num_days_to_load = (
# max([CON_T_THR, VITAL_T_THR, STILL_T_THR, PAUSED_T_THR])+1
# ) * WINDOW_D
num_days_to_load = (
max([action[3], action[7], action[9], action[2]]) + 1
max(
[
action["CON_T_THR"],
action["VITAL_T_THR"],
action["STILL_T_THR"],
action["PAUSED_T_THR"],
]
)
+ 1
) * window[0]
date_range[0] = date_range[1] - timedelta(days=num_days_to_load)

Expand All @@ -125,7 +129,7 @@ def analysis_member_activity(self, guildId, mongo_connection_str, from_start=Fal
date_range,
window,
action,
logging=self.logging,
logging=logging,
load_past_data=load_past_data,
)

Expand Down
10 changes: 3 additions & 7 deletions discord_analyzer/rn_analyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import sys

from discord_analyzer.analyzer.analyzer_heatmaps import Heatmaps
from discord_analyzer.analyzer.analyzer_memberactivities import Member_activities
from discord_analyzer.analyzer.analyzer_memberactivities import MemberActivities
from discord_analyzer.analyzer.base_analyzer import Base_analyzer
from discord_analyzer.analyzer.neo4j_analytics import Neo4JAnalytics
from discord_analyzer.models.GuildsRnDaoModel import GuildsRnDaoModel
Expand Down Expand Up @@ -70,9 +70,7 @@ def run_once(self, guildId):
remove_heatmaps=False,
)

memberactivities_analysis = Member_activities(
self.DB_connections, logging=logging
)
memberactivities_analysis = MemberActivities(self.DB_connections)
(
member_activities_data,
member_acitivities_networkx_data,
Expand Down Expand Up @@ -213,9 +211,7 @@ def recompute_analytics(self, guildId):

# run the member_activity analyze
logging.info(f"Analyzing the MemberActivities data for guild: {guildId}!")
memberactivity_analysis = Member_activities(
self.DB_connections, logging=logging
)
memberactivity_analysis = MemberActivities(self.DB_connections)
(
member_activities_data,
member_acitivities_networkx_data,
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ tc-messageBroker==1.4.0
sentry-sdk
rq
redis
tc-core-analyzer-lib==1.0.2
tc-core-analyzer-lib==1.1.0
tc-neo4j-lib==1.0.0
pybars3
17 changes: 16 additions & 1 deletion tests/integration/utils/remove_and_setup_guild.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,21 @@ def setup_db_guild(
db_access.db_mongo_client["RnDAO"]["guilds"].delete_one({"guildId": guildId})
db_access.db_mongo_client.drop_database(guildId)

action = {
"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,
}
db_access.db_mongo_client["RnDAO"]["guilds"].insert_one(
{
"guildId": guildId,
Expand All @@ -34,7 +49,7 @@ def setup_db_guild(
"isDisconnected": False,
"icon": "afd0d06fd12b2905c53708ca742e6c66",
"window": [7, 1],
"action": [1, 1, 1, 4, 3, 5, 5, 4, 3, 3, 2, 2, 1],
"action": action,
"selectedChannels": [
{
"channelId": "1020707129214111827",
Expand Down