Update battery_deltas.R to handle empty dataframes
parent
d7536d5cb5
commit
d2e9b79af6
|
@ -4,7 +4,8 @@ library("tidyverse")
|
|||
|
||||
battery <- read.csv(snakemake@input[[1]])
|
||||
|
||||
consumption <- battery %>%
|
||||
if(nrow(battery) > 0){
|
||||
consumption <- battery %>%
|
||||
mutate(group = ifelse(lag(battery_status) != battery_status, 1, 0) %>% coalesce(0),
|
||||
group_id = cumsum(group) + 1) %>%
|
||||
filter(battery_status == 2 || battery_status == 3) %>%
|
||||
|
@ -17,5 +18,13 @@ consumption <- battery %>%
|
|||
local_end_date = last(local_date)) %>%
|
||||
select(-group_id) %>%
|
||||
filter(time_diff > 0.1) # Avoids including quick cycles
|
||||
} else {
|
||||
consumption <- data.frame(battery_diff = numeric(),
|
||||
time_diff = numeric(),
|
||||
local_start_date_time = character(),
|
||||
local_end_date_time = character(),
|
||||
local_start_date = character(),
|
||||
local_end_date = character())
|
||||
}
|
||||
|
||||
write.csv(consumption, snakemake@output[[1]], row.names = FALSE)
|
||||
|
|
Loading…
Reference in New Issue