Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve pool_movement_data on ShinyApp #11

Closed
matiasandina opened this issue Jun 11, 2020 · 1 comment
Closed

Improve pool_movement_data on ShinyApp #11

matiasandina opened this issue Jun 11, 2020 · 1 comment

Comments

@matiasandina
Copy link
Owner

Current function is

pool_movement_data <- function(date){
    pattern_to_find <- paste0(date,".*_opt_flow.csv")
    # TODO: improve this so that is not recursive
    files <- list.files(pattern = pattern_to_find, recursive = TRUE, full.names = TRUE)
    names(files) <- files
    pooled_data <- purrr::map(files,
                              function(tt) read_csv(tt, col_names = "total_flow") %>% 
                                  # replace first element with zero
                                  mutate(total_flow = replace(total_flow, 1, 0))
    ) %>%
        bind_rows(.id="source") 
    
    if(nrow(pooled_data) > 0){
        pooled_data <- pooled_data %>%
            # clean
            mutate(mac = str_extract(source, "[a-z|0-9]{2}:.*/"),
                   mac = str_remove(mac, "/"),
            )
    }
    return(pooled_data)    
}
@matiasandina
Copy link
Owner Author

matiasandina commented Jun 11, 2020

This was written when optic flow had only one value (the total_flow).
The new way has more columns, so

  • Separate the reading itself to a parsing function that is called by map
  • This new function has to account for the number of columns and handle them or throw error
  • This function needs to clean the pool data because see opt_flow saves xy as tupple #10
flow_df <- purrr::map(flow_files,
          function(x)
          read_delim(x,
                     delim=",",
                     col_names = c("datetime", "movement", "x", "y")))

names(flow_df) <- basename(flow_files)
flow_df <- flow_df %>% bind_rows(.id="filename")

# clean
flow_df <- flow_df %>% 
  mutate(x = as.numeric(str_extract(x, "[0-9]+")),
         y = as.numeric(str_extract(y, "[0-9]+")))
  • Additionally, improve the list files thing to avoid recursion

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant