Start exploring proximity.

communication
junos 2021-07-26 11:37:31 +02:00
parent 9580533c14
commit d3f42ea402
2 changed files with 99 additions and 0 deletions

View File

@ -0,0 +1,69 @@
# ---
# jupyter:
# jupytext:
# formats: ipynb,py:percent
# text_representation:
# extension: .py
# format_name: percent
# format_version: '1.3'
# jupytext_version: 1.11.4
# kernelspec:
# display_name: straw2analysis
# language: python
# name: straw2analysis
# ---
# %%
# %matplotlib inline
import datetime
import os
import sys
import seaborn as sns
from pytz import timezone
from tabulate import tabulate
nb_dir = os.path.split(os.getcwd())[0]
if nb_dir not in sys.path:
sys.path.append(nb_dir)
import participants.query_db
TZ_LJ = timezone("Europe/Ljubljana")
# %%
from features.proximity import *
# %% [markdown]
# # Basic characteristics
# %%
df_proximity_nokia = get_proximity_data(["nokia_0000003"])
print(df_proximity_nokia)
# %%
df_proximity_nokia.double_proximity.value_counts()
# %% [markdown]
# `double_proximity` is "the distance to an object in front of the mobile device or binary presence (**manufacturer dependent**)."
#
# "Most proximity sensors return [the absolute distance, in cm](https://developer.android.com/guide/topics/sensors/sensors_position#sensors-pos-prox), but some return only near and far values.
#
# Note: Some proximity sensors return binary values that represent "near" or "far." In this case, the sensor usually reports its maximum range value in the far state and a lesser value in the near state. Typically, the far value is a value > 5 cm, but this can vary from sensor to sensor. You can determine a sensor's maximum range by using the getMaximumRange() method."
# %%
participants_inactive_usernames = participants.query_db.get_usernames()
df_proximity_inactive = get_proximity_data(participants_inactive_usernames)
# %%
df_proximity_inactive.double_proximity.describe()
# %%
sns.displot(
data=df_proximity_inactive, x="double_proximity", binwidth=0.2, height=8,
)
# %%
df_proximity_inactive.double_proximity.value_counts()
# %%

View File

@ -0,0 +1,30 @@
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