stress_at_work_analysis/features/proximity.py

31 lines
861 B
Python

from collections.abc import Collection
import pandas as pd
from config.models import Participant, Proximity
from setup import db_engine, session
def get_proximity_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_proximity = (
session.query(Proximity, Participant.username)
.filter(Participant.id == Proximity.participant_id)
.filter(Participant.username.in_(usernames))
)
with db_engine.connect() as connection:
df_proximity = pd.read_sql(query_proximity.statement, connection)
return df_proximity