Skeleton file main.py for EDA CalcFt. integration.

sociality-task
Primoz 2022-03-22 12:48:43 +00:00
parent bd5a811256
commit 2da0911d4c
2 changed files with 87 additions and 7 deletions

View File

@ -180,7 +180,7 @@ PHONE_CALLS:
CONTAINER: calls.csv
PROVIDERS:
RAPIDS:
COMPUTE: True
COMPUTE: False
FEATURES_TYPE: EPISODES # EVENTS or EPISODES
CALL_TYPES: [missed, incoming, outgoing]
FEATURES:
@ -477,7 +477,7 @@ EMPATICA_ACCELEROMETER:
CONTAINER: ACC
PROVIDERS:
DBDP:
COMPUTE: True
COMPUTE: False
FEATURES: ["maxmagnitude", "minmagnitude", "avgmagnitude", "medianmagnitude", "stdmagnitude"]
SRC_SCRIPT: src/features/empatica_accelerometer/dbdp/main.py
@ -486,7 +486,7 @@ EMPATICA_HEARTRATE:
CONTAINER: HR
PROVIDERS:
DBDP:
COMPUTE: True
COMPUTE: False
FEATURES: ["maxhr", "minhr", "avghr", "medianhr", "modehr", "stdhr", "diffmaxmodehr", "diffminmodehr", "entropyhr"]
SRC_SCRIPT: src/features/empatica_heartrate/dbdp/main.py
@ -495,7 +495,7 @@ EMPATICA_TEMPERATURE:
CONTAINER: TEMP
PROVIDERS:
DBDP:
COMPUTE: True
COMPUTE: False
FEATURES: ["maxtemp", "mintemp", "avgtemp", "mediantemp", "modetemp", "stdtemp", "diffmaxmodetemp", "diffminmodetemp", "entropytemp"]
SRC_SCRIPT: src/features/empatica_temperature/dbdp/main.py
@ -504,16 +504,20 @@ EMPATICA_ELECTRODERMAL_ACTIVITY:
CONTAINER: EDA
PROVIDERS:
DBDP:
COMPUTE: True
COMPUTE: False
FEATURES: ["maxeda", "mineda", "avgeda", "medianeda", "modeeda", "stdeda", "diffmaxmodeeda", "diffminmodeeda", "entropyeda"]
SRC_SCRIPT: src/features/empatica_electrodermal_activity/dbdp/main.py
CF:
COMPUTE: True
FEATURES: ["maxeda", "mineda", "avgeda", "medianeda", "modeeda", "stdeda", "diffmaxmodeeda", "diffminmodeeda", "entropyeda"]
SRC_SCRIPT: src/features/empatica_electrodermal_activity/cf/main.py
# See https://www.rapids.science/latest/features/empatica-blood-volume-pulse/
EMPATICA_BLOOD_VOLUME_PULSE:
CONTAINER: BVP
PROVIDERS:
DBDP:
COMPUTE: True
COMPUTE: False
FEATURES: ["maxbvp", "minbvp", "avgbvp", "medianbvp", "modebvp", "stdbvp", "diffmaxmodebvp", "diffminmodebvp", "entropybvp"]
SRC_SCRIPT: src/features/empatica_blood_volume_pulse/dbdp/main.py
@ -522,7 +526,7 @@ EMPATICA_INTER_BEAT_INTERVAL:
CONTAINER: IBI
PROVIDERS:
DBDP:
COMPUTE: True
COMPUTE: False
FEATURES: ["maxibi", "minibi", "avgibi", "medianibi", "modeibi", "stdibi", "diffmaxmodeibi", "diffminmodeibi", "entropyibi"]
SRC_SCRIPT: src/features/empatica_inter_beat_interval/dbdp/main.py

View File

@ -0,0 +1,76 @@
import pandas as pd
from scipy.stats import entropy
def statsFeatures(eda_data, features, eda_features):
col_name = "electrodermal_activity"
if "sumeda" in features:
eda_features["sumeda"] = eda_data[["local_segment", col_name]].groupby(["local_segment"])[
col_name].sum()
if "maxeda" in features:
eda_features["maxeda"] = eda_data[["local_segment", col_name]].groupby(["local_segment"])[
col_name].max()
if "mineda" in features:
eda_features["mineda"] = eda_data[["local_segment", col_name]].groupby(["local_segment"])[
col_name].min()
if "avgeda" in features:
eda_features["avgeda"] = eda_data[["local_segment", col_name]].groupby(["local_segment"])[
col_name].mean()
if "medianeda" in features:
eda_features["medianeda"] = eda_data[["local_segment", col_name]].groupby(["local_segment"])[
col_name].median()
if "modeeda" in features:
eda_features["modeeda"] = eda_data[["local_segment", col_name]].groupby(["local_segment"])[
col_name].agg(lambda x: pd.Series.mode(x)[0])
if "stdeda" in features:
eda_features["stdeda"] = eda_data[["local_segment", col_name]].groupby(["local_segment"])[
col_name].std()
if "diffmaxmodeeda" in features:
eda_features["diffmaxmodeeda"] = eda_data[["local_segment", col_name]].groupby(["local_segment"])[
col_name].max() - \
eda_data[["local_segment", col_name]].groupby(["local_segment"])[
col_name].agg(lambda x: pd.Series.mode(x)[0])
if "diffminmodeeda" in features:
eda_features["diffminmodeeda"] = eda_data[["local_segment", col_name]].groupby(["local_segment"])[
col_name].agg(lambda x: pd.Series.mode(x)[0]) - \
eda_data[["local_segment", col_name]].groupby(["local_segment"])[
col_name].min()
if "entropyeda" in features:
eda_features["entropyeda"] = eda_data[["local_segment", col_name]].groupby(["local_segment"])[
col_name].agg(entropy)
return eda_features
def extractEDAFeaturesFromIntradayData(eda_intraday_data, features, time_segment, filter_data_by_segment):
eda_intraday_features = pd.DataFrame(columns=["local_segment"] + features)
if not eda_intraday_data.empty:
eda_intraday_data = filter_data_by_segment(eda_intraday_data, time_segment)
if not eda_intraday_data.empty:
eda_intraday_features = pd.DataFrame()
# get stats of eda
eda_intraday_features = statsFeatures(eda_intraday_data, features, eda_intraday_features)
eda_intraday_features.reset_index(inplace=True)
return eda_intraday_features
def cf_features(sensor_data_files, time_segment, provider, filter_data_by_segment, *args, **kwargs):
eda_intraday_data = pd.read_csv(sensor_data_files["sensor_data"])
requested_intraday_features = provider["FEATURES"]
# name of the features this function can compute
base_intraday_features_names = ["maxeda", "mineda", "avgeda", "medianeda", "modeeda", "stdeda", "diffmaxmodeeda",
"diffminmodeeda", "entropyeda"]
# the subset of requested features this function can compute
intraday_features_to_compute = list(set(requested_intraday_features) & set(base_intraday_features_names))
# extract features from intraday data
eda_intraday_features = extractEDAFeaturesFromIntradayData(eda_intraday_data,
intraday_features_to_compute, time_segment,
filter_data_by_segment)
return eda_intraday_features