Add device_id and label to heatmaps

pull/95/head
Meng Li 2020-02-20 10:16:03 -05:00
parent 76888b412d
commit 3369a97d0e
4 changed files with 33 additions and 12 deletions

View File

@ -1,6 +1,7 @@
rule heatmap_rows:
input:
"data/raw/{pid}/{sensor}_with_datetime.csv"
sensor = "data/raw/{pid}/{sensor}_with_datetime.csv",
pid_file = "data/external/{pid}"
params:
table = "{sensor}",
pid = "{pid}",
@ -12,7 +13,8 @@ rule heatmap_rows:
rule compliance_heatmap:
input:
"data/interim/{pid}/phone_sensed_bins.csv"
sensor = "data/interim/{pid}/phone_sensed_bins.csv",
pid_file = "data/external/{pid}"
params:
pid = "{pid}",
bin_size = config["PHONE_VALID_SENSED_DAYS"]["BIN_SIZE"]
@ -23,7 +25,8 @@ rule compliance_heatmap:
rule battery_consumption_rates_barchart:
input:
"data/processed/{pid}/battery_daily.csv"
sensor = "data/processed/{pid}/battery_daily.csv",
pid_file = "data/external/{pid}"
params:
pid = "{pid}"
output:

View File

@ -8,18 +8,24 @@ def getBatteryConsumptionRatesBarChart(battery_data, pid):
x=battery_data["battery_daily_avgconsumptionrate"],
y=battery_data["local_date"].apply(lambda x: x.strftime("%Y/%m/%d")).tolist(),
orientation='h'))
plot.update_layout(title="Daily battery consumption rates bar chart for " + pid,
plot.update_layout(title="Daily battery consumption rates bar chart for " + pid + "<br>Label: " + label + ", device_id: " + device_id,
xaxis_title="battery drains % per hour",
)
return plot
battery_data = pd.read_csv(snakemake.input[0], parse_dates=["local_date"])
battery_data = pd.read_csv(snakemake.input["sensor"], parse_dates=["local_date"])
pid = snakemake.params["pid"]
with open(snakemake.input["pid_file"]) as external_file:
external_file_content = external_file.readlines()
device_id = external_file_content[0].split(",")[-1]
label = external_file_content[2]
if battery_data.empty:
empty_html = open(snakemake.output[0], "w")
empty_html.write("There is no battery data for " + pid)
empty_html.write("There is no battery data for " + pid + "<br>Label: " + label + ", device_id: " + device_id)
empty_html.close()
else:
battery_data.set_index(["local_date"], inplace=True)

View File

@ -20,17 +20,23 @@ def getComplianceHeatmap(dates, compliance_matrix, pid, output_path, bin_size):
y=[datetime.datetime.strftime(date, '%Y/%m/%d') for date in dates],
colorscale='Viridis',
colorbar={'tick0': 0,'dtick': 1}))
plot.update_layout(title="Compliance heatmap.<br>Five-minute bins showing how many sensors logged at least one row of data in that period for " + pid)
plot.update_layout(title="Compliance heatmap.<br>Five-minute bins showing how many sensors logged at least one row of data in that period for " + pid + "<br>Label: " + label + ", device_id: " + device_id)
pio.write_html(plot, file=output_path, auto_open=False)
# 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")
with open(snakemake.input["pid_file"]) as external_file:
external_file_content = external_file.readlines()
device_id = external_file_content[0].split(",")[-1]
label = external_file_content[2]
phone_sensed_bins = pd.read_csv(snakemake.input["sensor"], parse_dates=["local_date"], index_col="local_date")
if phone_sensed_bins.empty:
empty_html = open(snakemake.output[0], "w")
empty_html.write("There is no sensor data for " + pid)
empty_html.write("There is no sensor data for " + pid + "<br>Label: " + label + ", device_id: " + device_id)
empty_html.close()
else:
# resample to impute missing dates

View File

@ -20,20 +20,26 @@ def getRowCountHeatmap(dates, row_count_per_bin, sensor_name, pid, output_path,
x=x_axis_labels,
y=[datetime.datetime.strftime(date, '%Y/%m/%d') for date in dates],
colorscale="Viridis"))
plot.update_layout(title="Row count heatmap for " + sensor_name + " of " + pid)
plot.update_layout(title="Row count heatmap for " + sensor_name + " of " + pid + "<br>Label: " + label + ", device_id: " + device_id)
pio.write_html(plot, file=output_path, auto_open=False)
sensor_data = pd.read_csv(snakemake.input[0], encoding="ISO-8859-1")
sensor_data = pd.read_csv(snakemake.input["sensor"], encoding="ISO-8859-1")
sensor_name = snakemake.params["table"]
pid = snakemake.params["pid"]
bin_size = snakemake.params["bin_size"]
with open(snakemake.input["pid_file"]) as external_file:
external_file_content = external_file.readlines()
device_id = external_file_content[0].split(",")[-1]
label = external_file_content[2]
# check if we have sensor data
if sensor_data.empty:
empty_html = open(snakemake.output[0], "w")
empty_html.write("There is no "+ sensor_name + " data for "+pid)
empty_html.write("There is no " + sensor_name + " data for " + pid + "<br>Label: " + label + ", device_id: " + device_id)
empty_html.close()
else:
start_date = sensor_data["local_date"][0]