Add bin_size parameter for compliance_heatmap and screen_metrics
parent
e6b096c6ad
commit
a4e39ad451
|
@ -100,7 +100,8 @@ rule screen_metrics:
|
||||||
day_segment = "{day_segment}",
|
day_segment = "{day_segment}",
|
||||||
metrics_events = config["SCREEN"]["METRICS_EVENTS"],
|
metrics_events = config["SCREEN"]["METRICS_EVENTS"],
|
||||||
metrics_deltas = config["SCREEN"]["METRICS_DELTAS"],
|
metrics_deltas = config["SCREEN"]["METRICS_DELTAS"],
|
||||||
episodes = config["SCREEN"]["EPISODES"]
|
episodes = config["SCREEN"]["EPISODES"],
|
||||||
|
bin_size = config["PHONE_VALID_SENSED_DAYS"]["BIN_SIZE"]
|
||||||
output:
|
output:
|
||||||
"data/processed/{pid}/screen_{day_segment}.csv"
|
"data/processed/{pid}/screen_{day_segment}.csv"
|
||||||
script:
|
script:
|
||||||
|
|
|
@ -13,7 +13,8 @@ rule compliance_heatmap:
|
||||||
input:
|
input:
|
||||||
"data/interim/{pid}/phone_sensed_bins.csv"
|
"data/interim/{pid}/phone_sensed_bins.csv"
|
||||||
params:
|
params:
|
||||||
pid = "{pid}"
|
pid = "{pid}",
|
||||||
|
bin_size = config["PHONE_VALID_SENSED_DAYS"]["BIN_SIZE"]
|
||||||
output:
|
output:
|
||||||
"reports/figures/{pid}/compliance_heatmap.html"
|
"reports/figures/{pid}/compliance_heatmap.html"
|
||||||
script:
|
script:
|
||||||
|
|
|
@ -22,7 +22,7 @@ def getEpisodeDurationFeatures(screen_deltas, episode, metrics):
|
||||||
duration_helper = duration_helper.fillna(0)
|
duration_helper = duration_helper.fillna(0)
|
||||||
return duration_helper
|
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:
|
if screen_data.empty:
|
||||||
return pd.DataFrame(columns=["screen_" + day_segment + "_" + x for x in metrics_events])
|
return pd.DataFrame(columns=["screen_" + day_segment + "_" + x for x in metrics_events])
|
||||||
# get count_helper
|
# get count_helper
|
||||||
|
@ -37,7 +37,7 @@ def getEventFeatures(screen_data, metrics_events, phone_sensed_bins):
|
||||||
|
|
||||||
# get unlocks per minute
|
# get unlocks per minute
|
||||||
for date, row in count_helper.iterrows():
|
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)
|
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
|
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_events = snakemake.params["metrics_events"]
|
||||||
metrics_deltas = snakemake.params["metrics_deltas"]
|
metrics_deltas = snakemake.params["metrics_deltas"]
|
||||||
episodes = snakemake.params["episodes"]
|
episodes = snakemake.params["episodes"]
|
||||||
|
bin_size = snakemake.params["bin_size"]
|
||||||
|
|
||||||
metrics_deltas_name = ["".join(metric) for metric in itertools.product(metrics_deltas, episodes)]
|
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)
|
screen_deltas.set_index(["local_start_date"],inplace=True)
|
||||||
|
|
||||||
# extract features for events and episodes
|
# 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:
|
if screen_deltas.empty:
|
||||||
duration_features = pd.DataFrame(columns=["screen_" + day_segment + "_" + x for x in metrics_deltas_name])
|
duration_features = pd.DataFrame(columns=["screen_" + day_segment + "_" + x for x in metrics_deltas_name])
|
||||||
|
|
|
@ -25,6 +25,7 @@ def getComplianceHeatmap(dates, compliance_matrix, pid, output_path, bin_size):
|
||||||
|
|
||||||
# get current patient id
|
# get current patient id
|
||||||
pid = snakemake.params["pid"]
|
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")
|
phone_sensed_bins = pd.read_csv(snakemake.input[0], parse_dates=["local_date"], index_col="local_date")
|
||||||
|
|
||||||
if phone_sensed_bins.empty:
|
if phone_sensed_bins.empty:
|
||||||
|
@ -37,4 +38,4 @@ else:
|
||||||
# get dates and compliance_matrix
|
# get dates and compliance_matrix
|
||||||
dates, compliance_matrix = getDatesComplianceMatrix(phone_sensed_bins)
|
dates, compliance_matrix = getDatesComplianceMatrix(phone_sensed_bins)
|
||||||
# get heatmap
|
# get heatmap
|
||||||
getComplianceHeatmap(dates, compliance_matrix, pid, snakemake.output[0], 5)
|
getComplianceHeatmap(dates, compliance_matrix, pid, snakemake.output[0], bin_size)
|
Loading…
Reference in New Issue