From c9ff2a2b07828b1de5d1446287b6d93e3ec8360c Mon Sep 17 00:00:00 2001 From: Damiano Oldoni Date: Mon, 9 May 2022 11:43:29 +0200 Subject: [PATCH 1/2] Fix #110 --- R/get_cam_op.R | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/R/get_cam_op.R b/R/get_cam_op.R index 16fee44c..880f97a3 100644 --- a/R/get_cam_op.R +++ b/R/get_cam_op.R @@ -90,11 +90,6 @@ get_cam_op <- function(datapkg, operational[days_operations == start_day] <- daily_effort_start operational[days_operations == end_day] <- daily_effort_end operational <- dplyr::as_tibble(operational) - # the 0s should actually be NAs meaning "camera(s) not set up". Notice - # that in the actual stadium of camera trap dp exchange format, 0s as - # returned by camtrapR::cameraOperation()` meaning "camera(s) not - # operational", will never occur. - operational <- dplyr::na_if(operational, y = 0) names(operational) <- x return(operational) }) @@ -114,12 +109,17 @@ get_cam_op <- function(datapkg, names(deployment_operational) %in% deploys_id] dep_op <- dplyr::bind_cols(dep_dfs) # sum daily effort along all deployments at same location - dep_op <- dplyr::as_tibble(rowSums(dep_op[, names(dep_op)])) + dep_op <- dplyr::as_tibble(rowSums(dep_op[, names(dep_op)], na.rm = TRUE)) # set locations as station id names(dep_op) <- loc_name if (use_prefix == TRUE) { names(dep_op) <- paste0("Station", names(dep_op)) } + # the 0s should actually be NAs meaning "camera(s) not set up". Notice + # that in the actual stadium of camera trap dp exchange format, 0s as + # returned by camtrapR::cameraOperation()` meaning "camera(s) not + # operational", will never occur. + dep_op <- dplyr::na_if(dep_op, y = 0) dep_op[[names(dep_op)]] <- as.numeric(dep_op[[names(dep_op)]]) return(dep_op) }) From af4d94e143c2981db5b4bbf29d4608bbd7397c33 Mon Sep 17 00:00:00 2001 From: Damiano Oldoni Date: Mon, 9 May 2022 12:57:21 +0200 Subject: [PATCH 2/2] Improve tests for multiple deploys at one location --- tests/testthat/test-get_cam_op.R | 48 ++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/tests/testthat/test-get_cam_op.R b/tests/testthat/test-get_cam_op.R index 70c20435..181d9c59 100644 --- a/tests/testthat/test-get_cam_op.R +++ b/tests/testthat/test-get_cam_op.R @@ -83,7 +83,55 @@ test_that("daily effort is > 0 and < 1 for partial active days (start/end)", { expect_true(cam_op_matrix[4, end] < 1) }) +test_that( + "effort is > 1 for locations with multiple deployments active at same time", { + mica1 <- mica + mica1$deployments$start[2] <- lubridate::as_datetime("2020-07-30 21:00:00") + mica1$deployments$end[2] <- lubridate::as_datetime("2020-08-07 21:00:00") + mica1$deployments$locationName[2] <- mica1$deployments$locationName[1] + cam_op_matrix <- get_cam_op(mica1) + + first_full_day_two_deps <- as.character(as.Date(mica1$deployments$start[2]) + + lubridate::ddays(1)) + last_full_day_two_deps <- as.character(as.Date(mica1$deployments$end[2]) - + lubridate::ddays(1)) + # as many rows as locations + expect_true( + nrow(cam_op_matrix) == length(unique(mica1$deployments$locationName)) + ) + expect_true(cam_op_matrix[1, first_full_day_two_deps] > 1) + expect_true(cam_op_matrix[1, last_full_day_two_deps] > 1) +}) + +test_that( + "0