generated from WorldFishCenter/peskas.timor.data.pipeline
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update preprocessing step, prepare for validation step
- Loading branch information
Showing
9 changed files
with
157 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,7 +25,8 @@ Imports: | |
readr, | ||
stringr, | ||
tidyr, | ||
rlang | ||
rlang, | ||
lubridate | ||
Suggests: | ||
covr, | ||
pkgdown, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#' Download WCS preprocessed surveys | ||
#' | ||
#' Download preprocessed WCS data from Google Cloud. | ||
#' | ||
#' @param pars The configuration file. | ||
#' | ||
#' @return A rds dataframe of preprocessed survey landings. | ||
#' @export | ||
#' | ||
get_preprocessed_surveys <- function(pars) { | ||
wcs_preprocessed_surveys <- | ||
cloud_object_name( | ||
prefix = pars$surveys$preprocessed_surveys$file_prefix, | ||
provider = pars$storage$google$key, | ||
extension = "rds", | ||
version = pars$surveys$wcs_surveys$version$preprocess, | ||
options = pars$storage$google$options | ||
) | ||
|
||
logger::log_info("Retrieving {wcs_preprocessed_surveys}") | ||
download_cloud_file( | ||
name = wcs_preprocessed_surveys, | ||
provider = pars$storage$google$key, | ||
options = pars$storage$google$options | ||
) | ||
|
||
readr::read_rds(wcs_preprocessed_surveys) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#' Validate surveys' temporal parameters | ||
#' | ||
#' This function takes a preprocessed landings' matrix and validate temporal | ||
#' info associated to each survey. | ||
#' | ||
#' @param data A preprocessed data frame | ||
#' @param hrs_max Upper threshold of fishing trip duration. | ||
#' @param hrs_min Lower threshold of fishing trip duration. | ||
#' | ||
#' @return A list containing data frames with validated catch dates and catch | ||
#' duration. | ||
#' | ||
#' @importFrom rlang .data | ||
#' @export | ||
#' | ||
#' @examples | ||
#' \dontrun{ | ||
#' pars <- read_config() | ||
#' landings <- get_preprocessed_surveys(pars) | ||
#' validate_surveys_time(landings, hrs_max = 72, hrs_min = 1) | ||
#' } | ||
validate_surveys_time <- function(data, hrs_max = NULL, hrs_min) { | ||
validated_time <- list( | ||
validated_dates = data %>% | ||
dplyr::select(.data$`_id`, date = .data$today) %>% | ||
dplyr::mutate( | ||
date = lubridate::with_tz(.data$date, "Africa/Dar_es_Salaam"), | ||
date = as.Date(date) | ||
), | ||
validated_duration = data %>% | ||
dplyr::select(.data$`_id`, .data$fishing_duration) %>% | ||
dplyr::mutate(fishing_duration = abs(as.numeric(.data$fishing_duration))) %>% | ||
dplyr::transmute( | ||
trip_duration = dplyr::case_when( | ||
.data$fishing_duration > hrs_max | | ||
.data$fishing_duration < hrs_min ~ NA_real_, | ||
TRUE ~ .data$fishing_duration | ||
), # test if catch duration is longer than n hours or minor than 1 hour | ||
alert_number = dplyr::case_when( | ||
.data$fishing_duration > hrs_max | | ||
.data$fishing_duration < hrs_min ~ 5, | ||
TRUE ~ NA_real_ | ||
), | ||
submission_id = as.integer(.data$`_id`) | ||
) | ||
) | ||
validated_time | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.