R/fct_get_longest_path_by_vessel_id.R

Defines functions getLongestPathByVesselId

Documented in getLongestPathByVesselId

#' The function aimed to find the longest two consecutives observations
#' for a given vessel
#' @import dplyr
#' @export
getLongestPathByVesselId = function(vesselId, maxTimeInterval = NA) {
  memFuncs = memoizedFunctions()
  memFuncs(function(memo) memo$getVesselById(vesselId))  %>%
    (function(x) {
      if(is.na(maxTimeInterval) | maxTimeInterval == 0) {
        return(x)
      } else {
        x %>% filter(TIME_DIFF <= maxTimeInterval)
      }
    }) %>%        
    filter(dist == max(dist, na.rm = TRUE)) %>%
    arrange(DATETIME %>% desc()) %>%
    slice(1L) 
}
filpro/vessel_challenge documentation built on March 17, 2021, 4:53 p.m.