Fix bug when there are no event segments for participants
parent
47adb8bc4b
commit
c41d24df45
|
@ -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() %>%
|
||||
|
|
|
@ -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)
|
Loading…
Reference in New Issue