diff --git a/participants/__init__.py b/participants/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/participants/query_db.py b/participants/query_db.py new file mode 100644 index 0000000..087d185 --- /dev/null +++ b/participants/query_db.py @@ -0,0 +1,27 @@ +import datetime +from collections.abc import Collection + +import pandas as pd +from sqlalchemy import and_ + +from config.models import Participant +from setup import db_engine, session + + +def get_usernames( + tester: bool = False, + active: bool = False, + collection_start: datetime.date = datetime.date.fromisoformat("2020-01-01"), + last_upload: datetime.date = datetime.date.today(), +) -> Collection: + query_participant_usernames = session.query(Participant.username).filter( + and_( + Participant.tester == tester, + Participant.active == active, + Participant.collection_start_utc >= collection_start, + Participant.last_upload_utc < last_upload, + ) + ) + with db_engine.connect() as connection: + df_participants = pd.read_sql(query_participant_usernames.statement, connection) + return df_participants diff --git a/test/test_participants.py b/test/test_participants.py new file mode 100644 index 0000000..e449d70 --- /dev/null +++ b/test/test_participants.py @@ -0,0 +1,10 @@ +import unittest + +from participants.query_db import get_usernames + + +class CallsFeatures(unittest.TestCase): + def test_get_usernames(self): + usernames_from_db = get_usernames() + print(usernames_from_db) + self.assertIsNotNone(usernames_from_db)