Fixed 2 Issues: Feature Names, Implementation of metrics in Config File
parent
4aec2c4032
commit
db2f3dc50f
|
@ -1,5 +1,5 @@
|
||||||
# Valid database table names
|
# Valid database table names
|
||||||
SENSORS: [applications_crashes, applications_foreground, applications_notifications, battery, bluetooth, calls, fitbit_data, locations, messages, plugin_ambient_noise, plugin_device_usage, plugin_google_activity_recognition, screen]
|
SENSORS: [applications_crashes, applications_foreground, applications_notifications, battery, bluetooth, calls, locations, messages, plugin_ambient_noise, plugin_device_usage, plugin_google_activity_recognition, screen]
|
||||||
|
|
||||||
FITBIT_TABLE: [fitbit_data]
|
FITBIT_TABLE: [fitbit_data]
|
||||||
FITBIT_SENSORS: [heartrate, steps, sleep]
|
FITBIT_SENSORS: [heartrate, steps, sleep]
|
||||||
|
@ -71,7 +71,8 @@ BLUETOOTH:
|
||||||
|
|
||||||
GOOGLE_ACTIVITY_RECOGNITION:
|
GOOGLE_ACTIVITY_RECOGNITION:
|
||||||
DAY_SEGMENTS: *day_segments
|
DAY_SEGMENTS: *day_segments
|
||||||
METRICS: ['count','most_common_activity','number_unique_activities','activity_change_count']
|
METRICS: ['count','mostcommonactivity','countuniqueactivities','activitychangecount','sumstationary','summobile','sumvehicle']
|
||||||
|
|
||||||
|
|
||||||
BATTERY:
|
BATTERY:
|
||||||
DAY_SEGMENTS: *day_segments
|
DAY_SEGMENTS: *day_segments
|
||||||
|
|
|
@ -4,18 +4,17 @@ 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"]
|
||||||
|
|
||||||
#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 = ['count','most_common_activity','count_unique_activities','activity_change_count','sumstationary','summobile','sumvehicle']
|
columns = list("ar_" + str(day_segment) + "_" + column for column in metrics)
|
||||||
columns = list("ar_" + str(day_segment) + "_" + column for column in columns)
|
|
||||||
|
|
||||||
|
|
||||||
if data.empty:
|
if data.empty:
|
||||||
finalDataset = pd.DataFrame(columns = columns)
|
finalDataset = pd.DataFrame(columns = columns)
|
||||||
else:
|
else:
|
||||||
|
finalDataset = pd.DataFrame()
|
||||||
ar_deltas = splitOvernightEpisodes(ar_deltas, [],['activity'])
|
ar_deltas = splitOvernightEpisodes(ar_deltas, [],['activity'])
|
||||||
|
|
||||||
if day_segment != "daily":
|
if day_segment != "daily":
|
||||||
|
@ -31,31 +30,34 @@ else:
|
||||||
if resampledData.empty:
|
if resampledData.empty:
|
||||||
finalDataset = pd.DataFrame(columns = columns)
|
finalDataset = pd.DataFrame(columns = columns)
|
||||||
else:
|
else:
|
||||||
count = resampledData['activity_type'].resample('D').count()
|
#Finding the count of samples of the day
|
||||||
|
if("count" in metrics):
|
||||||
|
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
|
||||||
mostCommonActivity = resampledData['activity_type'].resample('D').apply(lambda x:stats.mode(x)[0])
|
if("mostcommonactivity" in metrics):
|
||||||
|
finalDataset["ar_" + str(day_segment) + "_mostcommonactivity"] = resampledData['activity_type'].resample('D').apply(lambda x:stats.mode(x)[0])
|
||||||
|
|
||||||
#finding different number of activities during a day
|
#finding different number of activities during a day
|
||||||
uniqueActivities = resampledData['activity_type'].resample('D').nunique()
|
if("countuniqueactivities" in metrics):
|
||||||
|
finalDataset["ar_" + str(day_segment) + "_countuniqueactivities"] = resampledData['activity_type'].resample('D').nunique()
|
||||||
|
|
||||||
#finding Number of times activity changed
|
#finding Number of times activity changed
|
||||||
resampledData['activity_type_shift'] = resampledData['activity_type'].shift().fillna(resampledData['activity_type'].head(1),inplace=True)
|
if("activitychangecount" in metrics):
|
||||||
resampledData['different_activity'] = np.where(resampledData['activity_type']!=resampledData['activity_type_shift'],1,0)
|
resampledData['activity_type_shift'] = resampledData['activity_type'].shift().fillna(resampledData['activity_type'].head(1))
|
||||||
countChanges = resampledData['different_activity'].resample('D').sum()
|
resampledData['different_activity'] = np.where(resampledData['activity_type']!=resampledData['activity_type_shift'],1,0)
|
||||||
finalDataset = pd.concat([count, mostCommonActivity, uniqueActivities, countChanges],axis=1)
|
finalDataset["ar_" + str(day_segment) + "_activitychangecount"] = resampledData['different_activity'].resample('D').sum()
|
||||||
|
|
||||||
|
|
||||||
deltas_metrics = {'sumstationary':['still','tilting'],
|
deltas_metrics = {'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_metrics.items():
|
||||||
metric = (ar_deltas[ar_deltas['activity'].isin(pd.Series(activity_labels))]
|
if column in metrics:
|
||||||
.groupby(['local_start_date'])['time_diff']
|
finalDataset["ar_" + str(day_segment) + "_"+str(column)] = (ar_deltas[ar_deltas['activity'].isin(pd.Series(activity_labels))]
|
||||||
.agg({"ar_" + str(day_segment) + "_" + str(column) :'sum'}))
|
.groupby(['local_start_date'])['time_diff']
|
||||||
finalDataset = finalDataset.merge(metric,how='outer',left_index=True,right_index=True)
|
.agg({"ar_" + str(day_segment) + "_" + str(column) :'sum'}))
|
||||||
|
|
||||||
finalDataset.fillna(0,inplace=True)
|
|
||||||
finalDataset.index.names = ['local_date']
|
finalDataset.index.names = ['local_date']
|
||||||
finalDataset.columns=columns
|
|
||||||
finalDataset.to_csv(snakemake.output[0])
|
finalDataset.to_csv(snakemake.output[0])
|
Loading…
Reference in New Issue