From 7de4beca6ebe040df951e25e3a8706a495dbacc1 Mon Sep 17 00:00:00 2001 From: junos Date: Fri, 23 Jul 2021 16:19:56 +0200 Subject: [PATCH] Add a method for getting the light sensor data. --- features/light.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 features/light.py diff --git a/features/light.py b/features/light.py new file mode 100644 index 0000000..4e781b5 --- /dev/null +++ b/features/light.py @@ -0,0 +1,30 @@ +from collections.abc import Collection + +import pandas as pd + +from config.models import Participant, LightSensor +from setup import db_engine, session + + +def get_light_data(usernames: Collection) -> pd.DataFrame: + """ + Read the data from the light sensor table and return it in a dataframe. + + Parameters + ---------- + usernames: Collection + A list of usernames to put into the WHERE condition. + + Returns + ------- + df_light: pd.DataFrame + A dataframe of light data. + """ + query_light = ( + session.query(LightSensor, Participant.username) + .filter(Participant.id == LightSensor.participant_id) + .filter(Participant.username.in_(usernames)) + ) + with db_engine.connect() as connection: + df_light = pd.read_sql(query_light.statement, connection) + return df_light