Add bin_size parameter for compliance_heatmap and screen_metrics

replace/21880be131d5fada63fab7a704aed991da079bb5
Meng Li 2019-12-05 11:07:40 -05:00
parent e6b096c6ad
commit a4e39ad451
4 changed files with 10 additions and 6 deletions

View File

@ -100,7 +100,8 @@ rule screen_metrics:
day_segment = "{day_segment}",
metrics_events = config["SCREEN"]["METRICS_EVENTS"],
metrics_deltas = config["SCREEN"]["METRICS_DELTAS"],
episodes = config["SCREEN"]["EPISODES"]
episodes = config["SCREEN"]["EPISODES"],
bin_size = config["PHONE_VALID_SENSED_DAYS"]["BIN_SIZE"]
output:
"data/processed/{pid}/screen_{day_segment}.csv"
script:

View File

@ -13,7 +13,8 @@ rule compliance_heatmap:
input:
"data/interim/{pid}/phone_sensed_bins.csv"
params:
pid = "{pid}"
pid = "{pid}",
bin_size = config["PHONE_VALID_SENSED_DAYS"]["BIN_SIZE"]
output:
"reports/figures/{pid}/compliance_heatmap.html"
script:

View File

@ -22,7 +22,7 @@ def getEpisodeDurationFeatures(screen_deltas, episode, metrics):
duration_helper = duration_helper.fillna(0)
return duration_helper
def getEventFeatures(screen_data, metrics_events, phone_sensed_bins):
def getEventFeatures(screen_data, metrics_events, phone_sensed_bins, bin_size):
if screen_data.empty:
return pd.DataFrame(columns=["screen_" + day_segment + "_" + x for x in metrics_events])
# get count_helper
@ -37,7 +37,7 @@ def getEventFeatures(screen_data, metrics_events, phone_sensed_bins):
# get unlocks per minute
for date, row in count_helper.iterrows():
sensed_minutes = phone_sensed_bins.loc[date, :].sum() * 5
sensed_minutes = phone_sensed_bins.loc[date, :].sum() * bin_size
unlocks_per_minute = min(row["count_lock"], row["count_unlock"]) / (1 if sensed_minutes == 0 else sensed_minutes)
count_helper.loc[date, "unlocks_per_minute"] = unlocks_per_minute
@ -60,6 +60,7 @@ day_segment = snakemake.params["day_segment"]
metrics_events = snakemake.params["metrics_events"]
metrics_deltas = snakemake.params["metrics_deltas"]
episodes = snakemake.params["episodes"]
bin_size = snakemake.params["bin_size"]
metrics_deltas_name = ["".join(metric) for metric in itertools.product(metrics_deltas, episodes)]
@ -77,7 +78,7 @@ else:
screen_deltas.set_index(["local_start_date"],inplace=True)
# extract features for events and episodes
event_features = getEventFeatures(screen_data, metrics_events, phone_sensed_bins)
event_features = getEventFeatures(screen_data, metrics_events, phone_sensed_bins, bin_size)
if screen_deltas.empty:
duration_features = pd.DataFrame(columns=["screen_" + day_segment + "_" + x for x in metrics_deltas_name])

View File

@ -25,6 +25,7 @@ def getComplianceHeatmap(dates, compliance_matrix, pid, output_path, bin_size):
# get current patient id
pid = snakemake.params["pid"]
bin_size = snakemake.params["bin_size"]
phone_sensed_bins = pd.read_csv(snakemake.input[0], parse_dates=["local_date"], index_col="local_date")
if phone_sensed_bins.empty:
@ -37,4 +38,4 @@ else:
# get dates and compliance_matrix
dates, compliance_matrix = getDatesComplianceMatrix(phone_sensed_bins)
# get heatmap
getComplianceHeatmap(dates, compliance_matrix, pid, snakemake.output[0], 5)
getComplianceHeatmap(dates, compliance_matrix, pid, snakemake.output[0], bin_size)