Fix encoding issues when reading participant files

pull/95/head
JulioV 2020-03-03 11:08:57 -05:00
parent c7bc430425
commit e058820309
5 changed files with 6 additions and 5 deletions

View File

@ -18,6 +18,7 @@ for(id in 1:nrow(participants)){
device_id <- participants$device_id[[id]]
brand <- ifelse(participants$brand[[id]] == "iPhone", "ios", "android")
label <- ifelse(participants$label[[id]] == "", "EMPTY_LABEL", participants$label[[id]])
label <- iconv(label, from = "UTF-8", to = "UTF-8", sub='')
start_date <- format(as.POSIXct(participants$timestamp[[id]] / 1000, origin = "1970-01-01", tz = timezone), "%Y/%m/%d")
if(!(device_id %in% ignored_device_ids)){
pid <- paste0("p", ifelse(id < 10, paste0("0", id), id))

View File

@ -18,7 +18,7 @@ def getBatteryConsumptionRatesBarChart(battery_data, pid):
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:
with open(snakemake.input["pid_file"], encoding="ISO-8859-1") as external_file:
external_file_content = external_file.readlines()
device_id = external_file_content[0].split(",")[-1]
label = external_file_content[2]

View File

@ -27,7 +27,7 @@ def getComplianceHeatmap(dates, compliance_matrix, pid, output_path, bin_size):
pid = snakemake.params["pid"]
bin_size = snakemake.params["bin_size"]
with open(snakemake.input["pid_file"]) as external_file:
with open(snakemake.input["pid_file"], encoding="ISO-8859-1") as external_file:
external_file_content = external_file.readlines()
device_id = external_file_content[0].split(",")[-1]
label = external_file_content[2]
@ -35,7 +35,7 @@ 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 = open(snakemake.output[0], "w", encoding="ISO-8859-1")
empty_html.write("There is no sensor data for " + pid + "<br>Label: " + label + ", device_id: " + device_id)
empty_html.close()
else:

View File

@ -30,7 +30,7 @@ sensor_name = snakemake.params["table"]
pid = snakemake.params["pid"]
bin_size = snakemake.params["bin_size"]
with open(snakemake.input["pid_file"]) as external_file:
with open(snakemake.input["pid_file"], encoding="ISO-8859-1") as external_file:
external_file_content = external_file.readlines()
device_id = external_file_content[0].split(",")[-1]
label = external_file_content[2]

View File

@ -47,7 +47,7 @@ for date_offset in range(6,-1,-1):
sensors_with_data_records, valid_sensed_hours_records = [], []
for sensors_with_data_individual, valid_sensed_hours_individual, pid_file in zip(phone_sensed_bins, phone_valid_sensed_days, pid_files):
with open(pid_file) as external_file:
with open(pid_file, encoding="ISO-8859-1") as external_file:
external_file_content = external_file.readlines()
device_id = external_file_content[0].split(",")[-1].strip()
label = external_file_content[2].strip()