Fix bugs with empty dataframes in screen and gar metrics

replace/cb67d183ce858faab452a2747db7be3eda789434
JulioV 2019-12-04 12:04:20 -05:00
parent 0bd946b53c
commit 4d52e2d980
3 changed files with 36 additions and 27 deletions

View File

@ -9,7 +9,7 @@ rule all:
expand("data/raw/{pid}/{sensor}_with_datetime.csv", pid=config["PIDS"], sensor=config["SENSORS"]),
expand("data/processed/{pid}/battery_deltas.csv", pid=config["PIDS"]),
expand("data/processed/{pid}/screen_deltas.csv", pid=config["PIDS"]),
expand("data/processed/{pid}/google_activity_recognition_deltas.csv", pid=config["PIDS"]),
expand("data/processed/{pid}/plugin_google_activity_recognition_deltas.csv", pid=config["PIDS"]),
expand("data/interim/{pid}/phone_valid_sensed_days.csv", pid=config["PIDS"]),
expand("data/interim/{pid}/phone_sensed_bins.csv", pid=config["PIDS"]),
expand("data/processed/{pid}/sms_{sms_type}_{day_segment}.csv",

View File

@ -28,6 +28,9 @@ else:
if(day_segment!='daily'):
resampledData = resampledData.loc[resampledData['local_day_segment'] == str(day_segment)]
if resampledData.empty:
finalDataset = pd.DataFrame(columns = columns)
else:
count = resampledData['activity_type'].resample('D').count()
#Finding most common activity of the day
@ -44,7 +47,7 @@ else:
deltas_metrics = {'sumstationary':['still','tilting'],
'summobile':['on_foot','running','on_bicycle'],
'sumvehicle':['on_vehicle']}
'sumvehicle':['in_vehicle']}
for column, activity_labels in deltas_metrics.items():
metric = (ar_deltas[ar_deltas['activity'].isin(pd.Series(activity_labels))]

View File

@ -1,6 +1,7 @@
import pandas as pd
import numpy as np
import datetime
import itertools
from datetime import datetime, timedelta, time
from features_utils import splitOvernightEpisodes, splitMultiSegmentEpisodes
@ -73,6 +74,11 @@ else:
# extract features for events and episodes
event_features = getEventFeatures(screen_data, metrics_event)
if screen_deltas.empty:
metrics_deltas_name = ["".join(metric) for metric in itertools.product(metrics_deltas,episodes)]
duration_features = pd.DataFrame(columns=["screen_" + day_segment + "_" + x for x in metrics_deltas_name])
else:
duration_features = pd.DataFrame()
for episode in episodes:
duration_features = pd.concat([duration_features, getEpisodeDurationFeatures(screen_deltas, episode, metrics_deltas)], axis=1)