diff --git a/src/data/assign_to_day_segment.R b/src/data/assign_to_day_segment.R index d58cbdfa..ecf17973 100644 --- a/src/data/assign_to_day_segment.R +++ b/src/data/assign_to_day_segment.R @@ -59,7 +59,7 @@ assign_rows_to_segments_frequency <- function(nested_data, nested_timezone, day_ assign_to_day_segment <- function(sensor_data, day_segments, day_segments_type, include_past_periodic_segments){ - if(nrow(sensor_data) == 0) + if(nrow(sensor_data) == 0 || nrow(day_segments) == 0) return(sensor_data %>% mutate(assigned_segments = NA)) if(day_segments_type == "FREQUENCY"){ @@ -134,7 +134,7 @@ assign_to_day_segment <- function(sensor_data, day_segments, day_segments_type, arrange(timestamp) } else if ( day_segments_type == "EVENT"){ - + sensor_data <- sensor_data %>% group_by(local_timezone) %>% nest() %>% diff --git a/src/data/compute_day_segments.py b/src/data/compute_day_segments.py index bfdb493b..0b66593c 100644 --- a/src/data/compute_day_segments.py +++ b/src/data/compute_day_segments.py @@ -1,4 +1,5 @@ import pandas as pd +import warnings def is_valid_frequency_segments(day_segments, day_segments_file): """ @@ -200,5 +201,9 @@ def parse_day_segments(day_segments_file, segments_type, pid): return day_segments final_day_segments = parse_day_segments(snakemake.input[0], snakemake.params["day_segments_type"], snakemake.params["pid"]) + +if snakemake.params["day_segments_type"] == "EVENT" and final_day_segments.shape[0] == 0: + warnings.warn("There are no event day segments for {}. Check your day segment file {}".format(snakemake.params["pid"], snakemake.input[0])) + final_day_segments.to_csv(snakemake.output["segments_file"], index=False) pd.DataFrame({"label" : final_day_segments["label"].unique()}).to_csv(snakemake.output["segments_labels_file"], index=False) \ No newline at end of file