Add a method for getting the light sensor data.

communication
junos 2021-07-23 16:19:56 +02:00
parent 7aeb40d674
commit 7de4beca6e
1 changed files with 30 additions and 0 deletions

30
features/light.py 100644
View File

@ -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