Refactor google_activity_recognition feature: replace "metrics" with "features"
Co-authored-by: Meng Li <AnnieLM1996@gmail.com>pull/95/head
parent
0809001dfa
commit
a53ba242f8
|
@ -80,7 +80,7 @@ BLUETOOTH:
|
||||||
|
|
||||||
GOOGLE_ACTIVITY_RECOGNITION:
|
GOOGLE_ACTIVITY_RECOGNITION:
|
||||||
DAY_SEGMENTS: *day_segments
|
DAY_SEGMENTS: *day_segments
|
||||||
METRICS: ['count','mostcommonactivity','countuniqueactivities','activitychangecount','sumstationary','summobile','sumvehicle']
|
FEATURES: ['count','mostcommonactivity','countuniqueactivities','activitychangecount','sumstationary','summobile','sumvehicle']
|
||||||
|
|
||||||
BATTERY:
|
BATTERY:
|
||||||
DAY_SEGMENTS: *day_segments
|
DAY_SEGMENTS: *day_segments
|
||||||
|
|
|
@ -624,7 +624,7 @@ See `Google Activity Recognition Config Code`_
|
||||||
|
|
||||||
.. - Extract the deltas in Google Activity Recognition dataset: ``expand("data/processed/{pid}/plugin_google_activity_recognition_deltas.csv", pid=config["PIDS"]),``
|
.. - Extract the deltas in Google Activity Recognition dataset: ``expand("data/processed/{pid}/plugin_google_activity_recognition_deltas.csv", pid=config["PIDS"]),``
|
||||||
|
|
||||||
- Extract Sensor Metrics:
|
- Extract Sensor Features:
|
||||||
|
|
||||||
| ``expand("data/processed/{pid}/google_activity_recognition_{segment}.csv",pid=config["PIDS"],``
|
| ``expand("data/processed/{pid}/google_activity_recognition_{segment}.csv",pid=config["PIDS"],``
|
||||||
| ``segment = config["GOOGLE_ACTIVITY_RECOGNITION"]["DAY_SEGMENTS"]),``
|
| ``segment = config["GOOGLE_ACTIVITY_RECOGNITION"]["DAY_SEGMENTS"]),``
|
||||||
|
@ -643,7 +643,7 @@ See `Google Activity Recognition Config Code`_
|
||||||
|
|
||||||
- **Script:** ``src/features/google_activity_recognition_deltas.R`` - See the google_activity_recognition_deltas.R_ script.
|
- **Script:** ``src/features/google_activity_recognition_deltas.R`` - See the google_activity_recognition_deltas.R_ script.
|
||||||
|
|
||||||
- **Rule:** ``rules/features.snakefile/activity_metrics`` - See the activity_metrics_ rule.
|
- **Rule:** ``rules/features.snakefile/activity_features`` - See the activity_features_ rule.
|
||||||
|
|
||||||
- **Script:** ``ssrc/features/google_activity_recognition.py`` - See the google_activity_recognition.py_ script.
|
- **Script:** ``ssrc/features/google_activity_recognition.py`` - See the google_activity_recognition.py_ script.
|
||||||
|
|
||||||
|
@ -655,14 +655,14 @@ See `Google Activity Recognition Config Code`_
|
||||||
Name Description
|
Name Description
|
||||||
============ ===================
|
============ ===================
|
||||||
day_segment The particular ``day_segments`` that will be analyzed. The available options are ``daily``, ``morning``, ``afternoon``, ``evening``, ``night``
|
day_segment The particular ``day_segments`` that will be analyzed. The available options are ``daily``, ``morning``, ``afternoon``, ``evening``, ``night``
|
||||||
metrics The different measures that can be retrieved from the Google Activity Recognition dataset. See :ref:`Available Google Activity Recognition Metrics <google-activity-recognition-available-metrics>` Table below
|
features The different measures that can be retrieved from the Google Activity Recognition dataset. See :ref:`Available Google Activity Recognition Features <google-activity-recognition-available-features>` Table below
|
||||||
============ ===================
|
============ ===================
|
||||||
|
|
||||||
.. _google-activity-recognition-available-metrics:
|
.. _google-activity-recognition-available-features:
|
||||||
|
|
||||||
**Available Google Activity Recognition Metrics**
|
**Available Google Activity Recognition Features**
|
||||||
|
|
||||||
The following table shows a list of the available metrics for the Google Activity Recognition dataset.
|
The following table shows a list of the available features for the Google Activity Recognition dataset.
|
||||||
|
|
||||||
====================== ============ =============
|
====================== ============ =============
|
||||||
Name Units Description
|
Name Units Description
|
||||||
|
|
|
@ -73,13 +73,13 @@ rule bluetooth_features:
|
||||||
script:
|
script:
|
||||||
"../src/features/bluetooth_features.R"
|
"../src/features/bluetooth_features.R"
|
||||||
|
|
||||||
rule activity_metrics:
|
rule activity_features:
|
||||||
input:
|
input:
|
||||||
gar_events = "data/raw/{pid}/plugin_google_activity_recognition_with_datetime.csv",
|
gar_events = "data/raw/{pid}/plugin_google_activity_recognition_with_datetime.csv",
|
||||||
gar_deltas = "data/processed/{pid}/plugin_google_activity_recognition_deltas.csv"
|
gar_deltas = "data/processed/{pid}/plugin_google_activity_recognition_deltas.csv"
|
||||||
params:
|
params:
|
||||||
segment = "{day_segment}",
|
segment = "{day_segment}",
|
||||||
metrics = config["GOOGLE_ACTIVITY_RECOGNITION"]["METRICS"]
|
features = config["GOOGLE_ACTIVITY_RECOGNITION"]["FEATURES"]
|
||||||
output:
|
output:
|
||||||
"data/processed/{pid}/google_activity_recognition_{day_segment}.csv"
|
"data/processed/{pid}/google_activity_recognition_{day_segment}.csv"
|
||||||
script:
|
script:
|
||||||
|
|
|
@ -4,12 +4,12 @@ import scipy.stats as stats
|
||||||
from features_utils import splitOvernightEpisodes, splitMultiSegmentEpisodes
|
from features_utils import splitOvernightEpisodes, splitMultiSegmentEpisodes
|
||||||
|
|
||||||
day_segment = snakemake.params["segment"]
|
day_segment = snakemake.params["segment"]
|
||||||
metrics = snakemake.params["metrics"]
|
features = snakemake.params["features"]
|
||||||
|
|
||||||
#Read csv into a pandas dataframe
|
#Read csv into a pandas dataframe
|
||||||
data = pd.read_csv(snakemake.input['gar_events'],parse_dates=['local_date_time'])
|
data = pd.read_csv(snakemake.input['gar_events'],parse_dates=['local_date_time'])
|
||||||
ar_deltas = pd.read_csv(snakemake.input['gar_deltas'],parse_dates=["local_start_date_time", "local_end_date_time", "local_start_date", "local_end_date"])
|
ar_deltas = pd.read_csv(snakemake.input['gar_deltas'],parse_dates=["local_start_date_time", "local_end_date_time", "local_start_date", "local_end_date"])
|
||||||
columns = list("ar_" + str(day_segment) + "_" + column for column in metrics)
|
columns = list("ar_" + str(day_segment) + "_" + column for column in features)
|
||||||
|
|
||||||
if data.empty:
|
if data.empty:
|
||||||
finalDataset = pd.DataFrame(columns = columns)
|
finalDataset = pd.DataFrame(columns = columns)
|
||||||
|
@ -31,30 +31,30 @@ else:
|
||||||
finalDataset = pd.DataFrame(columns = columns)
|
finalDataset = pd.DataFrame(columns = columns)
|
||||||
else:
|
else:
|
||||||
#Finding the count of samples of the day
|
#Finding the count of samples of the day
|
||||||
if("count" in metrics):
|
if("count" in features):
|
||||||
finalDataset["ar_" + str(day_segment) + "_count"] = resampledData['activity_type'].resample('D').count()
|
finalDataset["ar_" + str(day_segment) + "_count"] = resampledData['activity_type'].resample('D').count()
|
||||||
|
|
||||||
#Finding most common activity of the day
|
#Finding most common activity of the day
|
||||||
if("mostcommonactivity" in metrics):
|
if("mostcommonactivity" in features):
|
||||||
finalDataset["ar_" + str(day_segment) + "_mostcommonactivity"] = resampledData['activity_type'].resample('D').apply(lambda x: stats.mode(x)[0] if len(stats.mode(x)[0]) != 0 else None)
|
finalDataset["ar_" + str(day_segment) + "_mostcommonactivity"] = resampledData['activity_type'].resample('D').apply(lambda x: stats.mode(x)[0] if len(stats.mode(x)[0]) != 0 else None)
|
||||||
|
|
||||||
#finding different number of activities during a day
|
#finding different number of activities during a day
|
||||||
if("countuniqueactivities" in metrics):
|
if("countuniqueactivities" in features):
|
||||||
finalDataset["ar_" + str(day_segment) + "_countuniqueactivities"] = resampledData['activity_type'].resample('D').nunique()
|
finalDataset["ar_" + str(day_segment) + "_countuniqueactivities"] = resampledData['activity_type'].resample('D').nunique()
|
||||||
|
|
||||||
#finding Number of times activity changed
|
#finding Number of times activity changed
|
||||||
if("activitychangecount" in metrics):
|
if("activitychangecount" in features):
|
||||||
resampledData['activity_type_shift'] = resampledData['activity_type'].shift().fillna(resampledData['activity_type'].head(1))
|
resampledData['activity_type_shift'] = resampledData['activity_type'].shift().fillna(resampledData['activity_type'].head(1))
|
||||||
resampledData['different_activity'] = np.where(resampledData['activity_type']!=resampledData['activity_type_shift'],1,0)
|
resampledData['different_activity'] = np.where(resampledData['activity_type']!=resampledData['activity_type_shift'],1,0)
|
||||||
finalDataset["ar_" + str(day_segment) + "_activitychangecount"] = resampledData['different_activity'].resample('D').sum()
|
finalDataset["ar_" + str(day_segment) + "_activitychangecount"] = resampledData['different_activity'].resample('D').sum()
|
||||||
|
|
||||||
|
|
||||||
deltas_metrics = {'sumstationary':['still','tilting'],
|
deltas_features = {'sumstationary':['still','tilting'],
|
||||||
'summobile':['on_foot','running','on_bicycle'],
|
'summobile':['on_foot','running','on_bicycle'],
|
||||||
'sumvehicle':['in_vehicle']}
|
'sumvehicle':['in_vehicle']}
|
||||||
|
|
||||||
for column, activity_labels in deltas_metrics.items():
|
for column, activity_labels in deltas_features.items():
|
||||||
if column in metrics:
|
if column in features:
|
||||||
finalDataset["ar_" + str(day_segment) + "_"+str(column)] = (ar_deltas[ar_deltas['activity'].isin(pd.Series(activity_labels))]
|
finalDataset["ar_" + str(day_segment) + "_"+str(column)] = (ar_deltas[ar_deltas['activity'].isin(pd.Series(activity_labels))]
|
||||||
.groupby(['local_start_date'])['time_diff']
|
.groupby(['local_start_date'])['time_diff']
|
||||||
.agg({"ar_" + str(day_segment) + "_" + str(column) :'sum'}))
|
.agg({"ar_" + str(day_segment) + "_" + str(column) :'sum'}))
|
||||||
|
|
Loading…
Reference in New Issue