parent
6302a0f0d9
commit
92fbda242b
|
@ -12,7 +12,7 @@ dependencies:
|
|||
- mypy
|
||||
- nodejs
|
||||
- pandas
|
||||
- psycopg2
|
||||
- psycopg2 >= 2.9.1
|
||||
- python-dotenv
|
||||
- pytz
|
||||
- seaborn
|
||||
|
|
|
@ -166,12 +166,43 @@ class Application(Base, AWAREsensor):
|
|||
|
||||
|
||||
class Barometer(Base, AWAREsensor):
|
||||
"""
|
||||
Contains the barometer sensor data.
|
||||
|
||||
Attributes
|
||||
----------
|
||||
double_values_0: float
|
||||
The ambient air pressure in mbar (hPa)
|
||||
accuracy: int
|
||||
Sensor’s accuracy level, either 1, 2, or 3 (see [SensorManager](https://developer.android.com/reference/android/hardware/SensorManager.html#SENSOR_STATUS_ACCURACY_HIGH))
|
||||
"""
|
||||
|
||||
double_values_0 = Column(Float, nullable=False)
|
||||
accuracy = Column(SmallInteger, nullable=True)
|
||||
label = Column(String, nullable=True)
|
||||
|
||||
|
||||
class BarometerSensor(Base, AWAREsensor):
|
||||
"""
|
||||
Contains the barometer sensor capabilities.
|
||||
|
||||
Attributes
|
||||
----------
|
||||
double_sensor_maximum_range: float
|
||||
Maximum sensor value possible
|
||||
double_sensor_minimum_delay: float
|
||||
Minimum sampling delay in microseconds
|
||||
sensor_name: str
|
||||
double_sensor_power_ma: float
|
||||
Sensor’s power drain in mA
|
||||
double_sensor_resolution: float
|
||||
Sensor’s resolution in sensor’s units
|
||||
sensor_type: str
|
||||
sensor_vendor: str
|
||||
Sensor’s manufacturer
|
||||
sensor_version: str
|
||||
"""
|
||||
|
||||
__tablename__ = "barometer_sensor"
|
||||
# Since this table is not really important,
|
||||
# I will leave all columns as nullable. (nullable=True by default.)
|
||||
|
@ -257,6 +288,19 @@ class Imperfection(Base):
|
|||
|
||||
|
||||
class LightSensor(Base, AWAREsensor):
|
||||
"""
|
||||
Contains the light sensor data.
|
||||
Note: Even though this table is named light_sensor, it actually contains what AWARE calls light data
|
||||
(rather than the data about the sensor's capabilities). Cf. Barometer(Sensor) and Temperature(Sensor).
|
||||
|
||||
Attributes
|
||||
----------
|
||||
double_light_lux: float
|
||||
The ambient luminance in lux units
|
||||
accuracy: int
|
||||
Sensor’s accuracy level, either 1, 2, or 3 (see [SensorManager](https://developer.android.com/reference/android/hardware/SensorManager.html#SENSOR_STATUS_ACCURACY_HIGH))
|
||||
"""
|
||||
|
||||
__tablename__ = "light_sensor"
|
||||
double_light_lux = Column(Float, nullable=False)
|
||||
accuracy = Column(Integer, nullable=True)
|
||||
|
@ -376,12 +420,43 @@ class SMS(Base, AWAREsensor):
|
|||
|
||||
|
||||
class Temperature(Base, AWAREsensor):
|
||||
"""
|
||||
Contains the temperature sensor data.
|
||||
|
||||
Attributes
|
||||
----------
|
||||
temperature_celsius: float
|
||||
Measured temperature in °C
|
||||
accuracy: int
|
||||
Sensor’s accuracy level, either 1, 2, or 3 (see [SensorManager](https://developer.android.com/reference/android/hardware/SensorManager.html#SENSOR_STATUS_ACCURACY_HIGH))
|
||||
"""
|
||||
|
||||
temperature_celsius = Column(Float, nullable=False)
|
||||
accuracy = Column(SmallInteger, nullable=True)
|
||||
label = Column(String, nullable=True)
|
||||
|
||||
|
||||
class TemperatureSensor(Base, AWAREsensor):
|
||||
"""
|
||||
Contains the temperature sensor capabilities.
|
||||
|
||||
Attributes
|
||||
----------
|
||||
double_sensor_maximum_range: float
|
||||
Maximum sensor value possible
|
||||
double_sensor_minimum_delay: float
|
||||
Minimum sampling delay in microseconds
|
||||
sensor_name: str
|
||||
double_sensor_power_ma: float
|
||||
Sensor’s power drain in mA
|
||||
double_sensor_resolution: float
|
||||
Sensor’s resolution in sensor’s units
|
||||
sensor_type: str
|
||||
sensor_vendor: str
|
||||
Sensor’s manufacturer
|
||||
sensor_version: str
|
||||
"""
|
||||
|
||||
# I left all of these nullable,
|
||||
# as we haven't seen any data from this sensor anyway.
|
||||
__tablename__ = "temperature_sensor"
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
# extension: .py
|
||||
# format_name: percent
|
||||
# format_version: '1.3'
|
||||
# jupytext_version: 1.12.0
|
||||
# jupytext_version: 1.13.0
|
||||
# kernelspec:
|
||||
# display_name: straw2analysis
|
||||
# language: python
|
||||
|
@ -21,7 +21,6 @@ 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:
|
||||
|
@ -103,7 +102,7 @@ df_light_nokia.loc[df_light_nokia["double_light_lux"] == 0, ["datetime_lj"]]
|
|||
# Zeroes are present during the day. It does happens when the sensor is physically blocked.
|
||||
|
||||
# %% [markdown]
|
||||
# # Differences between participants
|
||||
# ## Differences between participants
|
||||
|
||||
# %%
|
||||
df_light_participants = (
|
||||
|
@ -188,9 +187,52 @@ barometer_sensor_cols.remove("timestamp")
|
|||
barometer_sensor_cols.remove("device_id")
|
||||
print(df_barometer_sensor_samsung.drop_duplicates(subset=barometer_sensor_cols))
|
||||
|
||||
# %%
|
||||
## Barometer data
|
||||
# %% [markdown]
|
||||
# ## Barometer data
|
||||
|
||||
# %%
|
||||
df_barometer_sensor_samsung = get_ambient_data(["samsung_0000002"], "barometer")
|
||||
print(df_barometer_sensor_samsung)
|
||||
df_barometer_samsung = get_ambient_data(["samsung_0000002"], "barometer")
|
||||
print(df_barometer_samsung)
|
||||
|
||||
# %%
|
||||
df_barometer_inactive = get_ambient_data(participants_inactive_usernames, "barometer")
|
||||
|
||||
# %%
|
||||
df_barometer_inactive.accuracy.value_counts()
|
||||
|
||||
# %%
|
||||
df_barometer_inactive.participant_id.nunique()
|
||||
|
||||
# %%
|
||||
df_barometer_inactive.double_values_0.describe()
|
||||
|
||||
# %% [markdown]
|
||||
# From [Wikipedia](https://en.wikipedia.org/wiki/Atmospheric_pressure#Mean_sea-level_pressure):
|
||||
#
|
||||
# > The lowest measurable sea-level pressure is found at the centers of tropical cyclones and tornadoes, with a record low of 870 mbar (87 kPa; 26 inHg).
|
||||
|
||||
# %%
|
||||
df_barometer_inactive[df_barometer_inactive["double_values_0"] < 870]
|
||||
|
||||
# %%
|
||||
sns.displot(
|
||||
data=df_barometer_inactive[df_barometer_inactive["double_values_0"] > 870],
|
||||
x="double_values_0",
|
||||
binwidth=10,
|
||||
height=8,
|
||||
)
|
||||
|
||||
# %% [markdown]
|
||||
# # Temperature data
|
||||
|
||||
# %% [markdown]
|
||||
# ## Temperature sensor
|
||||
|
||||
# %% [markdown]
|
||||
# This table is empty.
|
||||
|
||||
# %% [markdown]
|
||||
# ## Temperature data
|
||||
|
||||
# %% [markdown]
|
||||
# This table is empty.
|
||||
|
|
|
@ -2,7 +2,14 @@ from collections.abc import Collection
|
|||
|
||||
import pandas as pd
|
||||
|
||||
from config.models import Barometer, BarometerSensor, LightSensor, Participant, Temperature, TemperatureSensor
|
||||
from config.models import (
|
||||
Barometer,
|
||||
BarometerSensor,
|
||||
LightSensor,
|
||||
Participant,
|
||||
Temperature,
|
||||
TemperatureSensor,
|
||||
)
|
||||
from setup import db_engine, session
|
||||
|
||||
|
||||
|
@ -25,36 +32,33 @@ def get_ambient_data(usernames: Collection, sensor=None) -> pd.DataFrame:
|
|||
A dataframe of ambient sensor data.
|
||||
"""
|
||||
if sensor == "barometer":
|
||||
query_ambient = (
|
||||
session.query(Barometer, Participant.username)
|
||||
.filter(Participant.id == Barometer.participant_id)
|
||||
query_ambient = session.query(Barometer, Participant.username).filter(
|
||||
Participant.id == Barometer.participant_id
|
||||
)
|
||||
elif sensor == "barometer_sensor":
|
||||
query_ambient = (
|
||||
session.query(BarometerSensor, Participant.username)
|
||||
.filter(Participant.id == BarometerSensor.participant_id)
|
||||
query_ambient = session.query(BarometerSensor, Participant.username).filter(
|
||||
Participant.id == BarometerSensor.participant_id
|
||||
)
|
||||
elif sensor == "light":
|
||||
query_ambient = (
|
||||
session.query(LightSensor, Participant.username)
|
||||
.filter(Participant.id == LightSensor.participant_id)
|
||||
query_ambient = session.query(LightSensor, Participant.username).filter(
|
||||
Participant.id == LightSensor.participant_id
|
||||
)
|
||||
# Note that LightSensor and its light_sensor table are incorrectly named.
|
||||
# In this table, we actually find light data, i.e. double_light_lux, the ambient luminance in lux,
|
||||
# and NOT light sensor data (its range, dela, resolution, vendor etc.) as the name suggests.
|
||||
# We do not have light sensor data saved in the database.
|
||||
elif sensor == "temperature":
|
||||
query_ambient = (
|
||||
session.query(Temperature, Participant.username)
|
||||
.filter(Participant.id == Temperature.participant_id)
|
||||
query_ambient = session.query(Temperature, Participant.username).filter(
|
||||
Participant.id == Temperature.participant_id
|
||||
)
|
||||
elif sensor == "temperature_sensor":
|
||||
query_ambient = (
|
||||
session.query(TemperatureSensor, Participant.username)
|
||||
.filter(Participant.id == TemperatureSensor.participant_id)
|
||||
query_ambient = session.query(TemperatureSensor, Participant.username).filter(
|
||||
Participant.id == TemperatureSensor.participant_id
|
||||
)
|
||||
else:
|
||||
raise KeyError("Specify one of the ambient sensors: barometer, barometer_sensor, light, temperature, or temperature_sensor.")
|
||||
raise KeyError(
|
||||
"Specify one of the ambient sensors: barometer, barometer_sensor, light, temperature, or temperature_sensor."
|
||||
)
|
||||
|
||||
query_ambient = query_ambient.filter(Participant.username.in_(usernames))
|
||||
with db_engine.connect() as connection:
|
||||
|
|
Loading…
Reference in New Issue