From 6eca98962f95dd12f4907ec97b4b03efdd266b83 Mon Sep 17 00:00:00 2001 From: junos Date: Wed, 1 Dec 2021 17:08:24 +0100 Subject: [PATCH] Export timezone info, too. --- features/timezone.py | 30 ++++++++++++++++++++++++++ participants/prepare_usernames_file.py | 11 ++++++++++ 2 files changed, 41 insertions(+) create mode 100644 features/timezone.py diff --git a/features/timezone.py b/features/timezone.py new file mode 100644 index 0000000..3ba9d08 --- /dev/null +++ b/features/timezone.py @@ -0,0 +1,30 @@ +from collections.abc import Collection + +import pandas as pd + +from config.models import Participant, Timezone +from setup import db_engine, session + + +def get_timezone_data(usernames: Collection) -> pd.DataFrame: + """ + Read the data from the proximity sensor table and return it in a dataframe. + + Parameters + ---------- + usernames: Collection + A list of usernames to put into the WHERE condition. + + Returns + ------- + df_proximity: pd.DataFrame + A dataframe of proximity data. + """ + query_timezone = ( + session.query(Timezone, Participant.username) + .filter(Participant.id == Timezone.participant_id) + .filter(Participant.username.in_(usernames)) + ) + with db_engine.connect() as connection: + df_timezone = pd.read_sql(query_timezone.statement, connection) + return df_timezone diff --git a/participants/prepare_usernames_file.py b/participants/prepare_usernames_file.py index 16b03d9..5d1e5d1 100644 --- a/participants/prepare_usernames_file.py +++ b/participants/prepare_usernames_file.py @@ -1,5 +1,7 @@ import datetime + import pandas as pd +from features.timezone import get_timezone_data from pyprojroot import here import participants.query_db @@ -50,3 +52,12 @@ participants_usernames_empatica.to_csv( index=False, line_terminator="\n", ) + +timezone_df = get_timezone_data(participants_inactive_usernames) + +timezone_df.to_csv( + here("rapids/data/external/timezone.csv"), + header=True, + index=False, + line_terminator="\n", +)