stress_at_work_analysis/features/screen.py

33 lines
886 B
Python

from collections.abc import Collection
import pandas as pd
from config.models import Participant, Screen
from setup import db_engine, session
screen_status = {0: "off", 1: "on", 2: "locked", 3: "unlocked"}
def get_screen_data(usernames: Collection) -> pd.DataFrame:
"""
Read the data from the screen table and return it in a dataframe.
Parameters
----------
usernames: Collection
A list of usernames to put into the WHERE condition.
Returns
-------
df_screen: pd.DataFrame
A dataframe of screen data.
"""
query_screen = (
session.query(Screen, Participant.username)
.filter(Participant.id == Screen.participant_id)
.filter(Participant.username.in_(usernames))
)
with db_engine.connect() as connection:
df_screen = pd.read_sql(query_screen.statement, connection)
return df_screen