diff --git a/.github/workflows/production.yml b/.github/workflows/production.yml index a1be27b..de44b12 100644 --- a/.github/workflows/production.yml +++ b/.github/workflows/production.yml @@ -9,4 +9,29 @@ jobs: ci: uses: TogetherCrew/operations/.github/workflows/ci.yml@main secrets: - CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }} \ No newline at end of file + CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }} + package_publish: + needs: ci + runs-on: ubuntu-latest + strategy: + matrix: + python-version: ["3.10"] + steps: + - uses: actions/checkout@v3 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v4 + with: + python-version: ${{ matrix.python-version }} + + - name: Install dependencies + run: | + python -m pip install --upgrade pip setuptools wheel twine + - name: Build package + run: | + python setup.py sdist bdist_wheel + - name: Publish package to PyPI + env: + TWINE_USERNAME: __token__ + TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }} + run: | + python -m twine upload dist/* \ No newline at end of file diff --git a/analyzer_init.py b/analyzer_init.py deleted file mode 100644 index d29bf46..0000000 --- a/analyzer_init.py +++ /dev/null @@ -1,34 +0,0 @@ -from typing import Any - -from discord_analyzer.tc_analyzer import TCAnalyzer - - -class AnalyzerInit: - """ - initialize the analyzer with its configs - """ - - # TODO: update to platform_id as input - def __init__(self, guild_id: str) -> None: - self.guild_id = guild_id - - def get_analyzer(self) -> TCAnalyzer: - """ - Returns: - --------- - analyzer : TCAnalyzer - """ - analyzer = TCAnalyzer(self.guild_id) - analyzer.database_connect() - - return analyzer - - def _get_mongo_connection(self, mongo_creds: dict[str, Any]): - user = mongo_creds["user"] - password = mongo_creds["password"] - host = mongo_creds["host"] - port = mongo_creds["port"] - - connection = f"mongodb://{user}:{password}@{host}:{port}" - - return connection diff --git a/discord_utils.py b/discord_utils.py deleted file mode 100644 index b21d8c9..0000000 --- a/discord_utils.py +++ /dev/null @@ -1,117 +0,0 @@ -import logging - -from analyzer_init import AnalyzerInit -from automation.automation_workflow import AutomationWorkflow -from tc_messageBroker.rabbit_mq.saga.saga_base import get_saga -from utils.credentials import get_mongo_credentials -from utils.get_guild_utils import get_platform_guild_id, get_platform_name -from utils.rabbitmq import RabbitMQSingleton -from utils.transactions_ordering import sort_transactions - - -def analyzer_recompute(sagaId: str): - saga = get_saga_instance(sagaId=sagaId) - if saga is None: - logging.warn( - f"Warn: Saga not found!, stopping the recompute for sagaId: {sagaId}" - ) - else: - platform_id = saga.data["platformId"] - guildId = get_platform_guild_id(platform_id) - - logging.info("Initializing the analyzer") - analyzer_init = AnalyzerInit(guildId) - analyzer = analyzer_init.get_analyzer() - logging.info("Analyzer initialized") - - def recompute_wrapper(**kwargs): - logging.info("recompute wrapper") - analyzer.recompute_analytics() - - def publish_wrapper(**kwargs): - pass - - logging.info("Calling the saga.next()") - saga.next( - publish_method=publish_wrapper, - call_function=recompute_wrapper, - ) - - return sagaId - - -def analyzer_run_once(sagaId: str): - saga = get_saga_instance(sagaId=sagaId) - if saga is None: - logging.warn(f"Saga not found!, stopping the run_once for sagaId: {sagaId}") - else: - platform_id = saga.data["platformId"] - guildId = get_platform_guild_id(platform_id) - - analyzer_init = AnalyzerInit(guildId) - analyzer = analyzer_init.get_analyzer() - - def run_once_wrapper(**kwargs): - analyzer.run_once() - - def publish_wrapper(**kwargs): - pass - - saga.next( - publish_method=publish_wrapper, - call_function=run_once_wrapper, - ) - return sagaId - - -def get_saga_instance(sagaId: str): - mongo_creds = get_mongo_credentials() - - saga = get_saga( - sagaId=sagaId, - connection_url=mongo_creds["connection_str"], - db_name="Saga", - collection="sagas", - ) - if saga is None: - raise ValueError(f"Saga with sagaId: {sagaId} not found!") - - return saga - - -def publish_on_success(connection, result, *args, **kwargs): - try: - sagaId = args[0] - logging.info(f"SAGAID: {sagaId}: ON_SUCCESS callback!") - - saga = get_saga_instance(sagaId=sagaId) - rabbitmq = RabbitMQSingleton.get_instance().get_client() - - transactions = saga.choreography.transactions - - (transactions_ordered, tx_not_started_count) = sort_transactions(transactions) - - platform_id = saga.data["platformId"] - - msg = f"PLATFORMID: {platform_id}: " - if tx_not_started_count != 0: - tx = transactions_ordered[0] - - logging.info(f"{msg}Publishing for {tx.queue}") - - rabbitmq.connect(tx.queue) - rabbitmq.publish( - queue_name=tx.queue, - event=tx.event, - content={"uuid": sagaId, "data": saga.data}, - ) - - guildId = get_platform_guild_id(platform_id) - platform_name = get_platform_name(platform_id) - # working specifically for discord - if platform_name == "discord": - automation_workflow = AutomationWorkflow() - automation_workflow.start(guild_id=guildId, platform_id=platform_id) - - except Exception as exp: - logging.info(f"Exception occured in job on_success callback: {exp}") diff --git a/docker-compose.test.yml b/docker-compose.test.yml index 3bd3a37..6c70063 100644 --- a/docker-compose.test.yml +++ b/docker-compose.test.yml @@ -42,6 +42,7 @@ services: condition: service_healthy mongo: image: "mongo:6.0.8" + restart: always attach: false environment: - MONGO_INITDB_ROOT_USERNAME=root @@ -54,6 +55,7 @@ services: start_period: 40s neo4j: image: "neo4j:5.9.0" + restart: always attach: false environment: - NEO4J_AUTH=neo4j/password @@ -67,6 +69,7 @@ services: start_period: 40s rabbitmq: image: "rabbitmq:3-management-alpine" + restart: always environment: - RABBITMQ_DEFAULT_USER=root - RABBITMQ_DEFAULT_PASS=pass diff --git a/requirements.txt b/requirements.txt index 4389aba..b778b21 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,11 +2,9 @@ attrs==22.2.0 dnspython==2.2.1 exceptiongroup==1.1.0 iniconfig==2.0.0 -numpy==1.24.1 packaging==23.0 pluggy==1.0.0 pymongo==4.3.3 -pytest==7.2.0 python-dateutil==2.8.2 pytz==2022.7.1 python-dotenv>=1.0.0 @@ -14,8 +12,6 @@ six==1.16.0 tomli==2.0.1 networkx==3.1 requests==2.29.0 -pytest-cov==4.0.0 -coverage==7.2.5 python-dateutil==2.8.2 tqdm tc-messageBroker==1.6.7 @@ -23,6 +19,6 @@ sentry-sdk rq redis tc-core-analyzer-lib==1.3.1 -tc-neo4j-lib==2.0.0 +tc-neo4j-lib==2.0.1 pybars3 backoff==2.2.1 diff --git a/server.py b/server.py deleted file mode 100644 index 830e01f..0000000 --- a/server.py +++ /dev/null @@ -1,74 +0,0 @@ -""" -start the project using rabbitMQ -""" - -import functools -import logging -from typing import Any - -import backoff -from discord_utils import analyzer_recompute, analyzer_run_once, publish_on_success -from pika.exceptions import AMQPConnectionError, ConnectionClosedByBroker -from rq import Queue as RQ_Queue -from tc_messageBroker.rabbit_mq.event import Event -from tc_messageBroker.rabbit_mq.queue import Queue -from utils.rabbitmq import RabbitMQSingleton -from utils.redis import RedisSingleton -from utils.sentryio_service import set_up_sentryio - - -@backoff.on_exception( - wait_gen=backoff.expo, - exception=(ConnectionClosedByBroker, ConnectionError, AMQPConnectionError), - # waiting for 3 hours - max_time=60 * 60 * 3, -) -def analyzer(): - # sentryio service - set_up_sentryio() - rabbit_mq = RabbitMQSingleton.get_instance().get_client() - redis = RedisSingleton.get_instance().get_client() - - # 24 hours equal to 86400 seconds - rq_queue = RQ_Queue(connection=redis, default_timeout=86400) - - analyzer_recompute = functools.partial(recompute_wrapper, redis_queue=rq_queue) - analyzer_run_once = functools.partial(run_once_wrapper, redis_queue=rq_queue) - - rabbit_mq.connect(Queue.DISCORD_ANALYZER, heartbeat=60) - - rabbit_mq.on_event(Event.DISCORD_ANALYZER.RUN, analyzer_recompute) - rabbit_mq.on_event(Event.DISCORD_ANALYZER.RUN_ONCE, analyzer_run_once) - - if rabbit_mq.channel is None: - raise ConnectionError("Couldn't connect to rmq server!") - else: - logging.info("Started Consuming!") - rabbit_mq.channel.start_consuming() - - -def recompute_wrapper(body: dict[str, Any], redis_queue: RQ_Queue): - sagaId = body["content"]["uuid"] - logging.info(f"SAGAID:{sagaId} recompute job Adding to queue") - - redis_queue.enqueue( - analyzer_recompute, - sagaId=sagaId, - on_success=publish_on_success, - ) - - -def run_once_wrapper(body: dict[str, Any], redis_queue: RQ_Queue): - sagaId = body["content"]["uuid"] - logging.info(f"SAGAID:{sagaId} run_once job Adding to queue") - redis_queue.enqueue( - analyzer_run_once, - sagaId=sagaId, - on_success=publish_on_success, - ) - - -if __name__ == "__main__": - logging.basicConfig() - logging.getLogger().setLevel(logging.INFO) - analyzer() diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..f773acf --- /dev/null +++ b/setup.py @@ -0,0 +1,17 @@ +from setuptools import find_packages, setup + +with open("requirements.txt") as f: + requirements = f.read().splitlines() + + +setup( + name="tc-analyzer-lib", + version="1.0.0", + author="Mohammad Amin Dadgar, TogetherCrew", + maintainer="Mohammad Amin Dadgar", + maintainer_email="dadgaramin96@gmail.com", + packages=find_packages(), + description="A platform agnostic analyzer, computing the TogetherCrew dashboard metrics.", + long_description=open("README.md").read(), + install_requires=requirements, +) diff --git a/automation/__init__.py b/tc_analyzer_lib/DB_operations/__init__.py similarity index 100% rename from automation/__init__.py rename to tc_analyzer_lib/DB_operations/__init__.py diff --git a/discord_analyzer/DB_operations/mongo_neo4j_ops.py b/tc_analyzer_lib/DB_operations/mongo_neo4j_ops.py similarity index 96% rename from discord_analyzer/DB_operations/mongo_neo4j_ops.py rename to tc_analyzer_lib/DB_operations/mongo_neo4j_ops.py index 2232506..02a0598 100644 --- a/discord_analyzer/DB_operations/mongo_neo4j_ops.py +++ b/tc_analyzer_lib/DB_operations/mongo_neo4j_ops.py @@ -1,9 +1,9 @@ import logging -from discord_analyzer.DB_operations.mongodb_interaction import MongoDBOps -from discord_analyzer.DB_operations.network_graph import NetworkGraph +from tc_analyzer_lib.DB_operations.mongodb_interaction import MongoDBOps +from tc_analyzer_lib.DB_operations.network_graph import NetworkGraph +from tc_analyzer_lib.schemas import GraphSchema from tc_neo4j_lib.neo4j_ops import Neo4jOps, Query -from discord_analyzer.schemas import GraphSchema class MongoNeo4jDB: diff --git a/discord_analyzer/DB_operations/mongodb_access.py b/tc_analyzer_lib/DB_operations/mongodb_access.py similarity index 98% rename from discord_analyzer/DB_operations/mongodb_access.py rename to tc_analyzer_lib/DB_operations/mongodb_access.py index 2427159..4d1b440 100644 --- a/discord_analyzer/DB_operations/mongodb_access.py +++ b/tc_analyzer_lib/DB_operations/mongodb_access.py @@ -1,4 +1,4 @@ -from utils.mongo import MongoSingleton +from tc_analyzer_lib.utils.mongo import MongoSingleton class DB_access: diff --git a/discord_analyzer/DB_operations/mongodb_interaction.py b/tc_analyzer_lib/DB_operations/mongodb_interaction.py similarity index 99% rename from discord_analyzer/DB_operations/mongodb_interaction.py rename to tc_analyzer_lib/DB_operations/mongodb_interaction.py index f0d9ffe..9ef5cb4 100644 --- a/discord_analyzer/DB_operations/mongodb_interaction.py +++ b/tc_analyzer_lib/DB_operations/mongodb_interaction.py @@ -1,8 +1,8 @@ import logging -from discord_analyzer.DB_operations.mongodb_access import DB_access from pymongo.read_concern import ReadConcern from pymongo.write_concern import WriteConcern +from tc_analyzer_lib.DB_operations.mongodb_access import DB_access class MongoDBOps: diff --git a/discord_analyzer/DB_operations/network_graph.py b/tc_analyzer_lib/DB_operations/network_graph.py similarity index 99% rename from discord_analyzer/DB_operations/network_graph.py rename to tc_analyzer_lib/DB_operations/network_graph.py index 11e5f62..43a6888 100644 --- a/discord_analyzer/DB_operations/network_graph.py +++ b/tc_analyzer_lib/DB_operations/network_graph.py @@ -3,8 +3,8 @@ import datetime import networkx +from tc_analyzer_lib.schemas import GraphSchema from tc_neo4j_lib import Query -from discord_analyzer.schemas import GraphSchema class NetworkGraph: diff --git a/discord_analyzer/__init__.py b/tc_analyzer_lib/__init__.py similarity index 100% rename from discord_analyzer/__init__.py rename to tc_analyzer_lib/__init__.py diff --git a/discord_analyzer/algorithms/__init__.py b/tc_analyzer_lib/algorithms/__init__.py similarity index 100% rename from discord_analyzer/algorithms/__init__.py rename to tc_analyzer_lib/algorithms/__init__.py diff --git a/discord_analyzer/algorithms/analytics_interactions_script.py b/tc_analyzer_lib/algorithms/analytics_interactions_script.py similarity index 100% rename from discord_analyzer/algorithms/analytics_interactions_script.py rename to tc_analyzer_lib/algorithms/analytics_interactions_script.py diff --git a/discord_analyzer/algorithms/compute_interaction_matrix_discord.py b/tc_analyzer_lib/algorithms/compute_interaction_matrix_discord.py similarity index 95% rename from discord_analyzer/algorithms/compute_interaction_matrix_discord.py rename to tc_analyzer_lib/algorithms/compute_interaction_matrix_discord.py index 8a1e805..e280e5d 100644 --- a/discord_analyzer/algorithms/compute_interaction_matrix_discord.py +++ b/tc_analyzer_lib/algorithms/compute_interaction_matrix_discord.py @@ -1,10 +1,10 @@ import copy -from typing import Any from datetime import datetime +from typing import Any from numpy import diag_indices_from, ndarray +from tc_analyzer_lib.utils.mongo import MongoSingleton -from utils.mongo import MongoSingleton from .utils.compute_interaction_mtx_utils import ( generate_interaction_matrix, prepare_per_account, diff --git a/discord_analyzer/algorithms/compute_member_activity.py b/tc_analyzer_lib/algorithms/compute_member_activity.py similarity index 94% rename from discord_analyzer/algorithms/compute_member_activity.py rename to tc_analyzer_lib/algorithms/compute_member_activity.py index 504e34c..574ebc1 100644 --- a/discord_analyzer/algorithms/compute_member_activity.py +++ b/tc_analyzer_lib/algorithms/compute_member_activity.py @@ -11,11 +11,11 @@ import networkx as nx import numpy as np from dateutil.relativedelta import relativedelta -from discord_analyzer.algorithms.member_activity_history import check_past_history -from discord_analyzer.algorithms.utils.member_activity_history_utils import ( +from tc_analyzer_lib.algorithms.member_activity_history import check_past_history +from tc_analyzer_lib.algorithms.utils.member_activity_history_utils import ( MemberActivityPastUtils, ) -from discord_analyzer.algorithms.utils.member_activity_utils import ( +from tc_analyzer_lib.algorithms.utils.member_activity_utils import ( assess_engagement, convert_to_dict, get_joined_accounts, @@ -24,8 +24,8 @@ store_based_date, update_activities, ) -from discord_analyzer.DB_operations.mongodb_access import DB_access -from discord_analyzer.schemas.platform_configs.config_base import PlatformConfigBase +from tc_analyzer_lib.DB_operations.mongodb_access import DB_access +from tc_analyzer_lib.schemas.platform_configs.config_base import PlatformConfigBase def compute_member_activity( diff --git a/discord_analyzer/algorithms/member_activity_history.py b/tc_analyzer_lib/algorithms/member_activity_history.py similarity index 96% rename from discord_analyzer/algorithms/member_activity_history.py rename to tc_analyzer_lib/algorithms/member_activity_history.py index 130a24e..c26486f 100644 --- a/discord_analyzer/algorithms/member_activity_history.py +++ b/tc_analyzer_lib/algorithms/member_activity_history.py @@ -2,10 +2,10 @@ from datetime import datetime, timedelta -from discord_analyzer.algorithms.utils.member_activity_history_utils import ( +from tc_analyzer_lib.algorithms.utils.member_activity_history_utils import ( MemberActivityPastUtils, ) -from discord_analyzer.DB_operations.mongodb_access import DB_access +from tc_analyzer_lib.DB_operations.mongodb_access import DB_access # the main script function diff --git a/automation/utils/__init__.py b/tc_analyzer_lib/algorithms/neo4j_analysis/__init__.py similarity index 100% rename from automation/utils/__init__.py rename to tc_analyzer_lib/algorithms/neo4j_analysis/__init__.py diff --git a/discord_analyzer/algorithms/neo4j_analysis/analyzer_node_stats.py b/tc_analyzer_lib/algorithms/neo4j_analysis/analyzer_node_stats.py similarity index 98% rename from discord_analyzer/algorithms/neo4j_analysis/analyzer_node_stats.py rename to tc_analyzer_lib/algorithms/neo4j_analysis/analyzer_node_stats.py index 2786894..ff6cc5a 100644 --- a/discord_analyzer/algorithms/neo4j_analysis/analyzer_node_stats.py +++ b/tc_analyzer_lib/algorithms/neo4j_analysis/analyzer_node_stats.py @@ -3,8 +3,8 @@ from uuid import uuid1 import pandas as pd -from discord_analyzer.algorithms.neo4j_analysis.utils import ProjectionUtils -from discord_analyzer.schemas import GraphSchema +from tc_analyzer_lib.algorithms.neo4j_analysis.utils import ProjectionUtils +from tc_analyzer_lib.schemas import GraphSchema from tc_neo4j_lib.neo4j_ops import Neo4jOps @@ -42,7 +42,6 @@ def __init__( self.projection_utils = ProjectionUtils(self.platform_id, self.graph_schema) def compute_stats(self, from_start: bool) -> None: - # possible dates to do the computations possible_dates = self.projection_utils.get_dates() diff --git a/discord_analyzer/algorithms/neo4j_analysis/centrality.py b/tc_analyzer_lib/algorithms/neo4j_analysis/centrality.py similarity index 99% rename from discord_analyzer/algorithms/neo4j_analysis/centrality.py rename to tc_analyzer_lib/algorithms/neo4j_analysis/centrality.py index 2b806d6..ede8762 100644 --- a/discord_analyzer/algorithms/neo4j_analysis/centrality.py +++ b/tc_analyzer_lib/algorithms/neo4j_analysis/centrality.py @@ -2,11 +2,11 @@ from typing import Literal import pandas as pd -from discord_analyzer.algorithms.neo4j_analysis.utils import ( +from tc_analyzer_lib.algorithms.neo4j_analysis.utils import ( Neo4JMetrics, ProjectionUtils, ) -from discord_analyzer.schemas import GraphSchema +from tc_analyzer_lib.schemas import GraphSchema from tc_neo4j_lib.neo4j_ops import Neo4jOps, Query diff --git a/discord_analyzer/algorithms/neo4j_analysis/local_clustering_coefficient.py b/tc_analyzer_lib/algorithms/neo4j_analysis/local_clustering_coefficient.py similarity index 97% rename from discord_analyzer/algorithms/neo4j_analysis/local_clustering_coefficient.py rename to tc_analyzer_lib/algorithms/neo4j_analysis/local_clustering_coefficient.py index dc6ae5d..2323851 100644 --- a/discord_analyzer/algorithms/neo4j_analysis/local_clustering_coefficient.py +++ b/tc_analyzer_lib/algorithms/neo4j_analysis/local_clustering_coefficient.py @@ -1,8 +1,8 @@ import logging from uuid import uuid1 -from discord_analyzer.algorithms.neo4j_analysis.utils import ProjectionUtils -from discord_analyzer.schemas import GraphSchema +from tc_analyzer_lib.algorithms.neo4j_analysis.utils import ProjectionUtils +from tc_analyzer_lib.schemas import GraphSchema from tc_neo4j_lib import Neo4jOps diff --git a/discord_analyzer/algorithms/neo4j_analysis/louvain.py b/tc_analyzer_lib/algorithms/neo4j_analysis/louvain.py similarity index 97% rename from discord_analyzer/algorithms/neo4j_analysis/louvain.py rename to tc_analyzer_lib/algorithms/neo4j_analysis/louvain.py index 8d72edc..8a00ddf 100644 --- a/discord_analyzer/algorithms/neo4j_analysis/louvain.py +++ b/tc_analyzer_lib/algorithms/neo4j_analysis/louvain.py @@ -1,8 +1,8 @@ import logging from uuid import uuid1 -from discord_analyzer.algorithms.neo4j_analysis.utils import ProjectionUtils -from discord_analyzer.schemas import GraphSchema +from tc_analyzer_lib.algorithms.neo4j_analysis.utils import ProjectionUtils +from tc_analyzer_lib.schemas import GraphSchema from tc_neo4j_lib.neo4j_ops import Neo4jOps diff --git a/discord_analyzer/algorithms/neo4j_analysis/utils/__init__.py b/tc_analyzer_lib/algorithms/neo4j_analysis/utils/__init__.py similarity index 100% rename from discord_analyzer/algorithms/neo4j_analysis/utils/__init__.py rename to tc_analyzer_lib/algorithms/neo4j_analysis/utils/__init__.py diff --git a/discord_analyzer/algorithms/neo4j_analysis/utils/neo4j_metrics.py b/tc_analyzer_lib/algorithms/neo4j_analysis/utils/neo4j_metrics.py similarity index 100% rename from discord_analyzer/algorithms/neo4j_analysis/utils/neo4j_metrics.py rename to tc_analyzer_lib/algorithms/neo4j_analysis/utils/neo4j_metrics.py diff --git a/discord_analyzer/algorithms/neo4j_analysis/utils/projection_utils.py b/tc_analyzer_lib/algorithms/neo4j_analysis/utils/projection_utils.py similarity index 99% rename from discord_analyzer/algorithms/neo4j_analysis/utils/projection_utils.py rename to tc_analyzer_lib/algorithms/neo4j_analysis/utils/projection_utils.py index 7378263..3f8bd9f 100644 --- a/discord_analyzer/algorithms/neo4j_analysis/utils/projection_utils.py +++ b/tc_analyzer_lib/algorithms/neo4j_analysis/utils/projection_utils.py @@ -1,6 +1,6 @@ import logging -from discord_analyzer.schemas import GraphSchema +from tc_analyzer_lib.schemas import GraphSchema from tc_neo4j_lib.neo4j_ops import Neo4jOps diff --git a/discord_analyzer/DB_operations/__init__.py b/tc_analyzer_lib/algorithms/utils/__init__.py similarity index 100% rename from discord_analyzer/DB_operations/__init__.py rename to tc_analyzer_lib/algorithms/utils/__init__.py diff --git a/discord_analyzer/algorithms/utils/activity.py b/tc_analyzer_lib/algorithms/utils/activity.py similarity index 100% rename from discord_analyzer/algorithms/utils/activity.py rename to tc_analyzer_lib/algorithms/utils/activity.py diff --git a/discord_analyzer/algorithms/utils/compute_interaction_mtx_utils.py b/tc_analyzer_lib/algorithms/utils/compute_interaction_mtx_utils.py similarity index 97% rename from discord_analyzer/algorithms/utils/compute_interaction_mtx_utils.py rename to tc_analyzer_lib/algorithms/utils/compute_interaction_mtx_utils.py index 540cd20..7cdd01b 100644 --- a/discord_analyzer/algorithms/utils/compute_interaction_mtx_utils.py +++ b/tc_analyzer_lib/algorithms/utils/compute_interaction_mtx_utils.py @@ -2,7 +2,7 @@ from typing import Any import numpy as np -from discord_analyzer.algorithms.analytics_interactions_script import ( +from tc_analyzer_lib.algorithms.analytics_interactions_script import ( per_account_interactions, ) diff --git a/discord_analyzer/algorithms/utils/member_activity_history_utils.py b/tc_analyzer_lib/algorithms/utils/member_activity_history_utils.py similarity index 99% rename from discord_analyzer/algorithms/utils/member_activity_history_utils.py rename to tc_analyzer_lib/algorithms/utils/member_activity_history_utils.py index 524f574..cff4f9d 100644 --- a/discord_analyzer/algorithms/utils/member_activity_history_utils.py +++ b/tc_analyzer_lib/algorithms/utils/member_activity_history_utils.py @@ -2,9 +2,8 @@ from datetime import datetime, timedelta from typing import Any -from dateutil import parser -from discord_analyzer.DB_operations.mongodb_access import DB_access from numpy import array +from tc_analyzer_lib.DB_operations.mongodb_access import DB_access class MemberActivityPastUtils: diff --git a/discord_analyzer/algorithms/utils/member_activity_utils.py b/tc_analyzer_lib/algorithms/utils/member_activity_utils.py similarity index 97% rename from discord_analyzer/algorithms/utils/member_activity_utils.py rename to tc_analyzer_lib/algorithms/utils/member_activity_utils.py index e0a6ee9..10a51ea 100644 --- a/discord_analyzer/algorithms/utils/member_activity_utils.py +++ b/tc_analyzer_lib/algorithms/utils/member_activity_utils.py @@ -4,12 +4,12 @@ import numpy as np import pymongo -from discord_analyzer.algorithms.compute_interaction_matrix_discord import ( +from networkx import DiGraph +from tc_analyzer_lib.algorithms.compute_interaction_matrix_discord import ( compute_interaction_matrix_discord, ) -from discord_analyzer.DB_operations.mongodb_access import DB_access -from discord_analyzer.schemas.platform_configs.config_base import PlatformConfigBase -from networkx import DiGraph +from tc_analyzer_lib.DB_operations.mongodb_access import DB_access +from tc_analyzer_lib.schemas.platform_configs.config_base import PlatformConfigBase from tc_core_analyzer_lib.assess_engagement import EngagementAssessment diff --git a/discord_analyzer/algorithms/neo4j_analysis/__init__.py b/tc_analyzer_lib/automation/__init__.py similarity index 100% rename from discord_analyzer/algorithms/neo4j_analysis/__init__.py rename to tc_analyzer_lib/automation/__init__.py diff --git a/automation/automation_workflow.py b/tc_analyzer_lib/automation/automation_workflow.py similarity index 98% rename from automation/automation_workflow.py rename to tc_analyzer_lib/automation/automation_workflow.py index 1da733d..8f2b5da 100644 --- a/automation/automation_workflow.py +++ b/tc_analyzer_lib/automation/automation_workflow.py @@ -1,9 +1,9 @@ import logging from typing import Any -from automation.utils.automation_base import AutomationBase -from automation.utils.model import AutomationDB from pybars import Compiler +from tc_analyzer_lib.automation.utils.automation_base import AutomationBase +from tc_analyzer_lib.automation.utils.model import AutomationDB from tc_messageBroker.rabbit_mq.event import Event from tc_messageBroker.rabbit_mq.queue import Queue diff --git a/discord_analyzer/algorithms/utils/__init__.py b/tc_analyzer_lib/automation/utils/__init__.py similarity index 100% rename from discord_analyzer/algorithms/utils/__init__.py rename to tc_analyzer_lib/automation/utils/__init__.py diff --git a/automation/utils/automation_base.py b/tc_analyzer_lib/automation/utils/automation_base.py similarity index 97% rename from automation/utils/automation_base.py rename to tc_analyzer_lib/automation/utils/automation_base.py index bfd0d34..54e2164 100644 --- a/automation/utils/automation_base.py +++ b/tc_analyzer_lib/automation/utils/automation_base.py @@ -2,8 +2,8 @@ from typing import Any from uuid import uuid1 -from utils.mongo import MongoSingleton -from utils.rabbitmq import RabbitMQSingleton +from tc_analyzer_lib.utils.mongo import MongoSingleton +from tc_analyzer_lib.utils.rabbitmq import RabbitMQAccess class AutomationBase: @@ -12,7 +12,7 @@ def __init__(self) -> None: utilities for automation workflow """ self.mongo_client = MongoSingleton.get_instance().get_client() - self.rabbitmq = RabbitMQSingleton.get_instance().get_client() + self.rabbitmq = RabbitMQAccess.get_instance().get_client() def _get_users_from_guildmembers( self, guild_id: str, user_ids: list[str], strategy: str = "ngu" diff --git a/automation/utils/interfaces.py b/tc_analyzer_lib/automation/utils/interfaces.py similarity index 100% rename from automation/utils/interfaces.py rename to tc_analyzer_lib/automation/utils/interfaces.py diff --git a/automation/utils/model.py b/tc_analyzer_lib/automation/utils/model.py similarity index 93% rename from automation/utils/model.py rename to tc_analyzer_lib/automation/utils/model.py index 1f4dc09..3eded62 100644 --- a/automation/utils/model.py +++ b/tc_analyzer_lib/automation/utils/model.py @@ -1,5 +1,5 @@ -from utils.get_automation_env import get_automations_env -from utils.mongo import MongoSingleton +from tc_analyzer_lib.utils.get_automation_env import get_automations_env +from tc_analyzer_lib.utils.mongo import MongoSingleton from .interfaces import Automation diff --git a/discord_analyzer/metrics/__init__.py b/tc_analyzer_lib/metrics/__init__.py similarity index 100% rename from discord_analyzer/metrics/__init__.py rename to tc_analyzer_lib/metrics/__init__.py diff --git a/discord_analyzer/metrics/analyzer_memberactivities.py b/tc_analyzer_lib/metrics/analyzer_memberactivities.py similarity index 92% rename from discord_analyzer/metrics/analyzer_memberactivities.py rename to tc_analyzer_lib/metrics/analyzer_memberactivities.py index a61a580..976ad10 100644 --- a/discord_analyzer/metrics/analyzer_memberactivities.py +++ b/tc_analyzer_lib/metrics/analyzer_memberactivities.py @@ -1,12 +1,12 @@ import logging from datetime import datetime, timedelta -from discord_analyzer.algorithms.compute_member_activity import compute_member_activity -from discord_analyzer.metrics.memberactivity_utils import MemberActivityUtils -from discord_analyzer.models.MemberActivityModel import MemberActivityModel -from discord_analyzer.models.RawInfoModel import RawInfoModel -from discord_analyzer.schemas.platform_configs.config_base import PlatformConfigBase -from utils.mongo import MongoSingleton +from tc_analyzer_lib.algorithms.compute_member_activity import compute_member_activity +from tc_analyzer_lib.metrics.memberactivity_utils import MemberActivityUtils +from tc_analyzer_lib.models.MemberActivityModel import MemberActivityModel +from tc_analyzer_lib.models.RawInfoModel import RawInfoModel +from tc_analyzer_lib.schemas.platform_configs.config_base import PlatformConfigBase +from tc_analyzer_lib.utils.mongo import MongoSingleton class MemberActivities: diff --git a/discord_analyzer/metrics/heatmaps/__init__.py b/tc_analyzer_lib/metrics/heatmaps/__init__.py similarity index 100% rename from discord_analyzer/metrics/heatmaps/__init__.py rename to tc_analyzer_lib/metrics/heatmaps/__init__.py diff --git a/discord_analyzer/metrics/heatmaps/analytics_hourly.py b/tc_analyzer_lib/metrics/heatmaps/analytics_hourly.py similarity index 99% rename from discord_analyzer/metrics/heatmaps/analytics_hourly.py rename to tc_analyzer_lib/metrics/heatmaps/analytics_hourly.py index a8eaf41..cb848f2 100644 --- a/discord_analyzer/metrics/heatmaps/analytics_hourly.py +++ b/tc_analyzer_lib/metrics/heatmaps/analytics_hourly.py @@ -2,7 +2,7 @@ from typing import Any import numpy as np -from utils.mongo import MongoSingleton +from tc_analyzer_lib.utils.mongo import MongoSingleton class AnalyticsHourly: diff --git a/discord_analyzer/metrics/heatmaps/analytics_raw.py b/tc_analyzer_lib/metrics/heatmaps/analytics_raw.py similarity index 98% rename from discord_analyzer/metrics/heatmaps/analytics_raw.py rename to tc_analyzer_lib/metrics/heatmaps/analytics_raw.py index 729babd..9f7f1da 100644 --- a/discord_analyzer/metrics/heatmaps/analytics_raw.py +++ b/tc_analyzer_lib/metrics/heatmaps/analytics_raw.py @@ -2,8 +2,8 @@ from datetime import date, datetime, time, timedelta from typing import Any -from discord_analyzer.schemas import RawAnalyticsItem -from utils.mongo import MongoSingleton +from tc_analyzer_lib.schemas import RawAnalyticsItem +from tc_analyzer_lib.utils.mongo import MongoSingleton class AnalyticsRaw: diff --git a/discord_analyzer/metrics/heatmaps/heatmaps.py b/tc_analyzer_lib/metrics/heatmaps/heatmaps.py similarity index 96% rename from discord_analyzer/metrics/heatmaps/heatmaps.py rename to tc_analyzer_lib/metrics/heatmaps/heatmaps.py index ed46333..40a36f9 100644 --- a/discord_analyzer/metrics/heatmaps/heatmaps.py +++ b/tc_analyzer_lib/metrics/heatmaps/heatmaps.py @@ -1,10 +1,10 @@ import logging from datetime import date, datetime, timedelta -from discord_analyzer.metrics.heatmaps import AnalyticsHourly, AnalyticsRaw -from discord_analyzer.metrics.heatmaps.heatmaps_utils import HeatmapsUtils -from discord_analyzer.schemas.platform_configs.config_base import PlatformConfigBase -from utils.mongo import MongoSingleton +from tc_analyzer_lib.metrics.heatmaps import AnalyticsHourly, AnalyticsRaw +from tc_analyzer_lib.metrics.heatmaps.heatmaps_utils import HeatmapsUtils +from tc_analyzer_lib.schemas.platform_configs.config_base import PlatformConfigBase +from tc_analyzer_lib.utils.mongo import MongoSingleton class Heatmaps: diff --git a/discord_analyzer/metrics/heatmaps/heatmaps_utils.py b/tc_analyzer_lib/metrics/heatmaps/heatmaps_utils.py similarity index 97% rename from discord_analyzer/metrics/heatmaps/heatmaps_utils.py rename to tc_analyzer_lib/metrics/heatmaps/heatmaps_utils.py index 26cb34d..60abaf1 100644 --- a/discord_analyzer/metrics/heatmaps/heatmaps_utils.py +++ b/tc_analyzer_lib/metrics/heatmaps/heatmaps_utils.py @@ -1,7 +1,7 @@ from datetime import datetime from pymongo.cursor import Cursor -from utils.mongo import MongoSingleton +from tc_analyzer_lib.utils.mongo import MongoSingleton class HeatmapsUtils: diff --git a/discord_analyzer/metrics/memberactivity_utils.py b/tc_analyzer_lib/metrics/memberactivity_utils.py similarity index 98% rename from discord_analyzer/metrics/memberactivity_utils.py rename to tc_analyzer_lib/metrics/memberactivity_utils.py index 5d74cc1..0f3a41b 100644 --- a/discord_analyzer/metrics/memberactivity_utils.py +++ b/tc_analyzer_lib/metrics/memberactivity_utils.py @@ -1,7 +1,7 @@ import logging from dateutil import parser -from utils.mongo import MongoSingleton +from tc_analyzer_lib.utils.mongo import MongoSingleton class MemberActivityUtils: diff --git a/discord_analyzer/metrics/neo4j_analytics.py b/tc_analyzer_lib/metrics/neo4j_analytics.py similarity index 94% rename from discord_analyzer/metrics/neo4j_analytics.py rename to tc_analyzer_lib/metrics/neo4j_analytics.py index eae76bb..451615d 100644 --- a/discord_analyzer/metrics/neo4j_analytics.py +++ b/tc_analyzer_lib/metrics/neo4j_analytics.py @@ -1,13 +1,13 @@ # A wrapper to compute the neo4j metrics in cron-job import logging -from discord_analyzer.algorithms.neo4j_analysis.analyzer_node_stats import NodeStats -from discord_analyzer.algorithms.neo4j_analysis.centrality import Centerality -from discord_analyzer.algorithms.neo4j_analysis.local_clustering_coefficient import ( +from tc_analyzer_lib.algorithms.neo4j_analysis.analyzer_node_stats import NodeStats +from tc_analyzer_lib.algorithms.neo4j_analysis.centrality import Centerality +from tc_analyzer_lib.algorithms.neo4j_analysis.local_clustering_coefficient import ( LocalClusteringCoeff, ) -from discord_analyzer.algorithms.neo4j_analysis.louvain import Louvain -from discord_analyzer.schemas import GraphSchema +from tc_analyzer_lib.algorithms.neo4j_analysis.louvain import Louvain +from tc_analyzer_lib.schemas import GraphSchema from tc_neo4j_lib.neo4j_ops import Neo4jOps diff --git a/discord_analyzer/metrics/utils/__init__.py b/tc_analyzer_lib/metrics/utils/__init__.py similarity index 100% rename from discord_analyzer/metrics/utils/__init__.py rename to tc_analyzer_lib/metrics/utils/__init__.py diff --git a/discord_analyzer/metrics/utils/analyzer_db_manager.py b/tc_analyzer_lib/metrics/utils/analyzer_db_manager.py similarity index 81% rename from discord_analyzer/metrics/utils/analyzer_db_manager.py rename to tc_analyzer_lib/metrics/utils/analyzer_db_manager.py index 475ee38..96394b2 100644 --- a/discord_analyzer/metrics/utils/analyzer_db_manager.py +++ b/tc_analyzer_lib/metrics/utils/analyzer_db_manager.py @@ -1,4 +1,4 @@ -from discord_analyzer.DB_operations.mongo_neo4j_ops import MongoNeo4jDB +from tc_analyzer_lib.DB_operations.mongo_neo4j_ops import MongoNeo4jDB class AnalyzerDBManager: diff --git a/discord_analyzer/metrics/utils/platform.py b/tc_analyzer_lib/metrics/utils/platform.py similarity index 98% rename from discord_analyzer/metrics/utils/platform.py rename to tc_analyzer_lib/metrics/utils/platform.py index fde2f6c..5989a12 100644 --- a/discord_analyzer/metrics/utils/platform.py +++ b/tc_analyzer_lib/metrics/utils/platform.py @@ -1,7 +1,7 @@ -from bson import ObjectId from datetime import datetime -from utils.mongo import MongoSingleton +from bson import ObjectId +from tc_analyzer_lib.utils.mongo import MongoSingleton class Platform: diff --git a/discord_analyzer/models/BaseModel.py b/tc_analyzer_lib/models/BaseModel.py similarity index 100% rename from discord_analyzer/models/BaseModel.py rename to tc_analyzer_lib/models/BaseModel.py diff --git a/discord_analyzer/models/GuildsRnDaoModel.py b/tc_analyzer_lib/models/GuildsRnDaoModel.py similarity index 96% rename from discord_analyzer/models/GuildsRnDaoModel.py rename to tc_analyzer_lib/models/GuildsRnDaoModel.py index a1f9557..ae2e6cb 100644 --- a/discord_analyzer/models/GuildsRnDaoModel.py +++ b/tc_analyzer_lib/models/GuildsRnDaoModel.py @@ -1,6 +1,5 @@ -#!/usr/bin/env python3 -from discord_analyzer.models.BaseModel import BaseModel from pymongo.database import Database +from tc_analyzer_lib.models.BaseModel import BaseModel class GuildsRnDaoModel(BaseModel): diff --git a/discord_analyzer/models/HeatMapModel.py b/tc_analyzer_lib/models/HeatMapModel.py similarity index 97% rename from discord_analyzer/models/HeatMapModel.py rename to tc_analyzer_lib/models/HeatMapModel.py index afcba0e..4c7bf15 100644 --- a/discord_analyzer/models/HeatMapModel.py +++ b/tc_analyzer_lib/models/HeatMapModel.py @@ -1,9 +1,9 @@ #!/usr/bin/env python3 from datetime import datetime -from discord_analyzer.models.BaseModel import BaseModel from pymongo import DESCENDING from pymongo.database import Database +from tc_analyzer_lib.models.BaseModel import BaseModel class HeatMapModel(BaseModel): diff --git a/discord_analyzer/models/MemberActivityModel.py b/tc_analyzer_lib/models/MemberActivityModel.py similarity index 96% rename from discord_analyzer/models/MemberActivityModel.py rename to tc_analyzer_lib/models/MemberActivityModel.py index 73f3234..c6f4121 100644 --- a/discord_analyzer/models/MemberActivityModel.py +++ b/tc_analyzer_lib/models/MemberActivityModel.py @@ -2,7 +2,7 @@ import logging import pymongo -from discord_analyzer.models.BaseModel import BaseModel +from tc_analyzer_lib.models.BaseModel import BaseModel class MemberActivityModel(BaseModel): diff --git a/discord_analyzer/models/RawInfoModel.py b/tc_analyzer_lib/models/RawInfoModel.py similarity index 97% rename from discord_analyzer/models/RawInfoModel.py rename to tc_analyzer_lib/models/RawInfoModel.py index 16e6a4a..51f7f68 100644 --- a/discord_analyzer/models/RawInfoModel.py +++ b/tc_analyzer_lib/models/RawInfoModel.py @@ -3,9 +3,9 @@ from datetime import datetime, timedelta from typing import Any -from discord_analyzer.models.BaseModel import BaseModel from pymongo import ASCENDING from pymongo.database import Database +from tc_analyzer_lib.models.BaseModel import BaseModel class RawInfoModel(BaseModel): diff --git a/discord_analyzer/models/__init__.py b/tc_analyzer_lib/models/__init__.py similarity index 100% rename from discord_analyzer/models/__init__.py rename to tc_analyzer_lib/models/__init__.py diff --git a/discord_analyzer/models/raw_member_activities.py b/tc_analyzer_lib/models/raw_member_activities.py similarity index 97% rename from discord_analyzer/models/raw_member_activities.py rename to tc_analyzer_lib/models/raw_member_activities.py index 8b5b537..7ada9e3 100644 --- a/discord_analyzer/models/raw_member_activities.py +++ b/tc_analyzer_lib/models/raw_member_activities.py @@ -3,8 +3,8 @@ from datetime import datetime, time, timedelta import numpy as np -from discord_analyzer.models.BaseModel import BaseModel -from utils.mongo import MongoSingleton +from tc_analyzer_lib.models.BaseModel import BaseModel +from tc_analyzer_lib.utils.mongo import MongoSingleton class RawMemberActivities(BaseModel): diff --git a/tc_analyzer_lib/publish_on_success.py b/tc_analyzer_lib/publish_on_success.py new file mode 100644 index 0000000..dc9d0ca --- /dev/null +++ b/tc_analyzer_lib/publish_on_success.py @@ -0,0 +1,73 @@ +import logging + +from tc_analyzer_lib.automation.automation_workflow import AutomationWorkflow +from tc_analyzer_lib.utils.get_guild_utils import ( + get_platform_community_owner, + get_platform_guild_id, + get_platform_name, +) +from tc_analyzer_lib.utils.rabbitmq import RabbitMQAccess +from tc_messageBroker.rabbit_mq.event import Event +from tc_messageBroker.rabbit_mq.queue import Queue + + +def publish_on_success(platform_id: str, recompute: bool) -> None: + """ + publish a message to discord platform for a specific platform + telling the Community Manager (CM) the work is finished and run automation + + Note: this will work just for discord platform! + + Parameters + ------------ + platform_id : str + the discord platform to send message to + recompute : bool + if recompute equal to `True` then publish the job finished message for CM + else, just run the automation + """ + + msg = f"PLATFORMID: {platform_id}: " + logging.info(f"{msg}publishing task done to CM") + + guild_id = get_platform_guild_id(platform_id) + platform_name = get_platform_name(platform_id) + + automation_workflow = AutomationWorkflow() + # working specifically for discord + if platform_name == "discord" and recompute: + logging.info(f"{msg}Sending job finished message & starting automation!") + rabbitmq = RabbitMQAccess.get_instance().get_client() + + message = ( + "Your data import into TogetherCrew is complete! " + "See your insights on your dashboard https://app.togethercrew.com/." + " If you have questions send a DM to katerinabc (Discord) or k_bc0 (Telegram)." + ) + owner_discord_id = get_platform_community_owner(platform_id) + data = { + "platformId": platform_id, + "created": False, + "discordId": owner_discord_id, + "message": message, # the message to send + "userFallback": True, + } + + # creating the discord notify saga + saga_id = automation_workflow._create_manual_saga(data=data) + + rabbitmq.publish( + Queue.DISCORD_BOT, + event=Event.DISCORD_BOT.SEND_MESSAGE, + content={"uuid": saga_id}, + ) + automation_workflow.start(platform_id, guild_id) + + elif recompute is False: + logging.info(f"{msg}Just running the automation!") + automation_workflow.start(platform_id, guild_id) + else: + logging.info( + f"{msg}platform was not discord! given platform: {platform_name}" + "No automation or job finished message will be fired" + ) diff --git a/discord_analyzer/schemas/__init__.py b/tc_analyzer_lib/schemas/__init__.py similarity index 100% rename from discord_analyzer/schemas/__init__.py rename to tc_analyzer_lib/schemas/__init__.py index 054b06b..fa41b99 100644 --- a/discord_analyzer/schemas/__init__.py +++ b/tc_analyzer_lib/schemas/__init__.py @@ -1,6 +1,6 @@ # flake8: noqa from .activity_type import ActivityDirection, ActivityType +from .graph import GraphSchema from .hourly_analytics import HourlyAnalytics from .raw_analytics import RawAnalytics from .raw_analytics_item import RawAnalyticsItem -from .graph import GraphSchema diff --git a/discord_analyzer/schemas/activity_type.py b/tc_analyzer_lib/schemas/activity_type.py similarity index 100% rename from discord_analyzer/schemas/activity_type.py rename to tc_analyzer_lib/schemas/activity_type.py diff --git a/discord_analyzer/schemas/graph.py b/tc_analyzer_lib/schemas/graph.py similarity index 100% rename from discord_analyzer/schemas/graph.py rename to tc_analyzer_lib/schemas/graph.py diff --git a/discord_analyzer/schemas/hourly_analytics.py b/tc_analyzer_lib/schemas/hourly_analytics.py similarity index 100% rename from discord_analyzer/schemas/hourly_analytics.py rename to tc_analyzer_lib/schemas/hourly_analytics.py diff --git a/discord_analyzer/schemas/platform_configs/__init__.py b/tc_analyzer_lib/schemas/platform_configs/__init__.py similarity index 100% rename from discord_analyzer/schemas/platform_configs/__init__.py rename to tc_analyzer_lib/schemas/platform_configs/__init__.py diff --git a/discord_analyzer/schemas/platform_configs/config_base.py b/tc_analyzer_lib/schemas/platform_configs/config_base.py similarity index 94% rename from discord_analyzer/schemas/platform_configs/config_base.py rename to tc_analyzer_lib/schemas/platform_configs/config_base.py index bf3e62c..1e6aeef 100644 --- a/discord_analyzer/schemas/platform_configs/config_base.py +++ b/tc_analyzer_lib/schemas/platform_configs/config_base.py @@ -1,4 +1,4 @@ -from discord_analyzer.schemas import HourlyAnalytics, RawAnalytics +from tc_analyzer_lib.schemas import HourlyAnalytics, RawAnalytics class PlatformConfigBase: diff --git a/discord_analyzer/schemas/platform_configs/discord.py b/tc_analyzer_lib/schemas/platform_configs/discord.py similarity index 96% rename from discord_analyzer/schemas/platform_configs/discord.py rename to tc_analyzer_lib/schemas/platform_configs/discord.py index 7879e5e..effb904 100644 --- a/discord_analyzer/schemas/platform_configs/discord.py +++ b/tc_analyzer_lib/schemas/platform_configs/discord.py @@ -1,10 +1,10 @@ -from discord_analyzer.schemas import ( +from tc_analyzer_lib.schemas import ( ActivityDirection, ActivityType, HourlyAnalytics, RawAnalytics, ) -from discord_analyzer.schemas.platform_configs.config_base import PlatformConfigBase +from tc_analyzer_lib.schemas.platform_configs.config_base import PlatformConfigBase class DiscordAnalyzerConfig(PlatformConfigBase): diff --git a/discord_analyzer/schemas/raw_analytics.py b/tc_analyzer_lib/schemas/raw_analytics.py similarity index 100% rename from discord_analyzer/schemas/raw_analytics.py rename to tc_analyzer_lib/schemas/raw_analytics.py diff --git a/discord_analyzer/schemas/raw_analytics_item.py b/tc_analyzer_lib/schemas/raw_analytics_item.py similarity index 100% rename from discord_analyzer/schemas/raw_analytics_item.py rename to tc_analyzer_lib/schemas/raw_analytics_item.py diff --git a/discord_analyzer/tc_analyzer.py b/tc_analyzer_lib/tc_analyzer.py similarity index 64% rename from discord_analyzer/tc_analyzer.py rename to tc_analyzer_lib/tc_analyzer.py index a6933cf..57d0a8a 100644 --- a/discord_analyzer/tc_analyzer.py +++ b/tc_analyzer_lib/tc_analyzer.py @@ -1,44 +1,78 @@ import logging +from datetime import datetime -from discord_analyzer.metrics.analyzer_memberactivities import MemberActivities -from discord_analyzer.metrics.heatmaps import Heatmaps -from discord_analyzer.metrics.neo4j_analytics import Neo4JAnalytics -from discord_analyzer.metrics.utils.analyzer_db_manager import AnalyzerDBManager -from discord_analyzer.metrics.utils.platform import Platform -from discord_analyzer.schemas import GraphSchema -from discord_analyzer.schemas.platform_configs import DiscordAnalyzerConfig +from tc_analyzer_lib.metrics.analyzer_memberactivities import MemberActivities +from tc_analyzer_lib.metrics.heatmaps import Heatmaps +from tc_analyzer_lib.metrics.neo4j_analytics import Neo4JAnalytics +from tc_analyzer_lib.metrics.utils.analyzer_db_manager import AnalyzerDBManager +from tc_analyzer_lib.metrics.utils.platform import Platform +from tc_analyzer_lib.schemas import GraphSchema +from tc_analyzer_lib.schemas.platform_configs import DiscordAnalyzerConfig +from tc_analyzer_lib.schemas.platform_configs.config_base import PlatformConfigBase class TCAnalyzer(AnalyzerDBManager): """ - TCAnalyzer + TogetherCrew's Analyzer class that handles database connections and data analysis """ def __init__( self, platform_id: str, + resources: list[str], + period: datetime, + action: dict[str, int], + window: dict[str, int], + analyzer_config: PlatformConfigBase = DiscordAnalyzerConfig(), ): """ - Class initiation function + analyze the platform's data + producing heatmaps, memberactivities, and graph analytics + + Parameters + ----------- + platform_id : str + platform to analyze its data + resources : list[str] + the resources id for filtering on data + period : datetime + the period to compute the analytics for + action : dict[str, int] + Parameters for computing different memberactivities + window : dict[str, int] + Parameters for the whole analyzer, includes the step size and window size + analyzer_config : PlatformConfigBase + the config for analyzer to use """ logging.basicConfig() logging.getLogger().setLevel(logging.INFO) self.platform_id = platform_id - - # hard-coded for now - # TODO: define a structure and make it read from db - self.analyzer_config = DiscordAnalyzerConfig() + self.resources = resources + self.period = period + self.action = action + self.window = window + self.analyzer_config = analyzer_config self.platform_utils = Platform(platform_id) self.community_id = self.platform_utils.get_community_id() - self.graph_schema = GraphSchema(platform=self.analyzer_config.platform) + self.graph_schema = GraphSchema(platform=analyzer_config.platform) self.neo4j_analytics = Neo4JAnalytics(platform_id, self.graph_schema) + # connect to Neo4j & MongoDB database + self.database_connect() + + def analyze(self, recompute: bool) -> None: + # TODO: merge run_one and recompute codes + if recompute: + self.run_once() + else: + self.recompute() + def run_once(self): - """Run analysis once (Wrapper)""" + """Run analysis and append to previous anlaytics""" # check if the platform was available # if not, will raise an error self.check_platform() @@ -47,8 +81,8 @@ def run_once(self): heatmaps_analysis = Heatmaps( platform_id=self.platform_id, - period=self.platform_utils.get_platform_period(), - resources=self.platform_utils.get_platform_resources(), + period=self.period, + resources=self.resources, analyzer_config=self.analyzer_config, ) heatmaps_data = heatmaps_analysis.start(from_start=False) @@ -66,14 +100,13 @@ def run_once(self): remove_heatmaps=False, ) - window, action = self.platform_utils.get_platform_analyzer_params() memberactivity_analysis = MemberActivities( platform_id=self.platform_id, - resources=self.platform_utils.get_platform_resources(), - action_config=action, - window_config=window, + resources=self.resources, + action_config=self.action, + window_config=self.window, analyzer_config=self.analyzer_config, - analyzer_period=self.platform_utils.get_platform_period(), + analyzer_period=self.period, ) ( member_activities_data, @@ -100,24 +133,10 @@ def run_once(self): self.platform_utils.update_isin_progress() - def recompute_analytics(self): + def recompute(self): """ - recompute the memberactivities (and heatmaps in case needed) - for a new selection of channels - - - - first it would update the channel selection in Core.Platform - - - Second the memebracitivites collection - of the input guildId would become empty - - - Third we would have the analytics running again on the - new channel selection (analytics would be inserted in memebractivities) - - - Returns: - --------- - `None` + recompute the analytics (heatmaps + memberactivities + graph analytics) + for a new selection of channels """ # check if the platform was available # if not, will raise an error @@ -126,8 +145,8 @@ def recompute_analytics(self): logging.info(f"Analyzing the Heatmaps data for platform: {self.platform_id}!") heatmaps_analysis = Heatmaps( platform_id=self.platform_id, - period=self.platform_utils.get_platform_period(), - resources=self.platform_utils.get_platform_resources(), + period=self.period, + resources=self.resources, analyzer_config=self.analyzer_config, ) heatmaps_data = heatmaps_analysis.start(from_start=True) @@ -149,14 +168,13 @@ def recompute_analytics(self): logging.info( f"Analyzing the MemberActivities data for platform: {self.platform_id}!" ) - window, action = self.platform_utils.get_platform_analyzer_params() memberactivity_analysis = MemberActivities( platform_id=self.platform_id, - resources=self.platform_utils.get_platform_resources(), - action_config=action, - window_config=window, + resources=self.resources, + action_config=self.action, + window_config=self.window, analyzer_config=self.analyzer_config, - analyzer_period=self.platform_utils.get_platform_period(), + analyzer_period=self.period, ) ( member_activities_data, diff --git a/utils/__init__.py b/tc_analyzer_lib/utils/__init__.py similarity index 100% rename from utils/__init__.py rename to tc_analyzer_lib/utils/__init__.py diff --git a/utils/credentials.py b/tc_analyzer_lib/utils/credentials.py similarity index 100% rename from utils/credentials.py rename to tc_analyzer_lib/utils/credentials.py diff --git a/utils/get_automation_env.py b/tc_analyzer_lib/utils/get_automation_env.py similarity index 100% rename from utils/get_automation_env.py rename to tc_analyzer_lib/utils/get_automation_env.py diff --git a/utils/get_guild_utils.py b/tc_analyzer_lib/utils/get_guild_utils.py similarity index 59% rename from utils/get_guild_utils.py rename to tc_analyzer_lib/utils/get_guild_utils.py index 4a65175..b1adf3e 100644 --- a/utils/get_guild_utils.py +++ b/tc_analyzer_lib/utils/get_guild_utils.py @@ -1,5 +1,5 @@ from bson.objectid import ObjectId -from utils.mongo import MongoSingleton +from tc_analyzer_lib.utils.mongo import MongoSingleton def get_platform_guild_id(platform_id: str) -> str: @@ -56,6 +56,7 @@ def get_guild_platform_id(guild_id: str) -> str: return platform_id + def get_platform_name(platform_id: str) -> str: """ get the platform name @@ -64,6 +65,11 @@ def get_platform_name(platform_id: str) -> str: ------------- platform_id : str the platform id related to a platform + + Returns + -------- + platform_name : str + the platform name i.e.: `discord`, `telegram`, etc """ client = MongoSingleton.get_instance().client @@ -71,6 +77,47 @@ def get_platform_name(platform_id: str) -> str: {"_id": ObjectId(platform_id)}, {"name": True} ) if platform is None: - raise AttributeError(f"platform with given platform_id: {platform_id} not found!") + raise AttributeError( + f"platform with given platform_id: {platform_id} not found!" + ) return platform["name"] + + +def get_platform_community_owner(platform_id: str) -> str: + """ + get the community owener discord id using the platform id + + Parameters + ------------- + platform_id : str + the platform id related to a platform + + Returns + -------- + owner_discord_id : str + the owner discord id + """ + client = MongoSingleton.get_instance().client + + platform = client["Core"]["platforms"].find_one( + {"_id": ObjectId(platform_id)}, {"community": True} + ) + + if platform is None: + raise AttributeError( + f"platform with given platform_id: {platform_id} not found!" + ) + + community_id = platform["community"] + community = client["Core"]["users"].find_one( + {"communities": community_id}, {"discordId": True} + ) + if community is None: + raise AttributeError( + f"Community user with given community id: {community_id} not found!" + ) + + owner_discord_id = community["discordId"] + + return owner_discord_id diff --git a/utils/mongo.py b/tc_analyzer_lib/utils/mongo.py similarity index 93% rename from utils/mongo.py rename to tc_analyzer_lib/utils/mongo.py index 9d67566..c40e36d 100644 --- a/utils/mongo.py +++ b/tc_analyzer_lib/utils/mongo.py @@ -2,7 +2,7 @@ from typing import Any from pymongo import MongoClient -from utils.credentials import get_mongo_credentials +from tc_analyzer_lib.utils.credentials import get_mongo_credentials class MongoSingleton: diff --git a/tc_analyzer_lib/utils/rabbitmq.py b/tc_analyzer_lib/utils/rabbitmq.py new file mode 100644 index 0000000..a833b0f --- /dev/null +++ b/tc_analyzer_lib/utils/rabbitmq.py @@ -0,0 +1,42 @@ +import logging + +from tc_analyzer_lib.utils.credentials import get_rabbit_mq_credentials +from tc_messageBroker import RabbitMQ +from tc_messageBroker.rabbit_mq.queue import Queue + + +class RabbitMQAccess: + __instance = None + + def __init__(self): + # if RabbitMQAccess.__instance is not None: + # raise Exception("This class is a singleton!") + # else: + creds = get_rabbit_mq_credentials() + self.client = self.create_rabbitmq_client(creds) + RabbitMQAccess.__instance = self + + @staticmethod + def get_instance(): + # if RabbitMQAccess.__instance is None: + try: + RabbitMQAccess() + logging.info("RabbitMQ broker Connected Successfully!") + except Exception as exp: + logging.error(f"RabbitMQ broker not connected! exp: {exp}") + + return RabbitMQAccess.__instance + + def get_client(self): + return self.client + + def create_rabbitmq_client(self, rabbit_creds: dict[str, str]): + rabbitmq = RabbitMQ( + broker_url=rabbit_creds["broker_url"], + port=rabbit_creds["port"], + username=rabbit_creds["username"], + password=rabbit_creds["password"], + ) + rabbitmq.connect(queue_name=Queue.DISCORD_ANALYZER) + + return rabbitmq diff --git a/utils/redis.py b/tc_analyzer_lib/utils/redis.py similarity index 94% rename from utils/redis.py rename to tc_analyzer_lib/utils/redis.py index c8224ed..e0cff89 100644 --- a/utils/redis.py +++ b/tc_analyzer_lib/utils/redis.py @@ -1,7 +1,7 @@ import logging import redis -from utils.credentials import get_redis_credentials +from tc_analyzer_lib.utils.credentials import get_redis_credentials class RedisSingleton: diff --git a/tests/integration/test_all_active_period.py b/tests/integration/test_all_active_period.py index ab181f2..6ba4dd0 100644 --- a/tests/integration/test_all_active_period.py +++ b/tests/integration/test_all_active_period.py @@ -1,7 +1,7 @@ from datetime import datetime, timedelta -from .utils.analyzer_setup import launch_db_access, setup_analyzer -from .utils.remove_and_setup_guild import setup_db_guild +from .utils.analyzer_setup import launch_db_access +from .utils.setup_platform import setup_platform def test_two_weeks_period_active_members(): @@ -20,7 +20,7 @@ def test_two_weeks_period_active_members(): # A guild connected at 35 days ago connected_days_before = 35 - setup_db_guild( + analyzer = setup_platform( db_access, platform_id, discordId_list=acc_id, @@ -170,7 +170,6 @@ def test_two_weeks_period_active_members(): rawinfo_samples ) - analyzer = setup_analyzer(platform_id) analyzer.run_once() memberactivities_cursor = db_access.query_db_find( diff --git a/tests/integration/test_all_joined_day_members.py b/tests/integration/test_all_joined_day_members.py index 9b01dfc..4796fa7 100644 --- a/tests/integration/test_all_joined_day_members.py +++ b/tests/integration/test_all_joined_day_members.py @@ -3,8 +3,8 @@ import numpy as np -from .utils.analyzer_setup import launch_db_access, setup_analyzer -from .utils.remove_and_setup_guild import setup_db_guild +from .utils.analyzer_setup import launch_db_access +from .utils.setup_platform import setup_platform def test_all_joined_day_members(): @@ -26,7 +26,7 @@ def test_all_joined_day_members(): today - timedelta(days=13), ] - setup_db_guild( + analyzer = setup_platform( db_access, platform_id, discordId_list=acc_id, @@ -83,7 +83,6 @@ def test_all_joined_day_members(): rawinfo_samples ) - analyzer = setup_analyzer(platform_id) analyzer.run_once() cursor = db_access.db_mongo_client[platform_id]["memberactivities"].find([]) diff --git a/tests/integration/test_analyzer_init.py b/tests/integration/test_analyzer_init.py deleted file mode 100644 index 138ec5d..0000000 --- a/tests/integration/test_analyzer_init.py +++ /dev/null @@ -1,109 +0,0 @@ -from datetime import datetime, timedelta - -import pytest -from bson.objectid import ObjectId -from utils.mongo import MongoSingleton - - -@pytest.mark.skip("To be removed! " "Analyzer will be a library.") -def test_analyzer_init(): - from analyzer_init import AnalyzerInit - - platform_id = "515151515151515151515151" - days_ago_period = 30 - community_id = "aabbccddeeff001122334455" - guildId = "1234" - - mongo_client = MongoSingleton.get_instance().get_client() - mongo_client["Core"]["platforms"].delete_one({"metadata.id": guildId}) - mongo_client.drop_database(guildId) - - 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, - } - window = { - "period_size": 7, - "step_size": 1, - } - - mongo_client["Core"]["platforms"].insert_one( - { - "_id": ObjectId(platform_id), - "name": "discord", - "metadata": { - "id": guildId, - "icon": "111111111111111111111111", - "name": "A guild", - "resources": ["1020707129214111827"], - "window": window, - "action": act_param, - "period": datetime.now() - timedelta(days=days_ago_period), - }, - "community": ObjectId(community_id), - "disconnectedAt": None, - "connectedAt": (datetime.now() - timedelta(days=days_ago_period + 10)), - "isInProgress": True, - "createdAt": datetime(2023, 11, 1), - "updatedAt": datetime(2023, 11, 1), - } - ) - - analyzer = AnalyzerInit(guildId) - - mongo_client[guildId]["rawmembers"].insert_one( - { - "id": "user1", - "joined_At": datetime.now() - timedelta(days=5), - "left_at": None, - "is_bot": False, - } - ) - mongo_client[guildId].create_collection("heatmaps") - mongo_client[guildId].create_collection("memberactivities") - - # generating random rawinfo data - # 24 hours - # 90 days - rawinfo_samples = [] - for i in range(24 * days_ago_period): - sample = { - "type": 19, - "author": "user1", - "content": f"test{i}", - "user_mentions": [], - "role_mentions": [], - "reactions": [], - "replied_user": "user2", - "createdDate": (datetime.now() - timedelta(hours=i)), - "messageId": f"11188143219343360{i}", - "channelId": "1020707129214111827", - "channelName": "general", - "threadId": None, - "threadName": None, - "isGeneratedByWebhook": False, - } - rawinfo_samples.append(sample) - - mongo_client[guildId]["rawmemberactivities"].insert_many(rawinfo_samples) - - tc_discord_analyzer = analyzer.get_analyzer() - - tc_discord_analyzer.recompute_analytics() - - heatmaps_data = mongo_client[guildId]["heatmaps"].find_one({}) - assert heatmaps_data is not None - - memberactivities_data = mongo_client[guildId]["memberactivities"].find_one({}) - assert memberactivities_data is not None diff --git a/tests/integration/test_analyzer_period_1year_recompute_available_analytics.py b/tests/integration/test_analyzer_period_1year_recompute_available_analytics.py index 9ecd3c6..27a3f2c 100644 --- a/tests/integration/test_analyzer_period_1year_recompute_available_analytics.py +++ b/tests/integration/test_analyzer_period_1year_recompute_available_analytics.py @@ -3,10 +3,10 @@ import numpy as np -from .utils.analyzer_setup import launch_db_access, setup_analyzer +from .utils.analyzer_setup import launch_db_access from .utils.mock_heatmaps import create_empty_heatmaps_data from .utils.mock_memberactivities import create_empty_memberactivities_data -from .utils.remove_and_setup_guild import setup_db_guild +from .utils.setup_platform import setup_platform def test_analyzer_one_year_period_recompute_available_analytics(): @@ -23,7 +23,9 @@ def test_analyzer_one_year_period_recompute_available_analytics(): "973993299281076286", ] - setup_db_guild(db_access, platform_id, discordId_list=acc_id, days_ago_period=360) + analyzer = setup_platform( + db_access, platform_id, discordId_list=acc_id, days_ago_period=360 + ) db_access.db_mongo_client[platform_id].drop_collection("heatmaps") db_access.db_mongo_client[platform_id].drop_collection("memberactivities") @@ -95,8 +97,7 @@ def test_analyzer_one_year_period_recompute_available_analytics(): rawinfo_samples ) - analyzer = setup_analyzer(platform_id) - analyzer.recompute_analytics() + analyzer.recompute() memberactivities_cursor = db_access.query_db_find( "memberactivities", {}, sorting=("date", -1) diff --git a/tests/integration/test_analyzer_period_1year_recompute_empty_analytics.py b/tests/integration/test_analyzer_period_1year_recompute_empty_analytics.py index 2392696..5d02b6e 100644 --- a/tests/integration/test_analyzer_period_1year_recompute_empty_analytics.py +++ b/tests/integration/test_analyzer_period_1year_recompute_empty_analytics.py @@ -3,8 +3,8 @@ import numpy as np -from .utils.analyzer_setup import launch_db_access, setup_analyzer -from .utils.remove_and_setup_guild import setup_db_guild +from .utils.analyzer_setup import launch_db_access +from .utils.setup_platform import setup_platform def test_analyzer_one_year_period_recompute_empty_analytics(): @@ -21,7 +21,9 @@ def test_analyzer_one_year_period_recompute_empty_analytics(): "973993299281076286", ] - setup_db_guild(db_access, platform_id, discordId_list=acc_id, days_ago_period=360) + analyzer = setup_platform( + db_access, platform_id, discordId_list=acc_id, days_ago_period=360 + ) db_access.db_mongo_client[platform_id].drop_collection("heatmaps") db_access.db_mongo_client[platform_id].drop_collection("memberactivities") @@ -75,8 +77,7 @@ def test_analyzer_one_year_period_recompute_empty_analytics(): rawinfo_samples ) - analyzer = setup_analyzer(platform_id) - analyzer.recompute_analytics() + analyzer.recompute() memberactivities_cursor = db_access.query_db_find( "memberactivities", {}, sorting=("date", -1) diff --git a/tests/integration/test_analyzer_period_1year_run_once_available_analytics.py b/tests/integration/test_analyzer_period_1year_run_once_available_analytics.py index 34f376c..d925fd5 100644 --- a/tests/integration/test_analyzer_period_1year_run_once_available_analytics.py +++ b/tests/integration/test_analyzer_period_1year_run_once_available_analytics.py @@ -3,10 +3,10 @@ import numpy as np -from .utils.analyzer_setup import launch_db_access, setup_analyzer +from .utils.analyzer_setup import launch_db_access from .utils.mock_heatmaps import create_empty_heatmaps_data from .utils.mock_memberactivities import create_empty_memberactivities_data -from .utils.remove_and_setup_guild import setup_db_guild +from .utils.setup_platform import setup_platform def test_analyzer_one_year_period_run_once_available_analytics(): @@ -23,7 +23,9 @@ def test_analyzer_one_year_period_run_once_available_analytics(): "973993299281076286", ] - setup_db_guild(db_access, platform_id, discordId_list=acc_id, days_ago_period=360) + analyzer = setup_platform( + db_access, platform_id, discordId_list=acc_id, days_ago_period=360 + ) db_access.db_mongo_client[platform_id].drop_collection("heatmaps") db_access.db_mongo_client[platform_id].drop_collection("memberactivities") @@ -99,7 +101,6 @@ def test_analyzer_one_year_period_run_once_available_analytics(): rawinfo_samples ) - analyzer = setup_analyzer(platform_id) analyzer.run_once() memberactivities_cursor = db_access.query_db_find( diff --git a/tests/integration/test_analyzer_period_1year_run_once_empty_analytics.py b/tests/integration/test_analyzer_period_1year_run_once_empty_analytics.py index cfaf8dc..f59820d 100644 --- a/tests/integration/test_analyzer_period_1year_run_once_empty_analytics.py +++ b/tests/integration/test_analyzer_period_1year_run_once_empty_analytics.py @@ -3,8 +3,8 @@ import numpy as np -from .utils.analyzer_setup import launch_db_access, setup_analyzer -from .utils.remove_and_setup_guild import setup_db_guild +from .utils.analyzer_setup import launch_db_access +from .utils.setup_platform import setup_platform def test_analyzer_one_year_period_run_once_empty_analytics(): @@ -21,7 +21,9 @@ def test_analyzer_one_year_period_run_once_empty_analytics(): "973993299281076286", ] - setup_db_guild(db_access, platform_id, discordId_list=acc_id, days_ago_period=360) + analyzer = setup_platform( + db_access, platform_id, discordId_list=acc_id, days_ago_period=360 + ) db_access.db_mongo_client[platform_id].drop_collection("heatmaps") db_access.db_mongo_client[platform_id].drop_collection("memberactivities") @@ -75,7 +77,6 @@ def test_analyzer_one_year_period_run_once_empty_analytics(): rawinfo_samples ) - analyzer = setup_analyzer(platform_id) analyzer.run_once() memberactivities_cursor = db_access.query_db_find( diff --git a/tests/integration/test_analyzer_period_35days_run_once.py b/tests/integration/test_analyzer_period_35days_run_once.py index 557636b..73d1192 100644 --- a/tests/integration/test_analyzer_period_35days_run_once.py +++ b/tests/integration/test_analyzer_period_35days_run_once.py @@ -3,10 +3,10 @@ import numpy as np -from .utils.analyzer_setup import launch_db_access, setup_analyzer +from .utils.analyzer_setup import launch_db_access from .utils.mock_heatmaps import create_empty_heatmaps_data from .utils.mock_memberactivities import create_empty_memberactivities_data -from .utils.remove_and_setup_guild import setup_db_guild +from .utils.setup_platform import setup_platform def test_analyzer_40days_period_run_once_available_analytics_overlapping_period(): @@ -24,7 +24,9 @@ def test_analyzer_40days_period_run_once_available_analytics_overlapping_period( "user2", ] - setup_db_guild(db_access, platform_id, discordId_list=acc_id, days_ago_period=40) + analyzer = setup_platform( + db_access, platform_id, discordId_list=acc_id, days_ago_period=40 + ) db_access.db_mongo_client[platform_id].drop_collection("heatmaps") db_access.db_mongo_client[platform_id].drop_collection("memberactivities") @@ -97,7 +99,6 @@ def test_analyzer_40days_period_run_once_available_analytics_overlapping_period( rawinfo_samples ) - analyzer = setup_analyzer(platform_id) analyzer.run_once() memberactivities_cursor = db_access.query_db_find( diff --git a/tests/integration/test_analyzer_period_3month_recompute_available_analytics.py b/tests/integration/test_analyzer_period_3month_recompute_available_analytics.py index eb4e149..1497865 100644 --- a/tests/integration/test_analyzer_period_3month_recompute_available_analytics.py +++ b/tests/integration/test_analyzer_period_3month_recompute_available_analytics.py @@ -3,10 +3,10 @@ import numpy as np -from .utils.analyzer_setup import launch_db_access, setup_analyzer +from .utils.analyzer_setup import launch_db_access from .utils.mock_heatmaps import create_empty_heatmaps_data from .utils.mock_memberactivities import create_empty_memberactivities_data -from .utils.remove_and_setup_guild import setup_db_guild +from .utils.setup_platform import setup_platform def test_analyzer_three_month_period_recompute_available_analytics(): @@ -23,7 +23,9 @@ def test_analyzer_three_month_period_recompute_available_analytics(): "973993299281076286", ] - setup_db_guild(db_access, platform_id, discordId_list=acc_id, days_ago_period=90) + analyzer = setup_platform( + db_access, platform_id, discordId_list=acc_id, days_ago_period=90 + ) db_access.db_mongo_client[platform_id].drop_collection("heatmaps") db_access.db_mongo_client[platform_id].drop_collection("memberactivities") @@ -95,8 +97,7 @@ def test_analyzer_three_month_period_recompute_available_analytics(): rawinfo_samples ) - analyzer = setup_analyzer(platform_id) - analyzer.recompute_analytics() + analyzer.recompute() memberactivities_cursor = db_access.query_db_find( "memberactivities", {}, sorting=("date", -1) diff --git a/tests/integration/test_analyzer_period_3month_recompute_empty_analytics.py b/tests/integration/test_analyzer_period_3month_recompute_empty_analytics.py index 7cd8f78..09c4166 100644 --- a/tests/integration/test_analyzer_period_3month_recompute_empty_analytics.py +++ b/tests/integration/test_analyzer_period_3month_recompute_empty_analytics.py @@ -3,8 +3,8 @@ import numpy as np -from .utils.analyzer_setup import launch_db_access, setup_analyzer -from .utils.remove_and_setup_guild import setup_db_guild +from .utils.analyzer_setup import launch_db_access +from .utils.setup_platform import setup_platform def test_analyzer_three_month_period_recompute_empty_analytics(): @@ -21,7 +21,9 @@ def test_analyzer_three_month_period_recompute_empty_analytics(): "973993299281076286", ] - setup_db_guild(db_access, platform_id, discordId_list=acc_id, days_ago_period=90) + analyzer = setup_platform( + db_access, platform_id, discordId_list=acc_id, days_ago_period=90 + ) db_access.db_mongo_client[platform_id].drop_collection("heatmaps") db_access.db_mongo_client[platform_id].drop_collection("memberactivities") @@ -75,8 +77,7 @@ def test_analyzer_three_month_period_recompute_empty_analytics(): rawinfo_samples ) - analyzer = setup_analyzer(platform_id) - analyzer.recompute_analytics() + analyzer.recompute() memberactivities_cursor = db_access.query_db_find( "memberactivities", {}, sorting=("date", -1) diff --git a/tests/integration/test_analyzer_period_3month_run_once_available_analytics.py b/tests/integration/test_analyzer_period_3month_run_once_available_analytics.py index 3e7e47d..f1ceb5a 100644 --- a/tests/integration/test_analyzer_period_3month_run_once_available_analytics.py +++ b/tests/integration/test_analyzer_period_3month_run_once_available_analytics.py @@ -3,10 +3,10 @@ import numpy as np -from .utils.analyzer_setup import launch_db_access, setup_analyzer +from .utils.analyzer_setup import launch_db_access from .utils.mock_heatmaps import create_empty_heatmaps_data from .utils.mock_memberactivities import create_empty_memberactivities_data -from .utils.remove_and_setup_guild import setup_db_guild +from .utils.setup_platform import setup_platform def test_analyzer_three_month_period_run_once_available_analytics(): @@ -23,7 +23,9 @@ def test_analyzer_three_month_period_run_once_available_analytics(): "973993299281076286", ] - setup_db_guild(db_access, platform_id, discordId_list=acc_id, days_ago_period=90) + analyzer = setup_platform( + db_access, platform_id, discordId_list=acc_id, days_ago_period=90 + ) db_access.db_mongo_client[platform_id].drop_collection("heatmaps") db_access.db_mongo_client[platform_id].drop_collection("memberactivities") @@ -96,7 +98,6 @@ def test_analyzer_three_month_period_run_once_available_analytics(): rawinfo_samples ) - analyzer = setup_analyzer(platform_id) analyzer.run_once() memberactivities_cursor = db_access.query_db_find( diff --git a/tests/integration/test_analyzer_period_3month_run_once_empty_analytics.py b/tests/integration/test_analyzer_period_3month_run_once_empty_analytics.py index c26cd0c..f3b51dd 100644 --- a/tests/integration/test_analyzer_period_3month_run_once_empty_analytics.py +++ b/tests/integration/test_analyzer_period_3month_run_once_empty_analytics.py @@ -3,8 +3,8 @@ import numpy as np -from .utils.analyzer_setup import launch_db_access, setup_analyzer -from .utils.remove_and_setup_guild import setup_db_guild +from .utils.analyzer_setup import launch_db_access +from .utils.setup_platform import setup_platform def test_analyzer_three_month_period_run_once_empty_analytics(): @@ -21,7 +21,9 @@ def test_analyzer_three_month_period_run_once_empty_analytics(): "973993299281076286", ] - setup_db_guild(db_access, platform_id, discordId_list=acc_id, days_ago_period=90) + analyzer = setup_platform( + db_access, platform_id, discordId_list=acc_id, days_ago_period=90 + ) db_access.db_mongo_client[platform_id].drop_collection("heatmaps") db_access.db_mongo_client[platform_id].drop_collection("memberactivities") @@ -75,7 +77,6 @@ def test_analyzer_three_month_period_run_once_empty_analytics(): rawinfo_samples ) - analyzer = setup_analyzer(platform_id) analyzer.run_once() memberactivities_cursor = db_access.query_db_find( diff --git a/tests/integration/test_analyzer_period_6month_recompute_available_analytics.py b/tests/integration/test_analyzer_period_6month_recompute_available_analytics.py index a7c9e75..5bb7e48 100644 --- a/tests/integration/test_analyzer_period_6month_recompute_available_analytics.py +++ b/tests/integration/test_analyzer_period_6month_recompute_available_analytics.py @@ -3,10 +3,10 @@ import numpy as np -from .utils.analyzer_setup import launch_db_access, setup_analyzer +from .utils.analyzer_setup import launch_db_access from .utils.mock_heatmaps import create_empty_heatmaps_data from .utils.mock_memberactivities import create_empty_memberactivities_data -from .utils.remove_and_setup_guild import setup_db_guild +from .utils.setup_platform import setup_platform def test_analyzer_six_month_period_recompute_available_analytics(): @@ -23,7 +23,9 @@ def test_analyzer_six_month_period_recompute_available_analytics(): "973993299281076286", ] - setup_db_guild(db_access, platform_id, discordId_list=acc_id, days_ago_period=180) + analyzer = setup_platform( + db_access, platform_id, discordId_list=acc_id, days_ago_period=180 + ) db_access.db_mongo_client[platform_id].drop_collection("heatmaps") db_access.db_mongo_client[platform_id].drop_collection("memberactivities") @@ -96,8 +98,7 @@ def test_analyzer_six_month_period_recompute_available_analytics(): rawinfo_samples ) - analyzer = setup_analyzer(platform_id) - analyzer.recompute_analytics() + analyzer.recompute() memberactivities_cursor = db_access.query_db_find( "memberactivities", {}, sorting=("date", -1) diff --git a/tests/integration/test_analyzer_period_6month_recompute_empty_analytics.py b/tests/integration/test_analyzer_period_6month_recompute_empty_analytics.py index 2373f4c..14b90a4 100644 --- a/tests/integration/test_analyzer_period_6month_recompute_empty_analytics.py +++ b/tests/integration/test_analyzer_period_6month_recompute_empty_analytics.py @@ -3,8 +3,8 @@ import numpy as np -from .utils.analyzer_setup import launch_db_access, setup_analyzer -from .utils.remove_and_setup_guild import setup_db_guild +from .utils.analyzer_setup import launch_db_access +from .utils.setup_platform import setup_platform def test_analyzer_six_month_period_recompute_empty_analytics(): @@ -21,7 +21,9 @@ def test_analyzer_six_month_period_recompute_empty_analytics(): "973993299281076286", ] - setup_db_guild(db_access, platform_id, discordId_list=acc_id, days_ago_period=180) + analyzer = setup_platform( + db_access, platform_id, discordId_list=acc_id, days_ago_period=180 + ) db_access.db_mongo_client[platform_id].drop_collection("heatmaps") db_access.db_mongo_client[platform_id].drop_collection("memberactivities") @@ -75,8 +77,7 @@ def test_analyzer_six_month_period_recompute_empty_analytics(): rawinfo_samples ) - analyzer = setup_analyzer(platform_id) - analyzer.recompute_analytics() + analyzer.recompute() memberactivities_cursor = db_access.query_db_find( "memberactivities", {}, sorting=("date", -1) diff --git a/tests/integration/test_analyzer_period_6month_run_once_available_analytics.py b/tests/integration/test_analyzer_period_6month_run_once_available_analytics.py index 790fc8c..94dff3e 100644 --- a/tests/integration/test_analyzer_period_6month_run_once_available_analytics.py +++ b/tests/integration/test_analyzer_period_6month_run_once_available_analytics.py @@ -3,10 +3,10 @@ import numpy as np -from .utils.analyzer_setup import launch_db_access, setup_analyzer +from .utils.analyzer_setup import launch_db_access from .utils.mock_heatmaps import create_empty_heatmaps_data from .utils.mock_memberactivities import create_empty_memberactivities_data -from .utils.remove_and_setup_guild import setup_db_guild +from .utils.setup_platform import setup_platform def test_analyzer_six_month_period_run_once_available_analytics(): @@ -23,7 +23,9 @@ def test_analyzer_six_month_period_run_once_available_analytics(): "973993299281076286", ] - setup_db_guild(db_access, platform_id, discordId_list=acc_id, days_ago_period=180) + analyzer = setup_platform( + db_access, platform_id, discordId_list=acc_id, days_ago_period=180 + ) db_access.db_mongo_client[platform_id].drop_collection("heatmaps") db_access.db_mongo_client[platform_id].drop_collection("memberactivities") @@ -96,7 +98,6 @@ def test_analyzer_six_month_period_run_once_available_analytics(): rawinfo_samples ) - analyzer = setup_analyzer(platform_id) analyzer.run_once() memberactivities_cursor = db_access.query_db_find( diff --git a/tests/integration/test_analyzer_period_6month_run_once_empty_analytics.py b/tests/integration/test_analyzer_period_6month_run_once_empty_analytics.py index e6f2b9c..c4eee00 100644 --- a/tests/integration/test_analyzer_period_6month_run_once_empty_analytics.py +++ b/tests/integration/test_analyzer_period_6month_run_once_empty_analytics.py @@ -3,8 +3,8 @@ import numpy as np -from .utils.analyzer_setup import launch_db_access, setup_analyzer -from .utils.remove_and_setup_guild import setup_db_guild +from .utils.analyzer_setup import launch_db_access +from .utils.setup_platform import setup_platform def test_analyzer_six_month_period_run_once_empty_analytics(): @@ -21,7 +21,9 @@ def test_analyzer_six_month_period_run_once_empty_analytics(): "973993299281076286", ] - setup_db_guild(db_access, platform_id, discordId_list=acc_id, days_ago_period=180) + analyzer = setup_platform( + db_access, platform_id, discordId_list=acc_id, days_ago_period=180 + ) db_access.db_mongo_client[platform_id].drop_collection("heatmaps") db_access.db_mongo_client[platform_id].drop_collection("memberactivities") @@ -75,7 +77,6 @@ def test_analyzer_six_month_period_run_once_empty_analytics(): rawinfo_samples ) - analyzer = setup_analyzer(platform_id) analyzer.run_once() memberactivities_cursor = db_access.query_db_find( diff --git a/tests/integration/test_analyzer_period_month_recompute_available_analytics.py b/tests/integration/test_analyzer_period_month_recompute_available_analytics.py index 35a9119..465d845 100644 --- a/tests/integration/test_analyzer_period_month_recompute_available_analytics.py +++ b/tests/integration/test_analyzer_period_month_recompute_available_analytics.py @@ -3,10 +3,10 @@ import numpy as np -from .utils.analyzer_setup import launch_db_access, setup_analyzer +from .utils.analyzer_setup import launch_db_access from .utils.mock_heatmaps import create_empty_heatmaps_data from .utils.mock_memberactivities import create_empty_memberactivities_data -from .utils.remove_and_setup_guild import setup_db_guild +from .utils.setup_platform import setup_platform def test_analyzer_month_period_recompute_available_analytics(): @@ -23,7 +23,9 @@ def test_analyzer_month_period_recompute_available_analytics(): "973993299281076286", ] - setup_db_guild(db_access, platform_id, discordId_list=acc_id, days_ago_period=30) + analyzer = setup_platform( + db_access, platform_id, discordId_list=acc_id, days_ago_period=30 + ) db_access.db_mongo_client[platform_id].drop_collection("heatmaps") db_access.db_mongo_client[platform_id].drop_collection("memberactivities") @@ -95,8 +97,7 @@ def test_analyzer_month_period_recompute_available_analytics(): rawinfo_samples ) - analyzer = setup_analyzer(platform_id) - analyzer.recompute_analytics() + analyzer.recompute() memberactivities_cursor = db_access.query_db_find( "memberactivities", {}, sorting=("date", -1) diff --git a/tests/integration/test_analyzer_period_month_recompute_empty_analytics.py b/tests/integration/test_analyzer_period_month_recompute_empty_analytics.py index 6744034..f0f313c 100644 --- a/tests/integration/test_analyzer_period_month_recompute_empty_analytics.py +++ b/tests/integration/test_analyzer_period_month_recompute_empty_analytics.py @@ -3,8 +3,8 @@ import numpy as np -from .utils.analyzer_setup import launch_db_access, setup_analyzer -from .utils.remove_and_setup_guild import setup_db_guild +from .utils.analyzer_setup import launch_db_access +from .utils.setup_platform import setup_platform def test_analyzer_month_period_recompute_empty_analytics(): @@ -21,7 +21,9 @@ def test_analyzer_month_period_recompute_empty_analytics(): "973993299281076286", ] - setup_db_guild(db_access, platform_id, discordId_list=acc_id, days_ago_period=30) + analyzer = setup_platform( + db_access, platform_id, discordId_list=acc_id, days_ago_period=30 + ) db_access.db_mongo_client[platform_id].drop_collection("heatmaps") db_access.db_mongo_client[platform_id].drop_collection("memberactivities") @@ -74,8 +76,7 @@ def test_analyzer_month_period_recompute_empty_analytics(): rawinfo_samples ) - analyzer = setup_analyzer(platform_id) - analyzer.recompute_analytics() + analyzer.recompute() memberactivities_cursor = db_access.query_db_find( "memberactivities", {}, sorting=("date", -1) diff --git a/tests/integration/test_analyzer_period_month_run_once_available_analytics.py b/tests/integration/test_analyzer_period_month_run_once_available_analytics.py index 2e55ab8..692782a 100644 --- a/tests/integration/test_analyzer_period_month_run_once_available_analytics.py +++ b/tests/integration/test_analyzer_period_month_run_once_available_analytics.py @@ -3,10 +3,10 @@ import numpy as np -from .utils.analyzer_setup import launch_db_access, setup_analyzer +from .utils.analyzer_setup import launch_db_access from .utils.mock_heatmaps import create_empty_heatmaps_data from .utils.mock_memberactivities import create_empty_memberactivities_data -from .utils.remove_and_setup_guild import setup_db_guild +from .utils.setup_platform import setup_platform def test_analyzer_month_period_run_once_available_analytics(): @@ -23,7 +23,9 @@ def test_analyzer_month_period_run_once_available_analytics(): "973993299281076286", ] - setup_db_guild(db_access, platform_id, discordId_list=acc_id, days_ago_period=30) + analyzer = setup_platform( + db_access, platform_id, discordId_list=acc_id, days_ago_period=30 + ) db_access.db_mongo_client[platform_id].drop_collection("heatmaps") db_access.db_mongo_client[platform_id].drop_collection("memberactivities") @@ -96,7 +98,6 @@ def test_analyzer_month_period_run_once_available_analytics(): rawinfo_samples ) - analyzer = setup_analyzer(platform_id) analyzer.run_once() memberactivities_cursor = db_access.query_db_find( diff --git a/tests/integration/test_analyzer_period_month_run_once_empty_analytics.py b/tests/integration/test_analyzer_period_month_run_once_empty_analytics.py index 82e8c46..a84fe47 100644 --- a/tests/integration/test_analyzer_period_month_run_once_empty_analytics.py +++ b/tests/integration/test_analyzer_period_month_run_once_empty_analytics.py @@ -3,8 +3,8 @@ import numpy as np -from .utils.analyzer_setup import launch_db_access, setup_analyzer -from .utils.remove_and_setup_guild import setup_db_guild +from .utils.analyzer_setup import launch_db_access +from .utils.setup_platform import setup_platform def test_analyzer_month_period_run_once_empty_analytics(): @@ -21,7 +21,9 @@ def test_analyzer_month_period_run_once_empty_analytics(): "973993299281076286", ] - setup_db_guild(db_access, platform_id, discordId_list=acc_id, days_ago_period=30) + analyzer = setup_platform( + db_access, platform_id, discordId_list=acc_id, days_ago_period=30 + ) db_access.db_mongo_client[platform_id].drop_collection("heatmaps") db_access.db_mongo_client[platform_id].drop_collection("memberactivities") @@ -74,7 +76,6 @@ def test_analyzer_month_period_run_once_empty_analytics(): rawinfo_samples ) - analyzer = setup_analyzer(platform_id) analyzer.run_once() memberactivities_cursor = db_access.query_db_find( diff --git a/tests/integration/test_analyzer_period_week_recompute_available_analytics.py b/tests/integration/test_analyzer_period_week_recompute_available_analytics.py index 196499a..0eb5282 100644 --- a/tests/integration/test_analyzer_period_week_recompute_available_analytics.py +++ b/tests/integration/test_analyzer_period_week_recompute_available_analytics.py @@ -3,10 +3,10 @@ import numpy as np -from .utils.analyzer_setup import launch_db_access, setup_analyzer +from .utils.analyzer_setup import launch_db_access from .utils.mock_heatmaps import create_empty_heatmaps_data from .utils.mock_memberactivities import create_empty_memberactivities_data -from .utils.remove_and_setup_guild import setup_db_guild +from .utils.setup_platform import setup_platform def test_analyzer_week_period_recompute_available_analytics(): @@ -23,7 +23,9 @@ def test_analyzer_week_period_recompute_available_analytics(): "user_1", "user_2", ] - setup_db_guild(db_access, platform_id, discordId_list=acc_id, days_ago_period=8) + analyzer = setup_platform( + db_access, platform_id, discordId_list=acc_id, days_ago_period=8 + ) db_access.db_mongo_client[platform_id].drop_collection("heatmaps") db_access.db_mongo_client[platform_id].drop_collection("memberactivities") @@ -93,8 +95,7 @@ def test_analyzer_week_period_recompute_available_analytics(): rawinfo_samples ) - analyzer = setup_analyzer(platform_id) - analyzer.recompute_analytics() + analyzer.recompute() memberactivities_cursor = db_access.query_db_find("memberactivities", {}) memberactivities_data = list(memberactivities_cursor) diff --git a/tests/integration/test_analyzer_period_week_recompute_empty_analytics.py b/tests/integration/test_analyzer_period_week_recompute_empty_analytics.py index b215999..3794f28 100644 --- a/tests/integration/test_analyzer_period_week_recompute_empty_analytics.py +++ b/tests/integration/test_analyzer_period_week_recompute_empty_analytics.py @@ -3,8 +3,8 @@ import numpy as np -from .utils.analyzer_setup import launch_db_access, setup_analyzer -from .utils.remove_and_setup_guild import setup_db_guild +from .utils.analyzer_setup import launch_db_access +from .utils.setup_platform import setup_platform def test_analyzer_week_period_recompute_empty_analytics(): @@ -21,7 +21,9 @@ def test_analyzer_week_period_recompute_empty_analytics(): "973993299281076286", ] - setup_db_guild(db_access, platform_id, discordId_list=acc_id, days_ago_period=7) + analyzer = setup_platform( + db_access, platform_id, discordId_list=acc_id, days_ago_period=7 + ) db_access.db_mongo_client[platform_id].drop_collection("heatmaps") db_access.db_mongo_client[platform_id].drop_collection("memberactivities") @@ -74,8 +76,7 @@ def test_analyzer_week_period_recompute_empty_analytics(): rawinfo_samples ) - analyzer = setup_analyzer(platform_id) - analyzer.recompute_analytics() + analyzer.recompute() memberactivities_cursor = db_access.db_mongo_client[platform_id][ "memberactivities" diff --git a/tests/integration/test_analyzer_period_week_run_once_available_analytics.py b/tests/integration/test_analyzer_period_week_run_once_available_analytics.py index 9e71d7f..f4245fc 100644 --- a/tests/integration/test_analyzer_period_week_run_once_available_analytics.py +++ b/tests/integration/test_analyzer_period_week_run_once_available_analytics.py @@ -3,10 +3,10 @@ import numpy as np -from .utils.analyzer_setup import launch_db_access, setup_analyzer +from .utils.analyzer_setup import launch_db_access from .utils.mock_heatmaps import create_empty_heatmaps_data from .utils.mock_memberactivities import create_empty_memberactivities_data -from .utils.remove_and_setup_guild import setup_db_guild +from .utils.setup_platform import setup_platform def test_analyzer_week_period_run_once_available_analytics(): @@ -23,7 +23,9 @@ def test_analyzer_week_period_run_once_available_analytics(): "973993299281076285", "973993299281076286", ] - setup_db_guild(db_access, platform_id, discordId_list=acc_id, days_ago_period=8) + analyzer = setup_platform( + db_access, platform_id, discordId_list=acc_id, days_ago_period=8 + ) db_access.db_mongo_client[platform_id].drop_collection("heatmaps") db_access.db_mongo_client[platform_id].drop_collection("memberactivities") @@ -91,7 +93,6 @@ def test_analyzer_week_period_run_once_available_analytics(): rawinfo_samples ) - analyzer = setup_analyzer(platform_id) analyzer.run_once() memberactivities_cursor = db_access.query_db_find( diff --git a/tests/integration/test_analyzer_period_week_run_once_empty_analytics.py b/tests/integration/test_analyzer_period_week_run_once_empty_analytics.py index 449fa98..bded353 100644 --- a/tests/integration/test_analyzer_period_week_run_once_empty_analytics.py +++ b/tests/integration/test_analyzer_period_week_run_once_empty_analytics.py @@ -3,8 +3,8 @@ import numpy as np -from .utils.analyzer_setup import launch_db_access, setup_analyzer -from .utils.remove_and_setup_guild import setup_db_guild +from .utils.analyzer_setup import launch_db_access +from .utils.setup_platform import setup_platform def test_analyzer_week_period_run_once_empty_analytics(): @@ -21,7 +21,9 @@ def test_analyzer_week_period_run_once_empty_analytics(): "user_1", ] - setup_db_guild(db_access, platform_id, discordId_list=acc_id, days_ago_period=7) + analyzer = setup_platform( + db_access, platform_id, discordId_list=acc_id, days_ago_period=7 + ) db_access.db_mongo_client[platform_id].drop_collection("heatmaps") db_access.db_mongo_client[platform_id].drop_collection("memberactivities") @@ -73,7 +75,6 @@ def test_analyzer_week_period_run_once_empty_analytics(): rawinfo_samples ) - analyzer = setup_analyzer(platform_id) analyzer.run_once() memberactivities_cursor = db_access.query_db_find( diff --git a/tests/integration/test_analyzer_platform_fetch_period.py b/tests/integration/test_analyzer_platform_fetch_period.py index afc9bf9..9ca4f44 100644 --- a/tests/integration/test_analyzer_platform_fetch_period.py +++ b/tests/integration/test_analyzer_platform_fetch_period.py @@ -1,9 +1,9 @@ -from bson import ObjectId from datetime import datetime from unittest import TestCase -from utils.mongo import MongoSingleton -from discord_analyzer.metrics.utils import Platform +from bson import ObjectId +from tc_analyzer_lib.metrics.utils import Platform +from tc_analyzer_lib.utils.mongo import MongoSingleton class TestPlatformUtilsFetchPeriod(TestCase): diff --git a/tests/integration/test_analyzer_platform_fetch_resources.py b/tests/integration/test_analyzer_platform_fetch_resources.py index 7a7d146..eb46fd2 100644 --- a/tests/integration/test_analyzer_platform_fetch_resources.py +++ b/tests/integration/test_analyzer_platform_fetch_resources.py @@ -1,9 +1,9 @@ -from bson import ObjectId from datetime import datetime from unittest import TestCase -from utils.mongo import MongoSingleton -from discord_analyzer.metrics.utils import Platform +from bson import ObjectId +from tc_analyzer_lib.metrics.utils import Platform +from tc_analyzer_lib.utils.mongo import MongoSingleton class TestPlatformUtilsFetchResources(TestCase): diff --git a/tests/integration/test_analyzer_utils_platform.py b/tests/integration/test_analyzer_utils_platform.py index 6a576c0..a6974a5 100644 --- a/tests/integration/test_analyzer_utils_platform.py +++ b/tests/integration/test_analyzer_utils_platform.py @@ -1,8 +1,8 @@ -from bson import ObjectId from unittest import TestCase -from discord_analyzer.metrics.utils import Platform -from utils.mongo import MongoSingleton +from bson import ObjectId +from tc_analyzer_lib.metrics.utils import Platform +from tc_analyzer_lib.utils.mongo import MongoSingleton class TestAnalyzerUtilsPlatform(TestCase): @@ -150,25 +150,6 @@ def test_get_community_id_single_platform_available(self): self.assertEqual(expected_community_id, community_id) - def test_get_community_id_single_platform_available(self): - platform_id = "60d5ec44f9a3c2b6d7e2d11a" - expected_community_id = "77d5ec44f6a3c2b6d7e2d11a" - - self.client["Core"]["platforms"].insert_one( - { - "_id": ObjectId(platform_id), - "name": "discord", - "community": ObjectId(expected_community_id), - "metadata": { - "isInProgress": True, - }, - } - ) - platform_obj = Platform(platform_id) - community_id = platform_obj.get_community_id() - - self.assertEqual(expected_community_id, community_id) - def test_get_community_id_irrelevant_platform_available(self): platform_id = "60d5ec44f9a3c2b6d7e2d11a" platform_id2 = "60d5ec44f9a3c2b6d7e2d11b" diff --git a/tests/integration/test_analyzer_utils_platform_parameters.py b/tests/integration/test_analyzer_utils_platform_parameters.py index 257097e..c6add2a 100644 --- a/tests/integration/test_analyzer_utils_platform_parameters.py +++ b/tests/integration/test_analyzer_utils_platform_parameters.py @@ -1,9 +1,9 @@ -from bson import ObjectId -from unittest import TestCase from datetime import datetime, timedelta +from unittest import TestCase -from discord_analyzer.metrics.utils import Platform -from utils.mongo import MongoSingleton +from bson import ObjectId +from tc_analyzer_lib.metrics.utils import Platform +from tc_analyzer_lib.utils.mongo import MongoSingleton class TestAnalyzerUtilsPlatform(TestCase): diff --git a/tests/integration/test_assess_engagement_mention.py b/tests/integration/test_assess_engagement_mention.py index 1f752eb..01f4795 100644 --- a/tests/integration/test_assess_engagement_mention.py +++ b/tests/integration/test_assess_engagement_mention.py @@ -1,14 +1,14 @@ from datetime import datetime, timedelta from unittest import TestCase -from discord_analyzer.algorithms.utils.member_activity_utils import assess_engagement -from discord_analyzer.metrics.utils.analyzer_db_manager import AnalyzerDBManager +from tc_analyzer_lib.algorithms.utils.member_activity_utils import assess_engagement +from tc_analyzer_lib.metrics.heatmaps import Heatmaps +from tc_analyzer_lib.metrics.utils.analyzer_db_manager import AnalyzerDBManager +from tc_analyzer_lib.schemas import GraphSchema +from tc_analyzer_lib.schemas.platform_configs import DiscordAnalyzerConfig from .utils.analyzer_setup import launch_db_access -from .utils.remove_and_setup_guild import setup_db_guild -from discord_analyzer.metrics.heatmaps import Heatmaps -from discord_analyzer.schemas import GraphSchema -from discord_analyzer.schemas.platform_configs import DiscordAnalyzerConfig +from .utils.setup_platform import setup_platform class TestAssessEngagementMentions(TestCase): @@ -75,7 +75,7 @@ def test_single_user_mention(self): } platform_id = "515151515151515151515151" - setup_db_guild( + setup_platform( self.db_access, platform_id, discordId_list=users_id_list, diff --git a/tests/integration/test_assess_engagement_reactions.py b/tests/integration/test_assess_engagement_reactions.py index 30d7948..5e3b34d 100644 --- a/tests/integration/test_assess_engagement_reactions.py +++ b/tests/integration/test_assess_engagement_reactions.py @@ -1,14 +1,14 @@ from datetime import datetime, timedelta from unittest import TestCase -from discord_analyzer.algorithms.utils.member_activity_utils import assess_engagement -from discord_analyzer.metrics.utils.analyzer_db_manager import AnalyzerDBManager +from tc_analyzer_lib.algorithms.utils.member_activity_utils import assess_engagement +from tc_analyzer_lib.metrics.heatmaps import Heatmaps +from tc_analyzer_lib.metrics.utils.analyzer_db_manager import AnalyzerDBManager +from tc_analyzer_lib.schemas import GraphSchema +from tc_analyzer_lib.schemas.platform_configs import DiscordAnalyzerConfig from .utils.analyzer_setup import launch_db_access -from .utils.remove_and_setup_guild import setup_db_guild -from discord_analyzer.metrics.heatmaps import Heatmaps -from discord_analyzer.schemas import GraphSchema -from discord_analyzer.schemas.platform_configs import DiscordAnalyzerConfig +from .utils.setup_platform import setup_platform class TestAssessEngagementReactions(TestCase): @@ -75,7 +75,7 @@ def test_single_user_reaction(self): } platform_id = "515151515151515151515151" - setup_db_guild( + setup_platform( self.db_access, platform_id, discordId_list=users_id_list, diff --git a/tests/integration/test_assess_engagement_replies.py b/tests/integration/test_assess_engagement_replies.py index 6d05135..1182c21 100644 --- a/tests/integration/test_assess_engagement_replies.py +++ b/tests/integration/test_assess_engagement_replies.py @@ -1,14 +1,14 @@ from datetime import datetime, timedelta from unittest import TestCase -from discord_analyzer.algorithms.utils.member_activity_utils import assess_engagement -from discord_analyzer.metrics.utils.analyzer_db_manager import AnalyzerDBManager +from tc_analyzer_lib.algorithms.utils.member_activity_utils import assess_engagement +from tc_analyzer_lib.metrics.heatmaps import Heatmaps +from tc_analyzer_lib.metrics.utils.analyzer_db_manager import AnalyzerDBManager +from tc_analyzer_lib.schemas import GraphSchema +from tc_analyzer_lib.schemas.platform_configs import DiscordAnalyzerConfig from .utils.analyzer_setup import launch_db_access -from .utils.remove_and_setup_guild import setup_db_guild -from discord_analyzer.metrics.heatmaps import Heatmaps -from discord_analyzer.schemas import GraphSchema -from discord_analyzer.schemas.platform_configs import DiscordAnalyzerConfig +from .utils.setup_platform import setup_platform class TestAssessEngagementReplies(TestCase): @@ -73,7 +73,7 @@ def test_single_user_reply(self): "DROP_H_THR": 2, "DROP_I_THR": 1, } - setup_db_guild( + setup_platform( self.db_access, self.heatmaps.platform_id, discordId_list=users_id_list, diff --git a/tests/integration/test_automation_base_create_manual_saga.py b/tests/integration/test_automation_base_create_manual_saga.py index 72f1c6b..ab3de7a 100644 --- a/tests/integration/test_automation_base_create_manual_saga.py +++ b/tests/integration/test_automation_base_create_manual_saga.py @@ -1,6 +1,6 @@ import unittest -from automation.utils.automation_base import AutomationBase +from tc_analyzer_lib.automation.utils.automation_base import AutomationBase from .utils.analyzer_setup import launch_db_access diff --git a/tests/integration/test_automation_base_get_users_from_memberactivities_empty_database.py b/tests/integration/test_automation_base_get_users_from_memberactivities_empty_database.py index a48502b..8a59bfc 100644 --- a/tests/integration/test_automation_base_get_users_from_memberactivities_empty_database.py +++ b/tests/integration/test_automation_base_get_users_from_memberactivities_empty_database.py @@ -1,6 +1,6 @@ from datetime import datetime, timedelta -from automation.utils.automation_base import AutomationBase +from tc_analyzer_lib.automation.utils.automation_base import AutomationBase from .utils.analyzer_setup import launch_db_access diff --git a/tests/integration/test_automation_base_get_users_from_memberactivities_filled_database.py b/tests/integration/test_automation_base_get_users_from_memberactivities_filled_database.py index 0096062..8797173 100644 --- a/tests/integration/test_automation_base_get_users_from_memberactivities_filled_database.py +++ b/tests/integration/test_automation_base_get_users_from_memberactivities_filled_database.py @@ -1,6 +1,6 @@ from datetime import datetime, timedelta -from automation.utils.automation_base import AutomationBase +from tc_analyzer_lib.automation.utils.automation_base import AutomationBase from .utils.analyzer_setup import launch_db_access diff --git a/tests/integration/test_automation_base_prepare_names_globalname.py b/tests/integration/test_automation_base_prepare_names_globalname.py index 8623d04..4a83ed8 100644 --- a/tests/integration/test_automation_base_prepare_names_globalname.py +++ b/tests/integration/test_automation_base_prepare_names_globalname.py @@ -1,6 +1,6 @@ from datetime import datetime, timedelta -from automation.utils.automation_base import AutomationBase +from tc_analyzer_lib.automation.utils.automation_base import AutomationBase from .utils.analyzer_setup import launch_db_access diff --git a/tests/integration/test_automation_base_prepare_names_ngu.py b/tests/integration/test_automation_base_prepare_names_ngu.py index 4166b37..70c695f 100644 --- a/tests/integration/test_automation_base_prepare_names_ngu.py +++ b/tests/integration/test_automation_base_prepare_names_ngu.py @@ -1,6 +1,6 @@ from datetime import datetime, timedelta -from automation.utils.automation_base import AutomationBase +from tc_analyzer_lib.automation.utils.automation_base import AutomationBase from .utils.analyzer_setup import launch_db_access diff --git a/tests/integration/test_automation_base_prepare_names_nickname.py b/tests/integration/test_automation_base_prepare_names_nickname.py index 6bdfbef..d516001 100644 --- a/tests/integration/test_automation_base_prepare_names_nickname.py +++ b/tests/integration/test_automation_base_prepare_names_nickname.py @@ -1,6 +1,6 @@ from datetime import datetime, timedelta -from automation.utils.automation_base import AutomationBase +from tc_analyzer_lib.automation.utils.automation_base import AutomationBase from .utils.analyzer_setup import launch_db_access diff --git a/tests/integration/test_automation_base_prepare_names_usernames.py b/tests/integration/test_automation_base_prepare_names_usernames.py index 97c684d..89edf25 100644 --- a/tests/integration/test_automation_base_prepare_names_usernames.py +++ b/tests/integration/test_automation_base_prepare_names_usernames.py @@ -1,6 +1,6 @@ from datetime import datetime, timedelta -from automation.utils.automation_base import AutomationBase +from tc_analyzer_lib.automation.utils.automation_base import AutomationBase from .utils.analyzer_setup import launch_db_access diff --git a/tests/integration/test_automation_db_load_from_db.py b/tests/integration/test_automation_db_load_from_db.py index 64fc96a..4951bec 100644 --- a/tests/integration/test_automation_db_load_from_db.py +++ b/tests/integration/test_automation_db_load_from_db.py @@ -2,9 +2,9 @@ import unittest from datetime import datetime, timedelta -from automation.utils.model import AutomationDB from dotenv import load_dotenv -from utils.mongo import MongoSingleton +from tc_analyzer_lib.automation.utils.model import AutomationDB +from tc_analyzer_lib.utils.mongo import MongoSingleton class TestAutomationDBLoadFromDB(unittest.TestCase): diff --git a/tests/integration/test_automation_db_save_to_db.py b/tests/integration/test_automation_db_save_to_db.py index 607e772..f360321 100644 --- a/tests/integration/test_automation_db_save_to_db.py +++ b/tests/integration/test_automation_db_save_to_db.py @@ -2,10 +2,10 @@ import unittest from datetime import datetime, timezone -from automation.utils.interfaces import Automation -from automation.utils.model import AutomationDB from dotenv import load_dotenv -from utils.mongo import MongoSingleton +from tc_analyzer_lib.automation.utils.interfaces import Automation +from tc_analyzer_lib.automation.utils.model import AutomationDB +from tc_analyzer_lib.utils.mongo import MongoSingleton class TestAutomationDBSaveToDB(unittest.TestCase): diff --git a/tests/integration/test_automation_fire_messages_mongo_saga_message_ngu_strategy.py b/tests/integration/test_automation_fire_messages_mongo_saga_message_ngu_strategy.py index dbbb19d..a084620 100644 --- a/tests/integration/test_automation_fire_messages_mongo_saga_message_ngu_strategy.py +++ b/tests/integration/test_automation_fire_messages_mongo_saga_message_ngu_strategy.py @@ -1,7 +1,7 @@ from datetime import datetime, timedelta -from automation.automation_workflow import AutomationWorkflow -from automation.utils.interfaces import ( +from tc_analyzer_lib.automation.automation_workflow import AutomationWorkflow +from tc_analyzer_lib.automation.utils.interfaces import ( Automation, AutomationAction, AutomationReport, diff --git a/tests/integration/test_automation_fire_messages_mongo_saga_message_nickname_strategy.py b/tests/integration/test_automation_fire_messages_mongo_saga_message_nickname_strategy.py index e834f7c..754a4b1 100644 --- a/tests/integration/test_automation_fire_messages_mongo_saga_message_nickname_strategy.py +++ b/tests/integration/test_automation_fire_messages_mongo_saga_message_nickname_strategy.py @@ -1,7 +1,7 @@ from datetime import datetime, timedelta -from automation.automation_workflow import AutomationWorkflow -from automation.utils.interfaces import ( +from tc_analyzer_lib.automation.automation_workflow import AutomationWorkflow +from tc_analyzer_lib.automation.utils.interfaces import ( Automation, AutomationAction, AutomationReport, diff --git a/tests/integration/test_automation_fire_messages_mongo_saga_message_no_handlebar.py b/tests/integration/test_automation_fire_messages_mongo_saga_message_no_handlebar.py index 85dc0ac..3f2715a 100644 --- a/tests/integration/test_automation_fire_messages_mongo_saga_message_no_handlebar.py +++ b/tests/integration/test_automation_fire_messages_mongo_saga_message_no_handlebar.py @@ -1,7 +1,7 @@ from datetime import datetime, timedelta -from automation.automation_workflow import AutomationWorkflow -from automation.utils.interfaces import ( +from tc_analyzer_lib.automation.automation_workflow import AutomationWorkflow +from tc_analyzer_lib.automation.utils.interfaces import ( Automation, AutomationAction, AutomationReport, diff --git a/tests/integration/test_automation_fire_messages_mongo_saga_message_username_strategy.py b/tests/integration/test_automation_fire_messages_mongo_saga_message_username_strategy.py index 8cf791d..2c6fe1c 100644 --- a/tests/integration/test_automation_fire_messages_mongo_saga_message_username_strategy.py +++ b/tests/integration/test_automation_fire_messages_mongo_saga_message_username_strategy.py @@ -1,7 +1,7 @@ from datetime import datetime, timedelta -from automation.automation_workflow import AutomationWorkflow -from automation.utils.interfaces import ( +from tc_analyzer_lib.automation.automation_workflow import AutomationWorkflow +from tc_analyzer_lib.automation.utils.interfaces import ( Automation, AutomationAction, AutomationReport, diff --git a/tests/integration/test_decentralization_score.py b/tests/integration/test_decentralization_score.py index 1b82408..bc722fa 100644 --- a/tests/integration/test_decentralization_score.py +++ b/tests/integration/test_decentralization_score.py @@ -1,6 +1,6 @@ # the nodes of the graph are partially connected -from discord_analyzer.algorithms.neo4j_analysis.centrality import Centerality -from discord_analyzer.schemas import GraphSchema +from tc_analyzer_lib.algorithms.neo4j_analysis.centrality import Centerality +from tc_analyzer_lib.schemas import GraphSchema from tc_neo4j_lib.neo4j_ops import Neo4jOps diff --git a/tests/integration/test_degree_centrality_multiple_guilds.py b/tests/integration/test_degree_centrality_multiple_guilds.py index ee2338d..8dcc8e8 100644 --- a/tests/integration/test_degree_centrality_multiple_guilds.py +++ b/tests/integration/test_degree_centrality_multiple_guilds.py @@ -1,7 +1,7 @@ # we have nodes of a community is connected to another one # meaning we have nodes available in more than one community -from discord_analyzer.algorithms.neo4j_analysis.centrality import Centerality -from discord_analyzer.schemas import GraphSchema +from tc_analyzer_lib.algorithms.neo4j_analysis.centrality import Centerality +from tc_analyzer_lib.schemas import GraphSchema from tc_neo4j_lib.neo4j_ops import Neo4jOps diff --git a/tests/integration/test_degree_centrality_multiple_guilds_preserve_parallel.py b/tests/integration/test_degree_centrality_multiple_guilds_preserve_parallel.py index 64fa8b3..27915ec 100644 --- a/tests/integration/test_degree_centrality_multiple_guilds_preserve_parallel.py +++ b/tests/integration/test_degree_centrality_multiple_guilds_preserve_parallel.py @@ -1,7 +1,7 @@ # we have nodes of a community is connected to another one # meaning we have nodes available in more than one community -from discord_analyzer.algorithms.neo4j_analysis.centrality import Centerality -from discord_analyzer.schemas import GraphSchema +from tc_analyzer_lib.algorithms.neo4j_analysis.centrality import Centerality +from tc_analyzer_lib.schemas import GraphSchema from tc_neo4j_lib.neo4j_ops import Neo4jOps diff --git a/tests/integration/test_degree_centrality_parallel_preservation.py b/tests/integration/test_degree_centrality_parallel_preservation.py index e89f921..5e5e286 100644 --- a/tests/integration/test_degree_centrality_parallel_preservation.py +++ b/tests/integration/test_degree_centrality_parallel_preservation.py @@ -1,6 +1,6 @@ # the nodes of the graph are partially connected -from discord_analyzer.algorithms.neo4j_analysis.centrality import Centerality -from discord_analyzer.schemas import GraphSchema +from tc_analyzer_lib.algorithms.neo4j_analysis.centrality import Centerality +from tc_analyzer_lib.schemas import GraphSchema from tc_neo4j_lib.neo4j_ops import Neo4jOps diff --git a/tests/integration/test_discord_heatmaps_config.py b/tests/integration/test_discord_heatmaps_config.py index 6ab12f2..0773474 100644 --- a/tests/integration/test_discord_heatmaps_config.py +++ b/tests/integration/test_discord_heatmaps_config.py @@ -1,7 +1,7 @@ from unittest import TestCase -from discord_analyzer.schemas import ActivityDirection, ActivityType -from discord_analyzer.schemas.platform_configs import DiscordAnalyzerConfig +from tc_analyzer_lib.schemas import ActivityDirection, ActivityType +from tc_analyzer_lib.schemas.platform_configs import DiscordAnalyzerConfig class TestDiscordAnalyzerConfig(TestCase): diff --git a/tests/integration/test_exclude_bots.py b/tests/integration/test_exclude_bots.py index a8ad929..7da1969 100644 --- a/tests/integration/test_exclude_bots.py +++ b/tests/integration/test_exclude_bots.py @@ -2,8 +2,8 @@ import numpy as np -from .utils.analyzer_setup import launch_db_access, setup_analyzer -from .utils.remove_and_setup_guild import setup_db_guild +from .utils.analyzer_setup import launch_db_access +from .utils.setup_platform import setup_platform def test_excluding_bots_heatmaps(): @@ -26,7 +26,7 @@ def test_excluding_bots_heatmaps(): # A guild connected at 35 days ago connected_days_before = 35 - setup_db_guild( + analyzer = setup_platform( db_access, platform_id, discordId_list=acc_id, @@ -87,7 +87,6 @@ def test_excluding_bots_heatmaps(): rawinfo_samples ) - analyzer = setup_analyzer(platform_id) analyzer.run_once() db_access.db_mongo_client[platform_id] diff --git a/tests/integration/test_fragmentation_score.py b/tests/integration/test_fragmentation_score.py index 915a3ed..cdbf69e 100644 --- a/tests/integration/test_fragmentation_score.py +++ b/tests/integration/test_fragmentation_score.py @@ -1,7 +1,7 @@ from datetime import datetime, timedelta -from discord_analyzer.metrics.neo4j_analytics import Neo4JAnalytics -from discord_analyzer.schemas import GraphSchema +from tc_analyzer_lib.metrics.neo4j_analytics import Neo4JAnalytics +from tc_analyzer_lib.schemas import GraphSchema from tc_neo4j_lib.neo4j_ops import Neo4jOps diff --git a/tests/integration/test_fragmentation_score_exclude_past.py b/tests/integration/test_fragmentation_score_exclude_past.py index 6eba0e9..39dde9f 100644 --- a/tests/integration/test_fragmentation_score_exclude_past.py +++ b/tests/integration/test_fragmentation_score_exclude_past.py @@ -1,7 +1,7 @@ from datetime import datetime, timedelta -from discord_analyzer.metrics.neo4j_analytics import Neo4JAnalytics -from discord_analyzer.schemas import GraphSchema +from tc_analyzer_lib.metrics.neo4j_analytics import Neo4JAnalytics +from tc_analyzer_lib.schemas import GraphSchema from tc_neo4j_lib.neo4j_ops import Neo4jOps diff --git a/tests/integration/test_fragmentation_score_from_start.py b/tests/integration/test_fragmentation_score_from_start.py index db1c4cd..b1c0e90 100644 --- a/tests/integration/test_fragmentation_score_from_start.py +++ b/tests/integration/test_fragmentation_score_from_start.py @@ -1,7 +1,7 @@ from datetime import datetime, timedelta -from discord_analyzer.metrics.neo4j_analytics import Neo4JAnalytics -from discord_analyzer.schemas import GraphSchema +from tc_analyzer_lib.metrics.neo4j_analytics import Neo4JAnalytics +from tc_analyzer_lib.schemas import GraphSchema from tc_neo4j_lib.neo4j_ops import Neo4jOps diff --git a/tests/integration/test_fragmentation_score_rescaling.py b/tests/integration/test_fragmentation_score_rescaling.py index 85540c0..0273537 100644 --- a/tests/integration/test_fragmentation_score_rescaling.py +++ b/tests/integration/test_fragmentation_score_rescaling.py @@ -1,7 +1,7 @@ from datetime import datetime, timedelta -from discord_analyzer.metrics.neo4j_analytics import Neo4JAnalytics -from discord_analyzer.schemas import GraphSchema +from tc_analyzer_lib.metrics.neo4j_analytics import Neo4JAnalytics +from tc_analyzer_lib.schemas import GraphSchema from tc_neo4j_lib.neo4j_ops import Neo4jOps diff --git a/tests/integration/test_generated_graph_period_1_year_run_once.py b/tests/integration/test_generated_graph_period_1_year_run_once.py index ad74f40..9e87207 100644 --- a/tests/integration/test_generated_graph_period_1_year_run_once.py +++ b/tests/integration/test_generated_graph_period_1_year_run_once.py @@ -3,10 +3,10 @@ import numpy as np from tc_neo4j_lib.neo4j_ops import Neo4jOps -from .utils.analyzer_setup import launch_db_access, setup_analyzer +from .utils.analyzer_setup import launch_db_access from .utils.mock_heatmaps import create_empty_heatmaps_data from .utils.mock_memberactivities import create_empty_memberactivities_data -from .utils.remove_and_setup_guild import setup_db_guild +from .utils.setup_platform import setup_platform def test_networkgraph_one_year_period_run_once_available_analytics(): @@ -33,7 +33,7 @@ def test_networkgraph_one_year_period_run_once_available_analytics(): "973993299281076286", ] - setup_db_guild( + analyzer = setup_platform( db_access, platform_id, discordId_list=acc_id, @@ -111,7 +111,6 @@ def test_networkgraph_one_year_period_run_once_available_analytics(): rawinfo_samples ) - analyzer = setup_analyzer(platform_id) analyzer.run_once() graph_schema = analyzer.graph_schema diff --git a/tests/integration/test_generated_graph_period_1year.py b/tests/integration/test_generated_graph_period_1year.py index 8707de9..e30cbe7 100644 --- a/tests/integration/test_generated_graph_period_1year.py +++ b/tests/integration/test_generated_graph_period_1year.py @@ -3,10 +3,10 @@ import numpy as np from tc_neo4j_lib.neo4j_ops import Neo4jOps -from .utils.analyzer_setup import launch_db_access, setup_analyzer +from .utils.analyzer_setup import launch_db_access from .utils.mock_heatmaps import create_empty_heatmaps_data from .utils.mock_memberactivities import create_empty_memberactivities_data -from .utils.remove_and_setup_guild import setup_db_guild +from .utils.setup_platform import setup_platform def test_networkgraph_one_year_period_recompute_available_analytics(): @@ -33,7 +33,7 @@ def test_networkgraph_one_year_period_recompute_available_analytics(): "973993299281076286", ] - setup_db_guild( + analyzer = setup_platform( db_access, platform_id, discordId_list=acc_id, @@ -111,8 +111,7 @@ def test_networkgraph_one_year_period_recompute_available_analytics(): rawinfo_samples ) - analyzer = setup_analyzer(platform_id) - analyzer.recompute_analytics() + analyzer.recompute() graph_schema = analyzer.graph_schema platform_label = graph_schema.platform_label diff --git a/tests/integration/test_generated_graph_period_35_days.py b/tests/integration/test_generated_graph_period_35_days.py index eec7631..3e1722b 100644 --- a/tests/integration/test_generated_graph_period_35_days.py +++ b/tests/integration/test_generated_graph_period_35_days.py @@ -3,10 +3,10 @@ import numpy as np from tc_neo4j_lib.neo4j_ops import Neo4jOps -from .utils.analyzer_setup import launch_db_access, setup_analyzer +from .utils.analyzer_setup import launch_db_access from .utils.mock_heatmaps import create_empty_heatmaps_data from .utils.mock_memberactivities import create_empty_memberactivities_data -from .utils.remove_and_setup_guild import setup_db_guild +from .utils.setup_platform import setup_platform def test_networkgraph_35_days_period_recompute_available_analytics(): @@ -33,7 +33,7 @@ def test_networkgraph_35_days_period_recompute_available_analytics(): "973993299281076286", ] - setup_db_guild( + analyzer = setup_platform( db_access, platform_id, discordId_list=acc_id, @@ -111,8 +111,7 @@ def test_networkgraph_35_days_period_recompute_available_analytics(): rawinfo_samples ) - analyzer = setup_analyzer(platform_id) - analyzer.recompute_analytics() + analyzer.recompute() graph_schema = analyzer.graph_schema platform_label = graph_schema.platform_label diff --git a/tests/integration/test_generated_graph_period_35_days_run_once.py b/tests/integration/test_generated_graph_period_35_days_run_once.py index c3c328f..10f56a0 100644 --- a/tests/integration/test_generated_graph_period_35_days_run_once.py +++ b/tests/integration/test_generated_graph_period_35_days_run_once.py @@ -3,10 +3,10 @@ import numpy as np from tc_neo4j_lib.neo4j_ops import Neo4jOps -from .utils.analyzer_setup import launch_db_access, setup_analyzer +from .utils.analyzer_setup import launch_db_access from .utils.mock_heatmaps import create_empty_heatmaps_data from .utils.mock_memberactivities import create_empty_memberactivities_data -from .utils.remove_and_setup_guild import setup_db_guild +from .utils.setup_platform import setup_platform def test_networkgraph_35_days_period_run_once_available_analytics(): @@ -33,7 +33,7 @@ def test_networkgraph_35_days_period_run_once_available_analytics(): "973993299281076286", ] - setup_db_guild( + analyzer = setup_platform( db_access, platform_id, discordId_list=acc_id, @@ -111,7 +111,6 @@ def test_networkgraph_35_days_period_run_once_available_analytics(): rawinfo_samples ) - analyzer = setup_analyzer(platform_id) analyzer.run_once() graph_schema = analyzer.graph_schema diff --git a/tests/integration/test_generated_graph_period_3_months.py b/tests/integration/test_generated_graph_period_3_months.py index e6964d5..d39b965 100644 --- a/tests/integration/test_generated_graph_period_3_months.py +++ b/tests/integration/test_generated_graph_period_3_months.py @@ -3,10 +3,10 @@ import numpy as np from tc_neo4j_lib.neo4j_ops import Neo4jOps -from .utils.analyzer_setup import launch_db_access, setup_analyzer +from .utils.analyzer_setup import launch_db_access from .utils.mock_heatmaps import create_empty_heatmaps_data from .utils.mock_memberactivities import create_empty_memberactivities_data -from .utils.remove_and_setup_guild import setup_db_guild +from .utils.setup_platform import setup_platform def test_networkgraph_three_months_period_recompute_available_analytics(): @@ -32,7 +32,7 @@ def test_networkgraph_three_months_period_recompute_available_analytics(): "973993299281076285", "973993299281076286", ] - setup_db_guild( + analyzer = setup_platform( db_access, platform_id, discordId_list=acc_id, @@ -110,8 +110,7 @@ def test_networkgraph_three_months_period_recompute_available_analytics(): rawinfo_samples ) - analyzer = setup_analyzer(platform_id) - analyzer.recompute_analytics() + analyzer.recompute() graph_schema = analyzer.graph_schema platform_label = graph_schema.platform_label diff --git a/tests/integration/test_generated_graph_period_3_months_run_once.py b/tests/integration/test_generated_graph_period_3_months_run_once.py index 60f7806..2947722 100644 --- a/tests/integration/test_generated_graph_period_3_months_run_once.py +++ b/tests/integration/test_generated_graph_period_3_months_run_once.py @@ -3,10 +3,10 @@ import numpy as np from tc_neo4j_lib.neo4j_ops import Neo4jOps -from .utils.analyzer_setup import launch_db_access, setup_analyzer +from .utils.analyzer_setup import launch_db_access from .utils.mock_heatmaps import create_empty_heatmaps_data from .utils.mock_memberactivities import create_empty_memberactivities_data -from .utils.remove_and_setup_guild import setup_db_guild +from .utils.setup_platform import setup_platform def test_networkgraph_three_months_period_run_once_available_analytics(): @@ -33,7 +33,7 @@ def test_networkgraph_three_months_period_run_once_available_analytics(): "973993299281076286", ] - setup_db_guild( + analyzer = setup_platform( db_access, platform_id, discordId_list=acc_id, @@ -111,7 +111,6 @@ def test_networkgraph_three_months_period_run_once_available_analytics(): rawinfo_samples ) - analyzer = setup_analyzer(platform_id) analyzer.run_once() graph_schema = analyzer.graph_schema diff --git a/tests/integration/test_generated_graph_period_6_months.py b/tests/integration/test_generated_graph_period_6_months.py index ba1ee28..91f6402 100644 --- a/tests/integration/test_generated_graph_period_6_months.py +++ b/tests/integration/test_generated_graph_period_6_months.py @@ -3,10 +3,10 @@ import numpy as np from tc_neo4j_lib.neo4j_ops import Neo4jOps -from .utils.analyzer_setup import launch_db_access, setup_analyzer +from .utils.analyzer_setup import launch_db_access from .utils.mock_heatmaps import create_empty_heatmaps_data from .utils.mock_memberactivities import create_empty_memberactivities_data -from .utils.remove_and_setup_guild import setup_db_guild +from .utils.setup_platform import setup_platform def test_networkgraph_six_months_period_recompute_available_analytics(): @@ -33,7 +33,7 @@ def test_networkgraph_six_months_period_recompute_available_analytics(): "973993299281076286", ] - setup_db_guild( + analyzer = setup_platform( db_access, platform_id, discordId_list=acc_id, @@ -111,8 +111,7 @@ def test_networkgraph_six_months_period_recompute_available_analytics(): rawinfo_samples ) - analyzer = setup_analyzer(platform_id) - analyzer.recompute_analytics() + analyzer.recompute() graph_schema = analyzer.graph_schema platform_label = graph_schema.platform_label diff --git a/tests/integration/test_generated_graph_period_6_months_run_once.py b/tests/integration/test_generated_graph_period_6_months_run_once.py index 4ad7011..4531220 100644 --- a/tests/integration/test_generated_graph_period_6_months_run_once.py +++ b/tests/integration/test_generated_graph_period_6_months_run_once.py @@ -3,10 +3,10 @@ import numpy as np from tc_neo4j_lib.neo4j_ops import Neo4jOps -from .utils.analyzer_setup import launch_db_access, setup_analyzer +from .utils.analyzer_setup import launch_db_access from .utils.mock_heatmaps import create_empty_heatmaps_data from .utils.mock_memberactivities import create_empty_memberactivities_data -from .utils.remove_and_setup_guild import setup_db_guild +from .utils.setup_platform import setup_platform def test_networkgraph_six_months_period_run_once_available_analytics(): @@ -34,7 +34,7 @@ def test_networkgraph_six_months_period_run_once_available_analytics(): "973993299281076286", ] - setup_db_guild( + analyzer = setup_platform( db_access, platform_id, discordId_list=acc_id, @@ -112,7 +112,6 @@ def test_networkgraph_six_months_period_run_once_available_analytics(): rawinfo_samples ) - analyzer = setup_analyzer(platform_id) analyzer.run_once() graph_schema = analyzer.graph_schema diff --git a/tests/integration/test_get_guild_community_ids.py b/tests/integration/test_get_guild_community_ids.py index dd0c203..b0c0b1e 100644 --- a/tests/integration/test_get_guild_community_ids.py +++ b/tests/integration/test_get_guild_community_ids.py @@ -2,8 +2,8 @@ from unittest import TestCase from bson.objectid import ObjectId -from utils.get_guild_utils import get_platform_guild_id -from utils.mongo import MongoSingleton +from tc_analyzer_lib.utils.get_guild_utils import get_platform_guild_id +from tc_analyzer_lib.utils.mongo import MongoSingleton class TestGetGuildId(TestCase): diff --git a/tests/integration/test_get_guild_owner.py b/tests/integration/test_get_guild_owner.py new file mode 100644 index 0000000..844beab --- /dev/null +++ b/tests/integration/test_get_guild_owner.py @@ -0,0 +1,215 @@ +from datetime import datetime, timedelta +from unittest import TestCase + +from bson import ObjectId +from tc_analyzer_lib.utils.get_guild_utils import get_platform_community_owner +from tc_analyzer_lib.utils.mongo import MongoSingleton + + +class TestGetGuildOwner(TestCase): + def setUp(self) -> None: + self.client = MongoSingleton.get_instance().get_client() + self.client["Core"].drop_collection("platforms") + self.client["Core"].drop_collection("users") + self.platform_id = "515151515151515151515151" + self.community_id = "aabbccddeeff001122334455" + self.guild_id = "1234" + self.client.drop_database(self.guild_id) + self.client.drop_database(self.platform_id) + + def tearDown(self) -> None: + self.client["Core"].drop_collection("platforms") + self.client["Core"].drop_collection("users") + self.client.drop_database(self.guild_id) + self.client.drop_database(self.platform_id) + + def test_no_platform_available(self): + with self.assertRaises(AttributeError): + _ = get_platform_community_owner(self.platform_id) + + def test_no_community_available(self): + self.client["Core"]["platforms"].insert_one( + { + "_id": ObjectId(self.platform_id), + "name": "discord", + "metadata": { + "id": self.guild_id, + "icon": "111111111111111111111111", + "name": "A guild", + "resources": ["1020707129214111827"], + "window": {"period_size": 7, "step_size": 1}, + "action": {"some_Values": 1}, + "period": datetime.now() - timedelta(days=30), + }, + "community": ObjectId(self.community_id), + "disconnectedAt": None, + "connectedAt": (datetime.now() - timedelta(days=40)), + "isInProgress": True, + "createdAt": datetime(2023, 11, 1), + "updatedAt": datetime(2023, 11, 1), + } + ) + with self.assertRaises(AttributeError): + _ = get_platform_community_owner(self.platform_id) + + def test_single_platform(self): + expected_owner_discord_id = "1234567890" + + self.client["Core"]["platforms"].insert_one( + { + "_id": ObjectId(self.platform_id), + "name": "discord", + "metadata": { + "id": self.guild_id, + "icon": "111111111111111111111111", + "name": "A guild", + "resources": ["1020707129214111827"], + "window": {"period_size": 7, "step_size": 1}, + "action": {"some_Values": 1}, + "period": datetime.now() - timedelta(days=30), + }, + "community": ObjectId(self.community_id), + "disconnectedAt": None, + "connectedAt": (datetime.now() - timedelta(days=40)), + "isInProgress": True, + "createdAt": datetime(2023, 11, 1), + "updatedAt": datetime(2023, 11, 1), + } + ) + self.client["Core"]["users"].insert_one( + { + "_id": ObjectId(self.platform_id), + "discordId": expected_owner_discord_id, + "communities": [ObjectId(self.community_id)], + "createdAt": datetime(2023, 12, 1), + "updatedAt": datetime(2023, 12, 1), + "tcaAt": datetime(2023, 12, 2), + } + ) + + owner = get_platform_community_owner(platform_id=self.platform_id) + + self.assertEqual( + owner, + expected_owner_discord_id, + ) + + def test_multiple_platforms(self): + expected_owner_discord_id = "1234567890" + + self.client["Core"]["platforms"].insert_one( + { + "_id": ObjectId(self.platform_id), + "name": "discord", + "metadata": { + "id": self.guild_id, + "icon": "111111111111111111111111", + "name": "A guild", + "resources": ["1020707129214111827"], + "window": {"period_size": 7, "step_size": 1}, + "action": {"some_Values": 1}, + "period": datetime.now() - timedelta(days=30), + }, + "community": ObjectId(self.community_id), + "disconnectedAt": None, + "connectedAt": (datetime.now() - timedelta(days=40)), + "isInProgress": True, + "createdAt": datetime(2023, 11, 1), + "updatedAt": datetime(2023, 11, 1), + } + ) + self.client["Core"]["users"].insert_one( + { + "_id": ObjectId(self.platform_id), + "discordId": expected_owner_discord_id, + "communities": [ObjectId(self.community_id)], + "createdAt": datetime(2023, 12, 1), + "updatedAt": datetime(2023, 12, 1), + "tcaAt": datetime(2023, 12, 2), + } + ) + + owner = get_platform_community_owner(platform_id=self.platform_id) + + self.assertEqual(owner, expected_owner_discord_id) + + def test_multiple_platforms_available(self): + expected_owner_discord_id = "1234567891" + platform_id2 = "515151515151515151515152" + platform_id3 = "515151515151515151515153" + + self.client["Core"]["platforms"].insert_many( + [ + { + "_id": ObjectId(self.platform_id), + "name": "discord", + "metadata": { + "id": self.guild_id, + "icon": "111111111111111111111111", + "name": "A guild", + "resources": ["1020707129214111827"], + "window": {"period_size": 7, "step_size": 1}, + "action": {"some_Values": 1}, + "period": datetime.now() - timedelta(days=30), + }, + "community": ObjectId(self.community_id), + "disconnectedAt": None, + "connectedAt": (datetime.now() - timedelta(days=40)), + "isInProgress": True, + "createdAt": datetime(2023, 11, 1), + "updatedAt": datetime(2023, 11, 1), + }, + { + "_id": ObjectId(platform_id2), + "name": "discord", + "metadata": { + "id": self.guild_id, + "icon": "111111111111111111111111", + "name": "A guild", + "resources": ["1020707129214111827"], + "window": {"period_size": 7, "step_size": 1}, + "action": {"some_Values": 1}, + "period": datetime.now() - timedelta(days=30), + }, + "community": ObjectId("aabbccddeeff001122334456"), + "disconnectedAt": None, + "connectedAt": (datetime.now() - timedelta(days=40)), + "isInProgress": True, + "createdAt": datetime(2023, 11, 1), + "updatedAt": datetime(2023, 11, 1), + }, + { + "_id": ObjectId(platform_id3), + "name": "discord", + "metadata": { + "id": self.guild_id, + "icon": "111111111111111111111111", + "name": "A guild", + "resources": ["1020707129214111827"], + "window": {"period_size": 7, "step_size": 1}, + "action": {"some_Values": 1}, + "period": datetime.now() - timedelta(days=30), + }, + "community": ObjectId("aabbccddeeff001122334457"), + "disconnectedAt": None, + "connectedAt": (datetime.now() - timedelta(days=40)), + "isInProgress": True, + "createdAt": datetime(2023, 11, 1), + "updatedAt": datetime(2023, 11, 1), + }, + ] + ) + self.client["Core"]["users"].insert_one( + { + "_id": ObjectId(self.platform_id), + "discordId": expected_owner_discord_id, + "communities": [ObjectId(self.community_id)], + "createdAt": datetime(2023, 12, 1), + "updatedAt": datetime(2023, 12, 1), + "tcaAt": datetime(2023, 12, 2), + } + ) + + owner = get_platform_community_owner(platform_id=self.platform_id) + + self.assertEqual(owner, expected_owner_discord_id) diff --git a/tests/integration/test_get_guild_platform_id.py b/tests/integration/test_get_guild_platform_id.py index 5e4fa92..bb125b7 100644 --- a/tests/integration/test_get_guild_platform_id.py +++ b/tests/integration/test_get_guild_platform_id.py @@ -2,8 +2,8 @@ from unittest import TestCase from bson.objectid import ObjectId -from utils.get_guild_utils import get_guild_platform_id -from utils.mongo import MongoSingleton +from tc_analyzer_lib.utils.get_guild_utils import get_guild_platform_id +from tc_analyzer_lib.utils.mongo import MongoSingleton class TestGetGuildId(TestCase): diff --git a/tests/integration/test_get_past_7_days_heatmaps.py b/tests/integration/test_get_past_7_days_heatmaps.py index 52cb174..a1c4686 100644 --- a/tests/integration/test_get_past_7_days_heatmaps.py +++ b/tests/integration/test_get_past_7_days_heatmaps.py @@ -1,9 +1,7 @@ from datetime import datetime, timedelta import numpy as np -from discord_analyzer.algorithms.utils.member_activity_utils import ( - get_users_past_window, -) +from tc_analyzer_lib.algorithms.utils.member_activity_utils import get_users_past_window from .utils.analyzer_setup import launch_db_access diff --git a/tests/integration/test_heatmaps_analytics.py b/tests/integration/test_heatmaps_analytics.py index fbc3d1d..e7a434b 100644 --- a/tests/integration/test_heatmaps_analytics.py +++ b/tests/integration/test_heatmaps_analytics.py @@ -1,9 +1,9 @@ from datetime import datetime, timedelta from unittest import TestCase -from discord_analyzer.metrics.heatmaps import Heatmaps -from discord_analyzer.schemas.platform_configs import DiscordAnalyzerConfig -from utils.mongo import MongoSingleton +from tc_analyzer_lib.metrics.heatmaps import Heatmaps +from tc_analyzer_lib.schemas.platform_configs import DiscordAnalyzerConfig +from tc_analyzer_lib.utils.mongo import MongoSingleton class TestHeatmapsAnalytics(TestCase): diff --git a/tests/integration/test_heatmaps_analytics_base.py b/tests/integration/test_heatmaps_analytics_base.py index 4b09e55..ed47f74 100644 --- a/tests/integration/test_heatmaps_analytics_base.py +++ b/tests/integration/test_heatmaps_analytics_base.py @@ -1,8 +1,8 @@ from datetime import datetime from unittest import TestCase -from discord_analyzer.metrics.heatmaps.analytics_hourly import AnalyticsHourly -from utils.mongo import MongoSingleton +from tc_analyzer_lib.metrics.heatmaps.analytics_hourly import AnalyticsHourly +from tc_analyzer_lib.utils.mongo import MongoSingleton class TestHeatmapsAnalyticsBaseWithFilter(TestCase): diff --git a/tests/integration/test_heatmaps_analytics_different_source.py b/tests/integration/test_heatmaps_analytics_different_source.py index d3e4296..3d66b9c 100644 --- a/tests/integration/test_heatmaps_analytics_different_source.py +++ b/tests/integration/test_heatmaps_analytics_different_source.py @@ -1,9 +1,9 @@ from datetime import datetime, timedelta from unittest import TestCase -from discord_analyzer.metrics.heatmaps import Heatmaps -from discord_analyzer.schemas.platform_configs import DiscordAnalyzerConfig -from utils.mongo import MongoSingleton +from tc_analyzer_lib.metrics.heatmaps import Heatmaps +from tc_analyzer_lib.schemas.platform_configs import DiscordAnalyzerConfig +from tc_analyzer_lib.utils.mongo import MongoSingleton class TestHeatmapsAnalyticsSingleDay(TestCase): diff --git a/tests/integration/test_heatmaps_analytics_hourly_no_filter.py b/tests/integration/test_heatmaps_analytics_hourly_no_filter.py index c484a40..f2f8bad 100644 --- a/tests/integration/test_heatmaps_analytics_hourly_no_filter.py +++ b/tests/integration/test_heatmaps_analytics_hourly_no_filter.py @@ -1,8 +1,8 @@ from datetime import datetime from unittest import TestCase -from discord_analyzer.metrics.heatmaps.analytics_hourly import AnalyticsHourly -from utils.mongo import MongoSingleton +from tc_analyzer_lib.metrics.heatmaps.analytics_hourly import AnalyticsHourly +from tc_analyzer_lib.utils.mongo import MongoSingleton class TestHeatmapsAnalyticsBaseNoFilter(TestCase): diff --git a/tests/integration/test_heatmaps_analytics_raw.py b/tests/integration/test_heatmaps_analytics_raw.py index bcdf1f4..4c73e29 100644 --- a/tests/integration/test_heatmaps_analytics_raw.py +++ b/tests/integration/test_heatmaps_analytics_raw.py @@ -1,9 +1,9 @@ from datetime import datetime, timedelta from unittest import TestCase -from discord_analyzer.metrics.heatmaps.analytics_raw import AnalyticsRaw -from discord_analyzer.schemas import ActivityDirection, RawAnalyticsItem -from utils.mongo import MongoSingleton +from tc_analyzer_lib.metrics.heatmaps.analytics_raw import AnalyticsRaw +from tc_analyzer_lib.schemas import ActivityDirection, RawAnalyticsItem +from tc_analyzer_lib.utils.mongo import MongoSingleton class TestHeatmapsRawAnalytics(TestCase): diff --git a/tests/integration/test_heatmaps_hourly_analytics_actions_vectors.py b/tests/integration/test_heatmaps_hourly_analytics_actions_vectors.py index 105c5df..5f5d6a7 100644 --- a/tests/integration/test_heatmaps_hourly_analytics_actions_vectors.py +++ b/tests/integration/test_heatmaps_hourly_analytics_actions_vectors.py @@ -1,8 +1,8 @@ from datetime import datetime from unittest import TestCase -from discord_analyzer.metrics.heatmaps.analytics_hourly import AnalyticsHourly -from utils.mongo import MongoSingleton +from tc_analyzer_lib.metrics.heatmaps.analytics_hourly import AnalyticsHourly +from tc_analyzer_lib.utils.mongo import MongoSingleton class TestHeatmapsRawAnalyticsVectorsActions(TestCase): diff --git a/tests/integration/test_heatmaps_hourly_analytics_interaction_vectors.py b/tests/integration/test_heatmaps_hourly_analytics_interaction_vectors.py index 0ba1557..2587e16 100644 --- a/tests/integration/test_heatmaps_hourly_analytics_interaction_vectors.py +++ b/tests/integration/test_heatmaps_hourly_analytics_interaction_vectors.py @@ -1,8 +1,8 @@ from datetime import datetime from unittest import TestCase -from discord_analyzer.metrics.heatmaps.analytics_hourly import AnalyticsHourly -from utils.mongo import MongoSingleton +from tc_analyzer_lib.metrics.heatmaps.analytics_hourly import AnalyticsHourly +from tc_analyzer_lib.utils.mongo import MongoSingleton class TestHeatmapsRawAnalyticsVectorsInteractions(TestCase): diff --git a/tests/integration/test_heatmaps_hourly_lone_message.py b/tests/integration/test_heatmaps_hourly_lone_message.py index 0fd4254..2ae5167 100644 --- a/tests/integration/test_heatmaps_hourly_lone_message.py +++ b/tests/integration/test_heatmaps_hourly_lone_message.py @@ -1,8 +1,8 @@ from datetime import datetime, timedelta -from discord_analyzer.metrics.heatmaps import Heatmaps -from discord_analyzer.schemas.platform_configs import DiscordAnalyzerConfig -from utils.mongo import MongoSingleton +from tc_analyzer_lib.metrics.heatmaps import Heatmaps +from tc_analyzer_lib.schemas.platform_configs import DiscordAnalyzerConfig +from tc_analyzer_lib.utils.mongo import MongoSingleton def test_lone_messages(): diff --git a/tests/integration/test_heatmaps_hourly_mentions.py b/tests/integration/test_heatmaps_hourly_mentions.py index a47bf41..4a56143 100644 --- a/tests/integration/test_heatmaps_hourly_mentions.py +++ b/tests/integration/test_heatmaps_hourly_mentions.py @@ -1,8 +1,8 @@ from datetime import datetime, timedelta -from discord_analyzer.metrics.heatmaps import Heatmaps -from discord_analyzer.schemas.platform_configs import DiscordAnalyzerConfig -from utils.mongo import MongoSingleton +from tc_analyzer_lib.metrics.heatmaps import Heatmaps +from tc_analyzer_lib.schemas.platform_configs import DiscordAnalyzerConfig +from tc_analyzer_lib.utils.mongo import MongoSingleton def test_mentioned_messages(): diff --git a/tests/integration/test_heatmaps_process_hourly_single_day.py b/tests/integration/test_heatmaps_process_hourly_single_day.py index e41f0bf..2a47834 100644 --- a/tests/integration/test_heatmaps_process_hourly_single_day.py +++ b/tests/integration/test_heatmaps_process_hourly_single_day.py @@ -1,9 +1,9 @@ from datetime import datetime from unittest import TestCase -from discord_analyzer.metrics.heatmaps import Heatmaps -from discord_analyzer.schemas.platform_configs import DiscordAnalyzerConfig -from utils.mongo import MongoSingleton +from tc_analyzer_lib.metrics.heatmaps import Heatmaps +from tc_analyzer_lib.schemas.platform_configs import DiscordAnalyzerConfig +from tc_analyzer_lib.utils.mongo import MongoSingleton class TestHeatmapsProcessHourlySingleDay(TestCase): diff --git a/tests/integration/test_heatmaps_process_raw_analytics.py b/tests/integration/test_heatmaps_process_raw_analytics.py index 5bc86d5..18eeb69 100644 --- a/tests/integration/test_heatmaps_process_raw_analytics.py +++ b/tests/integration/test_heatmaps_process_raw_analytics.py @@ -1,9 +1,9 @@ from datetime import datetime from unittest import TestCase -from discord_analyzer.metrics.heatmaps import Heatmaps -from discord_analyzer.schemas.platform_configs import DiscordAnalyzerConfig -from utils.mongo import MongoSingleton +from tc_analyzer_lib.metrics.heatmaps import Heatmaps +from tc_analyzer_lib.schemas.platform_configs import DiscordAnalyzerConfig +from tc_analyzer_lib.utils.mongo import MongoSingleton class TestHeatmapsProcessRawAnalyticsSingleDay(TestCase): diff --git a/tests/integration/test_heatmaps_reactions.py b/tests/integration/test_heatmaps_reactions.py index a01d73e..09cd53b 100644 --- a/tests/integration/test_heatmaps_reactions.py +++ b/tests/integration/test_heatmaps_reactions.py @@ -1,8 +1,8 @@ from datetime import datetime, timedelta -from discord_analyzer.metrics.heatmaps import Heatmaps -from discord_analyzer.schemas.platform_configs import DiscordAnalyzerConfig -from utils.mongo import MongoSingleton +from tc_analyzer_lib.metrics.heatmaps import Heatmaps +from tc_analyzer_lib.schemas.platform_configs import DiscordAnalyzerConfig +from tc_analyzer_lib.utils.mongo import MongoSingleton def test_reacted_messages(): diff --git a/tests/integration/test_heatmaps_replier.py b/tests/integration/test_heatmaps_replier.py index f375603..a716060 100644 --- a/tests/integration/test_heatmaps_replier.py +++ b/tests/integration/test_heatmaps_replier.py @@ -1,8 +1,8 @@ from datetime import datetime, timedelta -from discord_analyzer.metrics.heatmaps import Heatmaps -from discord_analyzer.schemas.platform_configs import DiscordAnalyzerConfig -from utils.mongo import MongoSingleton +from tc_analyzer_lib.metrics.heatmaps import Heatmaps +from tc_analyzer_lib.schemas.platform_configs import DiscordAnalyzerConfig +from tc_analyzer_lib.utils.mongo import MongoSingleton def test_reply_messages(): diff --git a/tests/integration/test_heatmaps_thread_msg.py b/tests/integration/test_heatmaps_thread_msg.py index db7573c..09fa994 100644 --- a/tests/integration/test_heatmaps_thread_msg.py +++ b/tests/integration/test_heatmaps_thread_msg.py @@ -1,8 +1,8 @@ from datetime import datetime, timedelta -from discord_analyzer.metrics.heatmaps import Heatmaps -from discord_analyzer.schemas.platform_configs import DiscordAnalyzerConfig -from utils.mongo import MongoSingleton +from tc_analyzer_lib.metrics.heatmaps import Heatmaps +from tc_analyzer_lib.schemas.platform_configs import DiscordAnalyzerConfig +from tc_analyzer_lib.utils.mongo import MongoSingleton def test_thread_messages(): diff --git a/tests/integration/test_heatmaps_utils.py b/tests/integration/test_heatmaps_utils.py index f1a90b4..a9cb018 100644 --- a/tests/integration/test_heatmaps_utils.py +++ b/tests/integration/test_heatmaps_utils.py @@ -1,8 +1,8 @@ from datetime import datetime from unittest import TestCase -from discord_analyzer.metrics.heatmaps.heatmaps_utils import HeatmapsUtils -from utils.mongo import MongoSingleton +from tc_analyzer_lib.metrics.heatmaps.heatmaps_utils import HeatmapsUtils +from tc_analyzer_lib.utils.mongo import MongoSingleton class TestHeatmapsUtils(TestCase): diff --git a/tests/integration/test_interacted_in_deletion.py b/tests/integration/test_interacted_in_deletion.py index ad0eb58..6c3227d 100644 --- a/tests/integration/test_interacted_in_deletion.py +++ b/tests/integration/test_interacted_in_deletion.py @@ -1,5 +1,5 @@ -from discord_analyzer.metrics.neo4j_analytics import Neo4JAnalytics -from discord_analyzer.schemas import GraphSchema +from tc_analyzer_lib.metrics.neo4j_analytics import Neo4JAnalytics +from tc_analyzer_lib.schemas import GraphSchema from tc_neo4j_lib.neo4j_ops import Neo4jOps diff --git a/tests/integration/test_lcc_all_connected.py b/tests/integration/test_lcc_all_connected.py index 5478b9d..1b2f172 100644 --- a/tests/integration/test_lcc_all_connected.py +++ b/tests/integration/test_lcc_all_connected.py @@ -1,8 +1,8 @@ # test out local clustering coefficient with all nodes connected -from discord_analyzer.algorithms.neo4j_analysis.local_clustering_coefficient import ( +from tc_analyzer_lib.algorithms.neo4j_analysis.local_clustering_coefficient import ( LocalClusteringCoeff, ) -from discord_analyzer.schemas import GraphSchema +from tc_analyzer_lib.schemas import GraphSchema from tc_neo4j_lib.neo4j_ops import Neo4jOps diff --git a/tests/integration/test_lcc_partially_connected.py b/tests/integration/test_lcc_partially_connected.py index 8ee598b..a00ea58 100644 --- a/tests/integration/test_lcc_partially_connected.py +++ b/tests/integration/test_lcc_partially_connected.py @@ -1,8 +1,8 @@ # the nodes of the graph are partially connected -from discord_analyzer.algorithms.neo4j_analysis.local_clustering_coefficient import ( +from tc_analyzer_lib.algorithms.neo4j_analysis.local_clustering_coefficient import ( LocalClusteringCoeff, ) -from discord_analyzer.schemas import GraphSchema +from tc_analyzer_lib.schemas import GraphSchema from tc_neo4j_lib.neo4j_ops import Neo4jOps diff --git a/tests/integration/test_louvain_algorithm_computation.py b/tests/integration/test_louvain_algorithm_computation.py index be10dc0..7a336b3 100644 --- a/tests/integration/test_louvain_algorithm_computation.py +++ b/tests/integration/test_louvain_algorithm_computation.py @@ -1,5 +1,5 @@ -from discord_analyzer.algorithms.neo4j_analysis.louvain import Louvain -from discord_analyzer.schemas import GraphSchema +from tc_analyzer_lib.algorithms.neo4j_analysis.louvain import Louvain +from tc_analyzer_lib.schemas import GraphSchema from tc_neo4j_lib.neo4j_ops import Neo4jOps diff --git a/tests/integration/test_louvain_algorithm_get_computed_dates.py b/tests/integration/test_louvain_algorithm_get_computed_dates.py index 81f299a..e76fb6b 100644 --- a/tests/integration/test_louvain_algorithm_get_computed_dates.py +++ b/tests/integration/test_louvain_algorithm_get_computed_dates.py @@ -1,5 +1,5 @@ -from discord_analyzer.algorithms.neo4j_analysis.louvain import Louvain -from discord_analyzer.schemas import GraphSchema +from tc_analyzer_lib.algorithms.neo4j_analysis.louvain import Louvain +from tc_analyzer_lib.schemas import GraphSchema from tc_neo4j_lib.neo4j_ops import Neo4jOps diff --git a/tests/integration/test_member_activities_action_all_active.py b/tests/integration/test_member_activities_action_all_active.py index 6862a56..ec87057 100644 --- a/tests/integration/test_member_activities_action_all_active.py +++ b/tests/integration/test_member_activities_action_all_active.py @@ -1,8 +1,8 @@ from datetime import datetime, timedelta from unittest import TestCase -from .utils.analyzer_setup import launch_db_access, setup_analyzer -from .utils.remove_and_setup_guild import setup_db_guild +from .utils.analyzer_setup import launch_db_access +from .utils.setup_platform import setup_platform class TestMemberActivitiesActionsAllActive(TestCase): @@ -13,7 +13,7 @@ def setUp(self) -> None: def test_single_user_action(self): self.db_access.db_mongo_client[self.platform_id].drop_collection("heatmaps") users_id_list = ["user1"] - setup_db_guild( + analyzer = analyzer = setup_platform( self.db_access, self.platform_id, discordId_list=users_id_list, @@ -40,8 +40,8 @@ def test_single_user_action(self): self.db_access.db_mongo_client[self.platform_id][ "rawmemberactivities" ].insert_many(rawinfo_samples) - analyzer = setup_analyzer(self.platform_id) - analyzer.recompute_analytics() + + analyzer.recompute() cursor = self.db_access.db_mongo_client[self.platform_id][ "memberactivities" ].find({}, {"_id": 0, "all_active": 1}) @@ -55,7 +55,7 @@ def test_single_user_action(self): def test_lone_msg_action(self): users_id_list = ["user1", "user2", "user3"] - setup_db_guild( + analyzer = setup_platform( self.db_access, self.platform_id, discordId_list=users_id_list, @@ -84,8 +84,8 @@ def test_lone_msg_action(self): self.db_access.db_mongo_client[self.platform_id][ "rawmemberactivities" ].insert_many(rawinfo_samples) - analyzer = setup_analyzer(self.platform_id) - analyzer.recompute_analytics() + + analyzer.recompute() cursor = self.db_access.db_mongo_client[self.platform_id][ "memberactivities" ].find({}, {"_id": 0, "all_active": 1}) @@ -98,7 +98,7 @@ def test_lone_msg_action(self): def test_thr_message_action(self): users_id_list = ["user1", "user2", "user3", "user4"] - setup_db_guild( + analyzer = setup_platform( self.db_access, self.platform_id, discordId_list=users_id_list, @@ -127,8 +127,8 @@ def test_thr_message_action(self): self.db_access.db_mongo_client[self.platform_id][ "rawmemberactivities" ].insert_many(rawinfo_samples) - analyzer = setup_analyzer(self.platform_id) - analyzer.recompute_analytics() + + analyzer.recompute() cursor = self.db_access.db_mongo_client[self.platform_id][ "memberactivities" ].find({}, {"_id": 0, "all_active": 1, "date": 1}) diff --git a/tests/integration/test_member_activities_action_all_activities.py b/tests/integration/test_member_activities_action_all_activities.py index 8e13791..08bc936 100644 --- a/tests/integration/test_member_activities_action_all_activities.py +++ b/tests/integration/test_member_activities_action_all_activities.py @@ -1,8 +1,8 @@ from datetime import datetime, timedelta from unittest import TestCase -from .utils.analyzer_setup import launch_db_access, setup_analyzer -from .utils.remove_and_setup_guild import setup_db_guild +from .utils.analyzer_setup import launch_db_access +from .utils.setup_platform import setup_platform class TestMemberActivitiesActionsAllActivities(TestCase): @@ -32,7 +32,7 @@ def test_single_user_action(self): } platform_id = "515151515151515151515151" - setup_db_guild( + analyzer = setup_platform( self.db_access, platform_id, discordId_list=users_id_list, @@ -62,8 +62,8 @@ def test_single_user_action(self): self.db_access.db_mongo_client[platform_id]["rawmemberactivities"].insert_many( rawinfo_samples ) - analyzer = setup_analyzer(platform_id) - analyzer.recompute_analytics() + + analyzer.recompute() cursor = self.db_access.db_mongo_client[platform_id]["memberactivities"].find( {}, { diff --git a/tests/integration/test_member_activity_from_start_no_past_data.py b/tests/integration/test_member_activity_from_start_no_past_data.py index abbf2da..17c9f2f 100644 --- a/tests/integration/test_member_activity_from_start_no_past_data.py +++ b/tests/integration/test_member_activity_from_start_no_past_data.py @@ -3,7 +3,8 @@ from bson.objectid import ObjectId -from .utils.analyzer_setup import launch_db_access, setup_analyzer +from .utils.analyzer_setup import launch_db_access +from .utils.setup_platform import setup_platform def test_analyzer_member_activities_from_start_empty_memberactivities(): @@ -19,42 +20,12 @@ def test_analyzer_member_activities_from_start_empty_memberactivities(): db_access.db_mongo_client["Core"].drop_collection("platforms") db_access.db_mongo_client.drop_database(platform_id) - 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["Core"]["platforms"].insert_one( - { - "_id": ObjectId(platform_id), - "name": "discord", - "metadata": { - "id": guildId, - "icon": "111111111111111111111111", - "name": "A guild", - "resources": ["1020707129214111827"], - "window": {"period_size": 7, "step_size": 1}, - "action": action, - "period": datetime.now() - timedelta(days=30), - }, - "community": ObjectId("aabbccddeeff001122334455"), - "disconnectedAt": None, - "connectedAt": (datetime.now() - timedelta(days=40)), - "isInProgress": True, - "createdAt": datetime(2023, 11, 1), - "updatedAt": datetime(2023, 11, 1), - } + analyzer = setup_platform( + db_access, + platform_id, + discordId_list=["3451791"], + days_ago_period=30, + community_id="aabbccddeeff001122334455", ) db_access.db_mongo_client[platform_id].drop_collection("heatmaps") db_access.db_mongo_client[platform_id].drop_collection("memberactivities") @@ -93,8 +64,7 @@ def test_analyzer_member_activities_from_start_empty_memberactivities(): rawinfo_samples ) - analyzer = setup_analyzer(platform_id) - analyzer.recompute_analytics() + analyzer.recompute() memberactivities_data = db_access.db_mongo_client[platform_id][ "memberactivities" diff --git a/tests/integration/test_member_activity_from_start_with_guild_heatmaps_available.py b/tests/integration/test_member_activity_from_start_with_guild_heatmaps_available.py index bc838c1..081f39d 100644 --- a/tests/integration/test_member_activity_from_start_with_guild_heatmaps_available.py +++ b/tests/integration/test_member_activity_from_start_with_guild_heatmaps_available.py @@ -1,10 +1,10 @@ # test analyzing memberactivities from datetime import datetime, timedelta -from .utils.analyzer_setup import launch_db_access, setup_analyzer +from .utils.analyzer_setup import launch_db_access from .utils.mock_heatmaps import create_empty_heatmaps_data from .utils.mock_memberactivities import create_empty_memberactivities_data -from .utils.remove_and_setup_guild import setup_db_guild +from .utils.setup_platform import setup_platform def test_analyzer_member_activities_from_start_available_heatmaps(): @@ -17,7 +17,7 @@ def test_analyzer_member_activities_from_start_available_heatmaps(): platform_id = "515151515151515151515151" db_access = launch_db_access(platform_id) - setup_db_guild(db_access, platform_id, discordId_list=["user_0"]) + analyzer = setup_platform(db_access, platform_id, discordId_list=["user_0"]) db_access.db_mongo_client[platform_id].drop_collection("heatmaps") db_access.db_mongo_client[platform_id].drop_collection("memberactivities") @@ -56,8 +56,7 @@ def test_analyzer_member_activities_from_start_available_heatmaps(): rawinfo_samples ) - analyzer = setup_analyzer(platform_id) - analyzer.recompute_analytics() + analyzer.recompute() memberactivities_data = db_access.db_mongo_client[platform_id][ "memberactivities" diff --git a/tests/integration/test_member_activity_from_start_with_guild_memberactivities_available.py b/tests/integration/test_member_activity_from_start_with_guild_memberactivities_available.py index 2e9b923..0614da6 100644 --- a/tests/integration/test_member_activity_from_start_with_guild_memberactivities_available.py +++ b/tests/integration/test_member_activity_from_start_with_guild_memberactivities_available.py @@ -1,9 +1,9 @@ # test analyzing memberactivities from datetime import datetime, timedelta -from .utils.analyzer_setup import launch_db_access, setup_analyzer +from .utils.analyzer_setup import launch_db_access from .utils.mock_memberactivities import create_empty_memberactivities_data -from .utils.remove_and_setup_guild import setup_db_guild +from .utils.setup_platform import setup_platform def test_analyzer_member_activities_from_start_available_member_activity(): @@ -16,7 +16,7 @@ def test_analyzer_member_activities_from_start_available_member_activity(): platform_id = "515151515151515151515151" db_access = launch_db_access(platform_id) - setup_db_guild(db_access, platform_id, discordId_list=["user_0"]) + analyzer = setup_platform(db_access, platform_id, discordId_list=["user_0"]) db_access.db_mongo_client[platform_id].drop_collection("heatmaps") db_access.db_mongo_client[platform_id].drop_collection("memberactivities") @@ -50,8 +50,7 @@ def test_analyzer_member_activities_from_start_available_member_activity(): rawinfo_samples ) - analyzer = setup_analyzer(platform_id) - analyzer.recompute_analytics() + analyzer.recompute() memberactivities_data = db_access.db_mongo_client[platform_id][ "memberactivities" diff --git a/tests/integration/test_member_activity_from_start_with_one_interval.py b/tests/integration/test_member_activity_from_start_with_one_interval.py index c224650..55e95a7 100644 --- a/tests/integration/test_member_activity_from_start_with_one_interval.py +++ b/tests/integration/test_member_activity_from_start_with_one_interval.py @@ -1,8 +1,8 @@ # test analyzing memberactivities from datetime import datetime, timedelta -from .utils.analyzer_setup import launch_db_access, setup_analyzer -from .utils.remove_and_setup_guild import setup_db_guild +from .utils.analyzer_setup import launch_db_access +from .utils.setup_platform import setup_platform def test_analyzer_from_start_one_interval(): @@ -14,7 +14,7 @@ def test_analyzer_from_start_one_interval(): guildId = "1234" db_access = launch_db_access(platform_id) - setup_db_guild(db_access, platform_id, discordId_list=["user_0"]) + analyzer = setup_platform(db_access, platform_id, discordId_list=["user_0"]) rawinfo_samples = [] @@ -41,8 +41,7 @@ def test_analyzer_from_start_one_interval(): db_access.db_mongo_client[platform_id].drop_collection("heatmaps") db_access.db_mongo_client[platform_id].drop_collection("memberactivities") - analyzer = setup_analyzer(platform_id) - analyzer.recompute_analytics() + analyzer.recompute() memberactivities_data = db_access.db_mongo_client[platform_id][ "memberactivities" diff --git a/tests/integration/test_member_activity_utils.py b/tests/integration/test_member_activity_utils.py index 43554d6..bcf8d69 100644 --- a/tests/integration/test_member_activity_utils.py +++ b/tests/integration/test_member_activity_utils.py @@ -1,18 +1,16 @@ from datetime import datetime, timedelta -from discord_analyzer.metrics.memberactivity_utils import MemberActivityUtils +from tc_analyzer_lib.metrics.memberactivity_utils import MemberActivityUtils -from .utils.analyzer_setup import launch_db_access, setup_analyzer -from .utils.remove_and_setup_guild import setup_db_guild +from .utils.analyzer_setup import launch_db_access +from .utils.setup_platform import setup_platform def test_utils_get_members(): platform_id = "515151515151515151515151" - guildId = "1012430565959553145" users = ["user_0"] db_access = launch_db_access(platform_id) - setup_db_guild(db_access, platform_id, discordId_list=users, days_ago_period=7) - analyzer = setup_analyzer(platform_id) + _ = setup_platform(db_access, platform_id, discordId_list=users, days_ago_period=7) rawinfo_samples = [] for i in range(150): diff --git a/tests/integration/test_memberactivities_mentions.py b/tests/integration/test_memberactivities_mentions.py index 8c9849c..96eceb6 100644 --- a/tests/integration/test_memberactivities_mentions.py +++ b/tests/integration/test_memberactivities_mentions.py @@ -1,8 +1,8 @@ from datetime import datetime, timedelta from unittest import TestCase -from .utils.analyzer_setup import launch_db_access, setup_analyzer -from .utils.remove_and_setup_guild import setup_db_guild +from .utils.analyzer_setup import launch_db_access +from .utils.setup_platform import setup_platform class TestMemberActivitiesReply(TestCase): @@ -28,7 +28,7 @@ def test_single_user_interaction(self): "DROP_I_THR": 1, } - setup_db_guild( + analyzer = setup_platform( self.db_access, self.platform_id, discordId_list=users_id_list, @@ -85,8 +85,7 @@ def test_single_user_interaction(self): self.db_access.db_mongo_client[self.platform_id][ "rawmemberactivities" ].insert_many(rawinfo_samples) - analyzer = setup_analyzer(self.platform_id) - analyzer.recompute_analytics() + analyzer.recompute() cursor = self.db_access.db_mongo_client[self.platform_id][ "memberactivities" ].find( diff --git a/tests/integration/test_memberactivities_reaction.py b/tests/integration/test_memberactivities_reaction.py index 9d8e0f5..da47a47 100644 --- a/tests/integration/test_memberactivities_reaction.py +++ b/tests/integration/test_memberactivities_reaction.py @@ -1,8 +1,8 @@ from datetime import datetime, timedelta from unittest import TestCase -from .utils.analyzer_setup import launch_db_access, setup_analyzer -from .utils.remove_and_setup_guild import setup_db_guild +from .utils.analyzer_setup import launch_db_access +from .utils.setup_platform import setup_platform class TestMemberActivitiesReactions(TestCase): @@ -31,7 +31,7 @@ def test_single_user_action(self): "DROP_I_THR": 1, } - setup_db_guild( + analyzer = setup_platform( self.db_access, self.platform_id, discordId_list=users_id_list, @@ -90,8 +90,8 @@ def test_single_user_action(self): self.db_access.db_mongo_client[self.platform_id][ "rawmemberactivities" ].insert_many(rawinfo_samples) - analyzer = setup_analyzer(self.platform_id) - analyzer.recompute_analytics() + + analyzer.recompute() cursor = self.db_access.db_mongo_client[self.platform_id][ "memberactivities" ].find( diff --git a/tests/integration/test_memberactivities_reply.py b/tests/integration/test_memberactivities_reply.py index ad94875..ff5a400 100644 --- a/tests/integration/test_memberactivities_reply.py +++ b/tests/integration/test_memberactivities_reply.py @@ -1,8 +1,8 @@ from datetime import datetime, timedelta from unittest import TestCase -from .utils.analyzer_setup import launch_db_access, setup_analyzer -from .utils.remove_and_setup_guild import setup_db_guild +from .utils.analyzer_setup import launch_db_access +from .utils.setup_platform import setup_platform class TestMemberActivitiesReply(TestCase): @@ -28,7 +28,7 @@ def test_single_user_interaction(self): "DROP_H_THR": 2, "DROP_I_THR": 1, } - setup_db_guild( + analyzer = setup_platform( self.db_access, self.platform_id, discordId_list=users_id_list, @@ -88,8 +88,7 @@ def test_single_user_interaction(self): self.db_access.db_mongo_client[self.platform_id][ "rawmemberactivities" ].insert_many(rawinfo_samples) - analyzer = setup_analyzer(self.platform_id) - analyzer.recompute_analytics() + analyzer.recompute() cursor = self.db_access.db_mongo_client[self.platform_id][ "memberactivities" ].find( diff --git a/tests/integration/test_mentioned_active_members_from_message.py b/tests/integration/test_mentioned_active_members_from_message.py index 47a862e..046db0f 100644 --- a/tests/integration/test_mentioned_active_members_from_message.py +++ b/tests/integration/test_mentioned_active_members_from_message.py @@ -1,7 +1,7 @@ from datetime import datetime, timedelta -from .utils.analyzer_setup import launch_db_access, setup_analyzer -from .utils.remove_and_setup_guild import setup_db_guild +from .utils.analyzer_setup import launch_db_access +from .utils.setup_platform import setup_platform def test_mention_active_members_from_rawinfo(): @@ -18,7 +18,7 @@ def test_mention_active_members_from_rawinfo(): "user1", "user2", ] - setup_db_guild( + analyzer = setup_platform( db_access=db_access, platform_id=platform_id, discordId_list=acc_id, @@ -80,7 +80,6 @@ def test_mention_active_members_from_rawinfo(): rawinfo_samples ) - analyzer = setup_analyzer(platform_id) analyzer.run_once() memberactivities_cursor = db_access.query_db_find( diff --git a/tests/integration/test_neo4j_compute_metrics.py b/tests/integration/test_neo4j_compute_metrics.py index c40d3e4..b94d825 100644 --- a/tests/integration/test_neo4j_compute_metrics.py +++ b/tests/integration/test_neo4j_compute_metrics.py @@ -1,6 +1,6 @@ import numpy as np -from discord_analyzer.metrics.neo4j_analytics import Neo4JAnalytics -from discord_analyzer.schemas import GraphSchema +from tc_analyzer_lib.metrics.neo4j_analytics import Neo4JAnalytics +from tc_analyzer_lib.schemas import GraphSchema from tc_neo4j_lib.neo4j_ops import Neo4jOps diff --git a/tests/integration/test_neo4j_compute_metrics_from_start.py b/tests/integration/test_neo4j_compute_metrics_from_start.py index 6aaf780..a4cbc2d 100644 --- a/tests/integration/test_neo4j_compute_metrics_from_start.py +++ b/tests/integration/test_neo4j_compute_metrics_from_start.py @@ -1,6 +1,6 @@ import numpy as np -from discord_analyzer.metrics.neo4j_analytics import Neo4JAnalytics -from discord_analyzer.schemas import GraphSchema +from tc_analyzer_lib.metrics.neo4j_analytics import Neo4JAnalytics +from tc_analyzer_lib.schemas import GraphSchema from tc_neo4j_lib.neo4j_ops import Neo4jOps diff --git a/tests/integration/test_neo4j_projection_utils_computed_dates.py b/tests/integration/test_neo4j_projection_utils_computed_dates.py index a0ff1cd..dcf6894 100644 --- a/tests/integration/test_neo4j_projection_utils_computed_dates.py +++ b/tests/integration/test_neo4j_projection_utils_computed_dates.py @@ -1,5 +1,5 @@ -from discord_analyzer.algorithms.neo4j_analysis.utils import ProjectionUtils -from discord_analyzer.schemas import GraphSchema +from tc_analyzer_lib.algorithms.neo4j_analysis.utils import ProjectionUtils +from tc_analyzer_lib.schemas import GraphSchema from tc_neo4j_lib.neo4j_ops import Neo4jOps diff --git a/tests/integration/test_network_graph_creation.py b/tests/integration/test_network_graph_creation.py deleted file mode 100644 index 95f10fe..0000000 --- a/tests/integration/test_network_graph_creation.py +++ /dev/null @@ -1,180 +0,0 @@ -# test out local clustering coefficient with all nodes connected -from datetime import datetime, timedelta - -import networkx as nx -import numpy as np -import pytest -from discord_analyzer.algorithms.utils.activity import Activity -from tc_neo4j_lib.neo4j_ops import Neo4jOps - - -@pytest.mark.skip("To be updated to platform centric!") -def test_network_graph_create(): - from .utils.mock_graph import generate_mock_graph, store_mock_data_in_neo4j - - community_id = "4321" - neo4j_ops = Neo4jOps.get_instance() - # deleting all data - neo4j_ops.gds.run_cypher("MATCH (n) DETACH DELETE (n)") - - guildId = "1234" - acc_names = np.array(["1000", "1001", "1002"]) - graph_dict = {} - - # saving the desired outputs - desired_outputs = [] - - # Generating 1st graph - np.random.seed(123) - int_matrix = {} - int_matrix[Activity.Reply] = np.array( - [ - [0, 1, 2], - [0, 0, 3], - [0, 4, 0], - ] - ) - - int_matrix[Activity.Mention] = np.array( - [ - [0, 1, 2], - [0, 0, 3], - [0, 4, 0], - ] - ) - - int_matrix[Activity.Reaction] = np.array( - [ - [0, 1, 2], - [0, 0, 3], - [0, 4, 0], - ] - ) - - graph = generate_mock_graph(int_matrix, acc_names) - - node_att = {} - for i, node in enumerate(list(graph)): - node_att[node] = acc_names[i] - - nx.set_node_attributes(graph, node_att, "acc_name") - - graph_date = datetime.now() - graph_date_timestamp = graph_date.replace( - hour=0, minute=0, second=0, microsecond=0 - ).timestamp() - graph_dict[graph_date] = graph - - desired_outputs.extend( - [ - ["1000", 1, graph_date_timestamp, "1001"], - ["1000", 2, graph_date_timestamp, "1002"], - ["1001", 3, graph_date_timestamp, "1002"], - ["1002", 4, graph_date_timestamp, "1001"], - ] - ) - - # Generating 2nd graph - int_matrix = {} - int_matrix[Activity.Reply] = np.array( - [ - [0, 0, 1], - [2, 0, 5], - [0, 0, 0], - ] - ) - - int_matrix[Activity.Mention] = np.array( - [ - [0, 0, 1], - [2, 0, 5], - [0, 0, 0], - ] - ) - - int_matrix[Activity.Reaction] = np.array( - [ - [0, 0, 1], - [2, 0, 5], - [0, 0, 0], - ] - ) - - graph = generate_mock_graph(int_matrix, acc_names) - - nx.set_node_attributes(graph, node_att, "acc_name") - - graph_date = datetime.now() + timedelta(days=-1) - graph_date_timestamp = graph_date.replace( - hour=0, minute=0, second=0, microsecond=0 - ).timestamp() - graph_dict[graph_date] = graph - - desired_outputs.extend( - [ - ["1000", 1, graph_date_timestamp, "1002"], - ["1001", 2, graph_date_timestamp, "1000"], - ["1001", 5, graph_date_timestamp, "1002"], - ] - ) - - # generating 3rd graph - int_matrix = {} - int_matrix[Activity.Reply] = np.array( - [ - [0, 0, 3], - [0, 0, 0], - [1, 0, 0], - ] - ) - int_matrix[Activity.Mention] = np.array( - [ - [0, 0, 3], - [0, 0, 0], - [1, 0, 0], - ] - ) - int_matrix[Activity.Reaction] = np.array( - [ - [0, 0, 3], - [0, 0, 0], - [1, 0, 0], - ] - ) - - graph = generate_mock_graph(int_matrix, acc_names) - nx.set_node_attributes(graph, node_att, "acc_name") - - graph_date = datetime.now() + timedelta(days=-8) - graph_date_timestamp = graph_date.replace( - hour=0, minute=0, second=0, microsecond=0 - ).timestamp() - graph_dict[graph_date] = graph - - desired_outputs.extend( - [ - ["1000", 3, graph_date_timestamp, "1002"], - ["1002", 1, graph_date_timestamp, "1000"], - ] - ) - - # DATABASE SAVING - - store_mock_data_in_neo4j( - graph_dict=graph_dict, guildId=guildId, community_id=community_id - ) - - results = neo4j_ops.gds.run_cypher( - f""" - MATCH (a:{user_label}) -[:{is_member}] -> (g:{platform_label} {{guildId: '{platform_id}'}}) - MATCH (a)-[r{interacted_with}]-> (b:{user_label}) - RETURN - a.id as fromUserId, - r.weight as weight, - r.date as date, - b.id as toUserId - """ - ) - print(desired_outputs) - print(results) - assert desired_outputs in results.values diff --git a/tests/integration/test_node_stats.py b/tests/integration/test_node_stats.py index f038dff..ae1b08a 100644 --- a/tests/integration/test_node_stats.py +++ b/tests/integration/test_node_stats.py @@ -1,6 +1,6 @@ # test out local clustering coefficient with all nodes connected -from discord_analyzer.algorithms.neo4j_analysis.analyzer_node_stats import NodeStats -from discord_analyzer.schemas import GraphSchema +from tc_analyzer_lib.algorithms.neo4j_analysis.analyzer_node_stats import NodeStats +from tc_analyzer_lib.schemas import GraphSchema from tc_neo4j_lib.neo4j_ops import Neo4jOps diff --git a/tests/integration/test_platforms_base_config.py b/tests/integration/test_platforms_base_config.py index f316919..ec39cab 100644 --- a/tests/integration/test_platforms_base_config.py +++ b/tests/integration/test_platforms_base_config.py @@ -1,12 +1,12 @@ import unittest -from discord_analyzer.schemas import ( +from tc_analyzer_lib.schemas import ( ActivityDirection, ActivityType, HourlyAnalytics, RawAnalytics, ) -from discord_analyzer.schemas.platform_configs.config_base import PlatformConfigBase +from tc_analyzer_lib.schemas.platform_configs.config_base import PlatformConfigBase class TestPlatformBaseConfig(unittest.TestCase): diff --git a/tests/integration/test_publish_on_success.py b/tests/integration/test_publish_on_success_recompute_false.py similarity index 94% rename from tests/integration/test_publish_on_success.py rename to tests/integration/test_publish_on_success_recompute_false.py index 20e4cc0..007b9f6 100644 --- a/tests/integration/test_publish_on_success.py +++ b/tests/integration/test_publish_on_success_recompute_false.py @@ -1,20 +1,20 @@ import os from datetime import datetime, timedelta -from automation.utils.interfaces import ( +from bson.objectid import ObjectId +from dotenv import load_dotenv +from tc_analyzer_lib.automation.utils.interfaces import ( Automation, AutomationAction, AutomationReport, AutomationTrigger, ) -from bson.objectid import ObjectId -from discord_utils import publish_on_success -from dotenv import load_dotenv +from tc_analyzer_lib.publish_on_success import publish_on_success from .utils.analyzer_setup import launch_db_access -def test_publish_on_success_check_notification_choreographies(): +def test_publish_on_success_recompute_false_check_notification_choreographies(): """ test the publish on success functions we want to check the database if the notify choreographies are created @@ -32,8 +32,8 @@ def test_publish_on_success_check_notification_choreographies(): {"_id": ObjectId(platform_id)} ) - db_access.db_mongo_client.drop_database(platform_id) - db_access.db_mongo_client.drop_database(guild_id) + db_access.db_mongo_client.drop_database(platform_id) + db_access.db_mongo_client.drop_database(guild_id) db_access.db_mongo_client["Saga"].drop_collection("sagas") db_access.db_mongo_client[at_db].drop_collection(at_collection) @@ -238,14 +238,12 @@ def test_publish_on_success_check_notification_choreographies(): db_access.db_mongo_client[at_db][at_collection].insert_one(automation.to_dict()) - date_yesterday = ( - (datetime.now() - timedelta(days=1)) - .replace(hour=0, minute=0, second=0, microsecond=0) + date_yesterday = (datetime.now() - timedelta(days=1)).replace( + hour=0, minute=0, second=0, microsecond=0 ) - date_two_past_days = ( - (datetime.now() - timedelta(days=2)) - .replace(hour=0, minute=0, second=0, microsecond=0) + date_two_past_days = (datetime.now() - timedelta(days=2)).replace( + hour=0, minute=0, second=0, microsecond=0 ) db_access.db_mongo_client[platform_id]["memberactivities"].insert_many( @@ -299,8 +297,7 @@ def test_publish_on_success_check_notification_choreographies(): ] ) - sample_args_data = saga_id - publish_on_success(None, None, sample_args_data) + publish_on_success(platform_id, recompute=False) notification_count = db_access.db_mongo_client["Saga"]["sagas"].count_documents( {"choreography.name": "DISCORD_NOTIFY_USERS"} diff --git a/tests/integration/test_publish_on_success_recompute_true.py b/tests/integration/test_publish_on_success_recompute_true.py new file mode 100644 index 0000000..79ef6e3 --- /dev/null +++ b/tests/integration/test_publish_on_success_recompute_true.py @@ -0,0 +1,350 @@ +import os +from datetime import datetime, timedelta + +from bson.objectid import ObjectId +from dotenv import load_dotenv +from tc_analyzer_lib.automation.utils.interfaces import ( + Automation, + AutomationAction, + AutomationReport, + AutomationTrigger, +) +from tc_analyzer_lib.publish_on_success import publish_on_success + +from .utils.analyzer_setup import launch_db_access + + +def test_publish_on_success_recompute_true_check_notification_choreographies(): + """ + test the publish on success functions + we want to check the database if the notify choreographies are created + """ + load_dotenv() + platform_id = "515151515151515151515151" + guild_id = "1234" + saga_id = "000000011111113333377777ie0w" + expected_owner_id = "334461287892" + db_access = launch_db_access(guild_id) + at_db = os.getenv("AUTOMATION_DB_NAME") + at_collection = os.getenv("AUTOMATION_DB_COLLECTION") + + db_access.db_mongo_client["Core"].drop_collection("platforms") + db_access.db_mongo_client["Core"].drop_collection("users") + db_access.db_mongo_client.drop_database(platform_id) + db_access.db_mongo_client.drop_database(guild_id) + db_access.db_mongo_client["Saga"].drop_collection("sagas") + db_access.db_mongo_client[at_db].drop_collection(at_collection) + + 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, + } + window = { + "period_size": 7, + "step_size": 1, + } + community_id = "aabbccddeeff001122334455" + owner_discord_id = "123487878912" + + db_access.db_mongo_client["Core"]["platforms"].insert_one( + { + "_id": ObjectId(platform_id), + "name": "discord", + "metadata": { + "id": guild_id, + "icon": "111111111111111111111111", + "name": "A guild", + "resources": ["4455178"], + "window": window, + "action": act_param, + "period": datetime.now() - timedelta(days=10), + }, + "community": ObjectId(community_id), + "disconnectedAt": None, + "connectedAt": (datetime.now() - timedelta(days=10)), + "isInProgress": True, + "createdAt": datetime(2023, 11, 1), + "updatedAt": datetime(2023, 11, 1), + } + ) + + db_access.db_mongo_client["Core"]["users"].insert_one( + { + "_id": ObjectId(platform_id), + "discordId": owner_discord_id, + "communities": [ObjectId(community_id)], + "createdAt": datetime(2023, 12, 1), + "updatedAt": datetime(2023, 12, 1), + "tcaAt": datetime(2023, 12, 2), + } + ) + + db_access.db_mongo_client["Saga"]["sagas"].insert_one( + { + "choreography": { + "name": "DISCORD_UPDATE_CHANNELS", + "transactions": [ + { + "queue": "DISCORD_BOT", + "event": "FETCH", + "order": 1, + "status": "SUCCESS", + "start": datetime.now(), + "end": datetime.now(), + "runtime": 1, + }, + { + "queue": "DISCORD_ANALYZER", + "event": "RUN", + "order": 2, + "status": "SUCCESS", + "start": datetime.now(), + "end": datetime.now(), + "runtime": 1, + }, + ], + }, + "status": "IN_PROGRESS", + "data": { + "platformId": platform_id, + "created": False, + "discordId": expected_owner_id, + "message": "data is ready", + "useFallback": True, + }, + "sagaId": saga_id, + "createdAt": datetime.now(), + "updatedAt": datetime.now(), + } + ) + + db_access.db_mongo_client[guild_id]["guildmembers"].insert_many( + [ + { + "discordId": "1111", + "username": "user1", + "roles": [], + "joinedAt": datetime.now() - timedelta(days=10), + "avatar": None, + "isBot": False, + "discriminator": "0", + "permissions": "6677", + "deletedAt": None, + "globalName": "User1GlobalName", + "nickname": "User1NickName", # this will be used for the message + }, + { + "discordId": "1112", + "username": "user2", + "roles": [], + "joinedAt": datetime.now() - timedelta(days=10), + "avatar": None, + "isBot": False, + "discriminator": "0", + "permissions": "6677", + "deletedAt": None, + "globalName": "User2GlobalName", # this will be used for the message + "nickname": None, + }, + { + "discordId": "1113", + "username": "user3", # this will be used for the message + "roles": [], + "joinedAt": datetime.now() - timedelta(days=10), + "avatar": None, + "isBot": False, + "discriminator": "0", + "permissions": "6677", + "deletedAt": None, + "globalName": None, + "nickname": None, + }, + { + "discordId": "1116", + "username": "user6", + "roles": [], + "joinedAt": datetime.now() - timedelta(days=10), + "avatar": None, + "isBot": False, + "discriminator": "0", + "permissions": "6677", + "deletedAt": None, + "globalName": "User6GlobalName", + "nickname": "User6NickName", + }, + { + "discordId": "1119", + "username": "user9", + "roles": [], + "joinedAt": datetime.now() - timedelta(days=10), + "avatar": None, + "isBot": False, + "discriminator": "0", + "permissions": "6677", + "deletedAt": None, + "globalName": "User9GlobalName", + "nickname": None, + }, + { + "discordId": "999", + "username": "community_manager", + "roles": [], + "joinedAt": datetime.now() - timedelta(days=10), + "avatar": None, + "isBot": False, + "discriminator": "0", + "permissions": "6677", + "deletedAt": None, + "globalName": "User9GlobalName", + "nickname": None, + }, + ] + ) + + triggers = [ + AutomationTrigger(options={"category": "all_new_disengaged"}, enabled=True), + AutomationTrigger(options={"category": "all_new_active"}, enabled=False), + ] + actions = [ + AutomationAction( + template="hey {{ngu}}! please get back to us!", + options={}, + enabled=True, + ), + AutomationAction( + template="hey {{ngu}}! please get back to us2!", + options={}, + enabled=False, + ), + ] + + report = AutomationReport( + recipientIds=["999"], + template="hey body! This users were messaged:\n{{#each usernames}}{{this}}{{/each}}", + options={}, + enabled=True, + ) + today_time = datetime.now() + + automation = Automation( + guild_id, + triggers, + actions, + report, + enabled=True, + createdAt=today_time, + updatedAt=today_time, + ) + + db_access.db_mongo_client[at_db][at_collection].insert_one(automation.to_dict()) + + date_yesterday = (datetime.now() - timedelta(days=1)).replace( + hour=0, minute=0, second=0, microsecond=0 + ) + + date_two_past_days = (datetime.now() - timedelta(days=2)).replace( + hour=0, minute=0, second=0, microsecond=0 + ) + + db_access.db_mongo_client[platform_id]["memberactivities"].insert_many( + [ + { + "date": date_yesterday, + "all_joined": [], + "all_joined_day": [], + "all_consistent": [], + "all_vital": [], + "all_active": [], + "all_connected": [], + "all_paused": [], + "all_new_disengaged": ["1111", "1112", "1113"], + "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": [], + }, + { + "date": date_two_past_days, + "all_joined": [], + "all_joined_day": [], + "all_consistent": [], + "all_vital": [], + "all_active": [], + "all_connected": [], + "all_paused": [], + "all_new_disengaged": ["1116", "1119"], + "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": [], + }, + ] + ) + + publish_on_success(platform_id, recompute=True) + + notification_count = db_access.db_mongo_client["Saga"]["sagas"].count_documents( + {"choreography.name": "DISCORD_NOTIFY_USERS"} + ) + + assert notification_count == 5 + + user1_doc = db_access.db_mongo_client["Saga"]["sagas"].find_one( + {"data.discordId": "1111"} + ) + assert user1_doc["data"]["message"] == ("hey User1NickName! please get back to us!") + + user2_doc = db_access.db_mongo_client["Saga"]["sagas"].find_one( + {"data.discordId": "1112"} + ) + assert user2_doc["data"]["message"] == ( + "hey User2GlobalName! please get back to us!" + ) + + user3_doc = db_access.db_mongo_client["Saga"]["sagas"].find_one( + {"data.discordId": "1113"} + ) + assert user3_doc["data"]["message"] == ("hey user3! please get back to us!") + + user_cm_doc = db_access.db_mongo_client["Saga"]["sagas"].find_one( + {"data.discordId": "999"} + ) + expected_msg = "hey body! This users were messaged:\n" + expected_msg += "- User1NickName\n- User2GlobalName\n- user3\n" + assert user_cm_doc["data"]["message"] == expected_msg + + job_finished_saga = db_access.db_mongo_client["Saga"]["sagas"].find_one( + {"data.discordId": owner_discord_id} + ) + assert job_finished_saga["data"]["message"] == ( + "Your data import into TogetherCrew is complete! " + "See your insights on your dashboard https://app.togethercrew.com/." + " If you have questions send a DM to katerinabc (Discord) or k_bc0 (Telegram)." + ) diff --git a/tests/integration/test_rawinfo_webhook_fetching.py b/tests/integration/test_rawinfo_webhook_fetching.py index 1f5aa11..96e8575 100644 --- a/tests/integration/test_rawinfo_webhook_fetching.py +++ b/tests/integration/test_rawinfo_webhook_fetching.py @@ -1,7 +1,7 @@ from datetime import datetime, timedelta -from discord_analyzer.models.RawInfoModel import RawInfoModel -from utils.mongo import MongoSingleton +from tc_analyzer_lib.models.RawInfoModel import RawInfoModel +from tc_analyzer_lib.utils.mongo import MongoSingleton def test_rawinfo_get_day_entry_empty_data(): diff --git a/tests/integration/test_service_connection.py b/tests/integration/test_service_connection.py index 1d4c4e7..ff828d2 100644 --- a/tests/integration/test_service_connection.py +++ b/tests/integration/test_service_connection.py @@ -1,5 +1,5 @@ +from tc_analyzer_lib.utils.credentials import get_rabbit_mq_credentials from tc_messageBroker.message_broker import RabbitMQ -from utils.credentials import get_rabbit_mq_credentials def test_rabbit_mq_connect(): diff --git a/tests/integration/utils/analyzer_setup.py b/tests/integration/utils/analyzer_setup.py index 914049c..3c4c87f 100644 --- a/tests/integration/utils/analyzer_setup.py +++ b/tests/integration/utils/analyzer_setup.py @@ -1,19 +1,5 @@ -import os - -from discord_analyzer.DB_operations.mongodb_access import DB_access -from discord_analyzer.tc_analyzer import TCAnalyzer from dotenv import load_dotenv - - -def setup_analyzer( - platform_id: str, -) -> TCAnalyzer: - load_dotenv() - - analyzer = TCAnalyzer(platform_id) - analyzer.database_connect() - - return analyzer +from tc_analyzer_lib.DB_operations.mongodb_access import DB_access def launch_db_access(platform_id: str): diff --git a/tests/integration/utils/mock_graph.py b/tests/integration/utils/mock_graph.py index bef5ae0..14eee74 100644 --- a/tests/integration/utils/mock_graph.py +++ b/tests/integration/utils/mock_graph.py @@ -1,7 +1,7 @@ -import os +# import os -from discord_analyzer.tc_analyzer import TCAnalyzer -from dotenv import load_dotenv +# from dotenv import load_dotenv +# from tc_analyzer_lib.tc_analyzer import TCAnalyzer from tc_core_analyzer_lib.assess_engagement import EngagementAssessment from tc_core_analyzer_lib.utils.activity import DiscordActivity @@ -64,25 +64,25 @@ def generate_mock_graph(int_matrix, acc_names): return graph -def store_mock_data_in_neo4j(graph_dict, guildId, community_id): - # CREDS - load_dotenv() +# def store_mock_data_in_neo4j(graph_dict, guildId, community_id): +# # CREDS +# load_dotenv() - analyzer = TCAnalyzer(guildId) - analyzer.database_connect() +# analyzer = TCAnalyzer(guildId) +# analyzer.database_connect() - guilds_data = {} +# guilds_data = {} - guilds_data["heatmaps"] = None - guilds_data["memberactivities"] = ( - None, - graph_dict, - ) +# guilds_data["heatmaps"] = None +# guilds_data["memberactivities"] = ( +# None, +# graph_dict, +# ) - analyzer.DB_connections.store_analytics_data( - analytics_data=guilds_data, - guild_id=guildId, - community_id=community_id, - remove_heatmaps=False, - remove_memberactivities=False, - ) +# analyzer.DB_connections.store_analytics_data( +# analytics_data=guilds_data, +# guild_id=guildId, +# community_id=community_id, +# remove_heatmaps=False, +# remove_memberactivities=False, +# ) diff --git a/tests/integration/utils/remove_and_setup_guild.py b/tests/integration/utils/setup_platform.py similarity index 83% rename from tests/integration/utils/remove_and_setup_guild.py rename to tests/integration/utils/setup_platform.py index 7470913..2bf06b4 100644 --- a/tests/integration/utils/remove_and_setup_guild.py +++ b/tests/integration/utils/setup_platform.py @@ -3,10 +3,11 @@ import numpy as np from bson.objectid import ObjectId -from discord_analyzer.DB_operations.mongodb_access import DB_access +from tc_analyzer_lib.DB_operations.mongodb_access import DB_access +from tc_analyzer_lib.tc_analyzer import TCAnalyzer -def setup_db_guild( +def setup_platform( db_access: DB_access, platform_id: str, discordId_list: list[str] = ["973993299281076285"], @@ -14,7 +15,7 @@ def setup_db_guild( dates: Optional[list[datetime]] = None, days_ago_period: int = 30, **kwargs, -): +) -> TCAnalyzer: """ Remove the guild from Core databse and then insert it there also drop the guildId database and re-create @@ -30,6 +31,14 @@ def setup_db_guild( ) db_access.db_mongo_client.drop_database(platform_id) + period = (datetime.now() - timedelta(days=days_ago_period)).replace( + hour=0, minute=0, second=0, microsecond=0 + ) + window = kwargs.get( + "window", + {"period_size": 7, "step_size": 1}, + ) + action = kwargs.get( "action", { @@ -59,11 +68,9 @@ def setup_db_guild( "icon": "111111111111111111111111", "name": "A guild", "resources": resources, - "window": {"period_size": 7, "step_size": 1}, + "window": window, "action": action, - "period": (datetime.now() - timedelta(days=days_ago_period)).replace( - hour=0, minute=0, second=0, microsecond=0 - ), + "period": period, }, "community": ObjectId(community_id), "disconnectedAt": None, @@ -74,6 +81,14 @@ def setup_db_guild( } ) + analyzer = TCAnalyzer( + platform_id, + resources=resources, + period=period, + action=action, + window=window, + ) + if dates is None: dates_using = np.repeat( datetime.now() - timedelta(days=10), len(discordId_list) @@ -101,3 +116,5 @@ def setup_db_guild( "options": {}, } ) + + return analyzer diff --git a/tests/unit/test_analyzer_heatmaps_compute_iteration_counts.py b/tests/unit/test_analyzer_heatmaps_compute_iteration_counts.py index 8252ec8..5de93a5 100644 --- a/tests/unit/test_analyzer_heatmaps_compute_iteration_counts.py +++ b/tests/unit/test_analyzer_heatmaps_compute_iteration_counts.py @@ -1,8 +1,8 @@ from datetime import datetime from unittest import TestCase -from discord_analyzer.metrics.heatmaps import Heatmaps -from discord_analyzer.schemas.platform_configs import DiscordAnalyzerConfig +from tc_analyzer_lib.metrics.heatmaps import Heatmaps +from tc_analyzer_lib.schemas.platform_configs import DiscordAnalyzerConfig class TestAnalyzerHeatmapsIterationCount(TestCase): diff --git a/tests/unit/test_automation_class.py b/tests/unit/test_automation_class.py index b7e02d4..31aaf45 100644 --- a/tests/unit/test_automation_class.py +++ b/tests/unit/test_automation_class.py @@ -1,7 +1,7 @@ import unittest from datetime import datetime -from automation.utils.interfaces import ( +from tc_analyzer_lib.automation.utils.interfaces import ( Automation, AutomationAction, AutomationReport, diff --git a/tests/unit/test_automation_get_handler_type.py b/tests/unit/test_automation_get_handler_type.py index ccbd8bd..434583c 100644 --- a/tests/unit/test_automation_get_handler_type.py +++ b/tests/unit/test_automation_get_handler_type.py @@ -1,6 +1,6 @@ import unittest -from automation.automation_workflow import AutomationWorkflow +from tc_analyzer_lib.automation.automation_workflow import AutomationWorkflow class TestGetHandlerType(unittest.TestCase): diff --git a/tests/unit/test_automation_trigger_action_report.py b/tests/unit/test_automation_trigger_action_report.py index 4f2ec9f..c8b8802 100644 --- a/tests/unit/test_automation_trigger_action_report.py +++ b/tests/unit/test_automation_trigger_action_report.py @@ -1,6 +1,6 @@ import unittest -from automation.utils.interfaces import ( +from tc_analyzer_lib.automation.utils.interfaces import ( AutomationAction, AutomationReport, AutomationTrigger, diff --git a/tests/unit/test_compile_message.py b/tests/unit/test_compile_message.py index 57dae41..d7a3239 100644 --- a/tests/unit/test_compile_message.py +++ b/tests/unit/test_compile_message.py @@ -1,6 +1,6 @@ import unittest -from automation.automation_workflow import AutomationWorkflow +from tc_analyzer_lib.automation.automation_workflow import AutomationWorkflow class CompileTemplateMessage(unittest.TestCase): diff --git a/tests/unit/test_converting_to_dict.py b/tests/unit/test_converting_to_dict.py index b4800c0..505dc17 100644 --- a/tests/unit/test_converting_to_dict.py +++ b/tests/unit/test_converting_to_dict.py @@ -1,4 +1,4 @@ -from discord_analyzer.algorithms.utils.member_activity_utils import convert_to_dict +from tc_analyzer_lib.algorithms.utils.member_activity_utils import convert_to_dict def test_empty(): diff --git a/tests/unit/test_creds_loading.py b/tests/unit/test_creds_loading.py index 2d35349..3d8f27c 100644 --- a/tests/unit/test_creds_loading.py +++ b/tests/unit/test_creds_loading.py @@ -1,4 +1,4 @@ -from utils.credentials import ( +from tc_analyzer_lib.utils.credentials import ( get_mongo_credentials, get_rabbit_mq_credentials, get_redis_credentials, diff --git a/tests/unit/test_engagement_notifier_subtract_users.py b/tests/unit/test_engagement_notifier_subtract_users.py index 8140903..613c8e8 100644 --- a/tests/unit/test_engagement_notifier_subtract_users.py +++ b/tests/unit/test_engagement_notifier_subtract_users.py @@ -1,4 +1,4 @@ -from automation.utils.automation_base import AutomationBase +from tc_analyzer_lib.automation.utils.automation_base import AutomationBase def test_subtract_users_empty_data(): diff --git a/tests/unit/test_generate_interaction_mtx.py b/tests/unit/test_generate_interaction_mtx.py index c5a4133..fe545a2 100644 --- a/tests/unit/test_generate_interaction_mtx.py +++ b/tests/unit/test_generate_interaction_mtx.py @@ -1,5 +1,5 @@ -from discord_analyzer.algorithms.utils.activity import Activity -from discord_analyzer.algorithms.utils.compute_interaction_mtx_utils import ( +from tc_analyzer_lib.algorithms.utils.activity import Activity +from tc_analyzer_lib.algorithms.utils.compute_interaction_mtx_utils import ( generate_interaction_matrix, ) diff --git a/tests/unit/test_generate_interaction_mtx_mention.py b/tests/unit/test_generate_interaction_mtx_mention.py index d5da9bd..dbcec85 100644 --- a/tests/unit/test_generate_interaction_mtx_mention.py +++ b/tests/unit/test_generate_interaction_mtx_mention.py @@ -1,5 +1,5 @@ -from discord_analyzer.algorithms.utils.activity import Activity -from discord_analyzer.algorithms.utils.compute_interaction_mtx_utils import ( +from tc_analyzer_lib.algorithms.utils.activity import Activity +from tc_analyzer_lib.algorithms.utils.compute_interaction_mtx_utils import ( generate_interaction_matrix, ) diff --git a/tests/unit/test_generate_interaction_mtx_reaction.py b/tests/unit/test_generate_interaction_mtx_reaction.py index 66e86f7..1183545 100644 --- a/tests/unit/test_generate_interaction_mtx_reaction.py +++ b/tests/unit/test_generate_interaction_mtx_reaction.py @@ -1,5 +1,5 @@ -from discord_analyzer.algorithms.utils.activity import Activity -from discord_analyzer.algorithms.utils.compute_interaction_mtx_utils import ( +from tc_analyzer_lib.algorithms.utils.activity import Activity +from tc_analyzer_lib.algorithms.utils.compute_interaction_mtx_utils import ( generate_interaction_matrix, ) diff --git a/tests/unit/test_generate_interaction_mtx_reply.py b/tests/unit/test_generate_interaction_mtx_reply.py index 840f138..71985ea 100644 --- a/tests/unit/test_generate_interaction_mtx_reply.py +++ b/tests/unit/test_generate_interaction_mtx_reply.py @@ -1,5 +1,5 @@ -from discord_analyzer.algorithms.utils.activity import Activity -from discord_analyzer.algorithms.utils.compute_interaction_mtx_utils import ( +from tc_analyzer_lib.algorithms.utils.activity import Activity +from tc_analyzer_lib.algorithms.utils.compute_interaction_mtx_utils import ( generate_interaction_matrix, ) diff --git a/tests/unit/test_get_timestamp.py b/tests/unit/test_get_timestamp.py index 6a5273b..adc61f2 100644 --- a/tests/unit/test_get_timestamp.py +++ b/tests/unit/test_get_timestamp.py @@ -1,8 +1,8 @@ import unittest from datetime import datetime, timezone -from discord_analyzer.DB_operations.network_graph import NetworkGraph -from discord_analyzer.schemas import GraphSchema +from tc_analyzer_lib.DB_operations.network_graph import NetworkGraph +from tc_analyzer_lib.schemas import GraphSchema class TestGetTimestamp(unittest.TestCase): diff --git a/tests/unit/test_graph_schema.py b/tests/unit/test_graph_schema.py index 210a117..851a307 100644 --- a/tests/unit/test_graph_schema.py +++ b/tests/unit/test_graph_schema.py @@ -1,6 +1,6 @@ from unittest import TestCase -from discord_analyzer.schemas import GraphSchema +from tc_analyzer_lib.schemas import GraphSchema class TestGraphSchema(TestCase): diff --git a/tests/unit/test_heatmaps_analytics_base_process_vectors.py b/tests/unit/test_heatmaps_analytics_base_process_vectors.py index 3b7495f..aee8195 100644 --- a/tests/unit/test_heatmaps_analytics_base_process_vectors.py +++ b/tests/unit/test_heatmaps_analytics_base_process_vectors.py @@ -1,6 +1,6 @@ from unittest import TestCase -from discord_analyzer.metrics.heatmaps.analytics_hourly import AnalyticsHourly +from tc_analyzer_lib.metrics.heatmaps.analytics_hourly import AnalyticsHourly class TestRawMemberActivitiesProcessVectors(TestCase): diff --git a/tests/unit/test_member_activity_utils.py b/tests/unit/test_member_activity_utils.py index 50d2c84..2bd9a59 100644 --- a/tests/unit/test_member_activity_utils.py +++ b/tests/unit/test_member_activity_utils.py @@ -1,6 +1,6 @@ from datetime import datetime, timedelta -from discord_analyzer.algorithms.utils.member_activity_history_utils import ( +from tc_analyzer_lib.algorithms.utils.member_activity_history_utils import ( MemberActivityPastUtils, ) diff --git a/tests/unit/test_mongo_singleton.py b/tests/unit/test_mongo_singleton.py index 9734592..33eed71 100644 --- a/tests/unit/test_mongo_singleton.py +++ b/tests/unit/test_mongo_singleton.py @@ -1,7 +1,7 @@ import unittest from pymongo import MongoClient -from utils.mongo import MongoSingleton +from tc_analyzer_lib.utils.mongo import MongoSingleton class TestMongoSingleton(unittest.TestCase): diff --git a/tests/unit/test_per_account_interaction.py b/tests/unit/test_per_account_interaction.py index 8a0270e..cb8a722 100644 --- a/tests/unit/test_per_account_interaction.py +++ b/tests/unit/test_per_account_interaction.py @@ -1,4 +1,4 @@ -from discord_analyzer.algorithms.analytics_interactions_script import ( +from tc_analyzer_lib.algorithms.analytics_interactions_script import ( per_account_interactions, ) diff --git a/tests/unit/test_prepare_results_per_acc.py b/tests/unit/test_prepare_results_per_acc.py index dc4d936..6cc66ea 100644 --- a/tests/unit/test_prepare_results_per_acc.py +++ b/tests/unit/test_prepare_results_per_acc.py @@ -1,4 +1,4 @@ -from discord_analyzer.algorithms.utils.compute_interaction_mtx_utils import ( +from tc_analyzer_lib.algorithms.utils.compute_interaction_mtx_utils import ( prepare_per_account, ) diff --git a/tests/unit/test_process_non_reaction_heatmaps.py b/tests/unit/test_process_non_reaction_heatmaps.py index c75155d..fbe4c0b 100644 --- a/tests/unit/test_process_non_reaction_heatmaps.py +++ b/tests/unit/test_process_non_reaction_heatmaps.py @@ -1,7 +1,7 @@ from unittest import TestCase import numpy as np -from discord_analyzer.algorithms.compute_interaction_matrix_discord import ( +from tc_analyzer_lib.algorithms.compute_interaction_matrix_discord import ( process_actions, ) diff --git a/tests/unit/test_schema_hourly_analytics.py b/tests/unit/test_schema_hourly_analytics.py index ee38be5..d6b573c 100644 --- a/tests/unit/test_schema_hourly_analytics.py +++ b/tests/unit/test_schema_hourly_analytics.py @@ -1,6 +1,6 @@ from unittest import TestCase -from discord_analyzer.schemas import ActivityDirection, ActivityType, HourlyAnalytics +from tc_analyzer_lib.schemas import ActivityDirection, ActivityType, HourlyAnalytics class TestHourlyAnalytics(TestCase): diff --git a/tests/unit/test_schema_raw_analytics.py b/tests/unit/test_schema_raw_analytics.py index 742f441..71893a8 100644 --- a/tests/unit/test_schema_raw_analytics.py +++ b/tests/unit/test_schema_raw_analytics.py @@ -1,7 +1,7 @@ from unittest import TestCase -from discord_analyzer.schemas import ActivityDirection, ActivityType -from discord_analyzer.schemas.platform_configs.config_base import RawAnalytics +from tc_analyzer_lib.schemas import ActivityDirection, ActivityType +from tc_analyzer_lib.schemas.platform_configs.config_base import RawAnalytics class TestRawAnalytics(TestCase): diff --git a/utils/rabbitmq.py b/utils/rabbitmq.py deleted file mode 100644 index 452c69a..0000000 --- a/utils/rabbitmq.py +++ /dev/null @@ -1,42 +0,0 @@ -import logging - -from tc_messageBroker import RabbitMQ -from tc_messageBroker.rabbit_mq.queue import Queue -from utils.credentials import get_rabbit_mq_credentials - - -class RabbitMQSingleton: - __instance = None - - def __init__(self): - if RabbitMQSingleton.__instance is not None: - raise Exception("This class is a singleton!") - else: - creds = get_rabbit_mq_credentials() - self.client = self.create_rabbitmq_client(creds) - RabbitMQSingleton.__instance = self - - @staticmethod - def get_instance(): - if RabbitMQSingleton.__instance is None: - try: - RabbitMQSingleton() - logging.info("RabbitMQ broker Connected Successfully!") - except Exception as exp: - logging.error(f"RabbitMQ broker not connected! exp: {exp}") - - return RabbitMQSingleton.__instance - - def get_client(self): - return self.client - - def create_rabbitmq_client(self, rabbit_creds: dict[str, str]): - rabbitmq = RabbitMQ( - broker_url=rabbit_creds["broker_url"], - port=rabbit_creds["port"], - username=rabbit_creds["username"], - password=rabbit_creds["password"], - ) - rabbitmq.connect(queue_name=Queue.DISCORD_ANALYZER) - - return rabbitmq diff --git a/utils/sentryio_service.py b/utils/sentryio_service.py deleted file mode 100644 index bf4da9e..0000000 --- a/utils/sentryio_service.py +++ /dev/null @@ -1,14 +0,0 @@ -import sentry_sdk -from utils.credentials import get_sentryio_service_creds - - -def set_up_sentryio(sample_rate=1.0): - sentry_creds = get_sentryio_service_creds() - sentry_sdk.init( - dsn=sentry_creds["dsn"], - environment=sentry_creds["env"], - # Set traces_sample_rate to 1.0 to capture 100% - # of transactions for performance monitoring. - # We recommend adjusting this value in production. - traces_sample_rate=sample_rate, - ) diff --git a/utils/transactions_ordering.py b/utils/transactions_ordering.py deleted file mode 100644 index d806736..0000000 --- a/utils/transactions_ordering.py +++ /dev/null @@ -1,61 +0,0 @@ -import numpy as np -from tc_messageBroker.rabbit_mq.status import Status - - -def sort_transactions(transactions: list): - """ - sort transactions by their order and status - the NOT_STARTED ones would be at the first of the list - and they are ordered by `order` property - - Parameters: - ------------ - transactions : list[ITransaction] - the list of transactions to order - - Returns: - --------- - transactions_ordered : ndarray(ITransaction) - the transactions ordered by status - the `NOT_STARTED` ones are the firsts - it is actually a numpy array for us to be able to - change the properties in deep memory - tx_not_started_count : int - the not started transactions count - """ - tx_not_started = [] - tx_other = [] - - for tx in transactions: - if tx.status == Status.NOT_STARTED: - tx_not_started.append(tx) - else: - tx_other.append(tx) - - tx_not_started_count = len(tx_not_started) - tx_not_started_sorted = sort_transactions_orderly(tx_not_started) - - transactions_ordered = list(tx_not_started_sorted) - transactions_ordered.extend(tx_other) - - return np.array(transactions_ordered), tx_not_started_count - - -def sort_transactions_orderly(transactions: list): - """ - sort transactions by their `order` property - - Parameters: - ------------ - transactions : list[ITransaction] - the list of transactions to order - - Returns: - --------- - transactions_orderly_sorted : list[ITransaction] - transactions sorted by their order - """ - orders = [tx.order for tx in transactions] - sorted_indices = np.argsort(orders) - - return np.array(transactions)[sorted_indices] diff --git a/worker.py b/worker.py deleted file mode 100644 index d756fd7..0000000 --- a/worker.py +++ /dev/null @@ -1,28 +0,0 @@ -import logging - -from rq import Worker -from utils.redis import RedisSingleton - - -def worker_exception_handler(job, exc_type, exc_value, traceback): - logging.error(" ========= RQ Exception =========") - logging.error(f"JOB: {job}") - logging.error(f"exc_type: {exc_type}") - logging.error(f"exc_value: {exc_value}") - logging.error(f"traceback: {traceback}") - - -if __name__ == "__main__": - logging.basicConfig() - logging.getLogger().setLevel(logging.INFO) - - r = RedisSingleton.get_instance().get_client() - worker = Worker( - queues=["default"], connection=r, exception_handlers=worker_exception_handler - ) - logging.info("Registered the worker!") - try: - worker.work(with_scheduler=True, max_jobs=1) - except KeyboardInterrupt: - worker.clean_registries() - worker.stop_scheduler()