Skip to content

Commit

Permalink
updated get_total_values...again...but updated tests, too.
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenranney committed May 17, 2024
1 parent b6b423e commit 75b897f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
16 changes: 12 additions & 4 deletions R/get_total_values.R
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,13 @@ get_total_values <- function(data, start_time = NULL, end_time = NULL,
wait_time = NULL, fishing_day_length = 12, sampling_prob = 1,
mean_catch_rate = NULL, scale = 1, ...){

print(fishing_day_length)

t_effort <- sum(data$trip_length)

n_anglers <- nrow(data)

lambda <- rgamma(n_anglers, mean_catch_rate, scale = scale)
# print(n_anglers, mean_catch_rate, scale)

lambda <- rgamma(n = n_anglers, shape = mean_catch_rate, scale = scale)

#Calculate true total catch for all anglers
total_catch <- sum(data$trip_length * lambda)
Expand Down Expand Up @@ -133,6 +133,7 @@ get_total_values <- function(data, start_time = NULL, end_time = NULL,
}

sampling_prob <- wait_time/fishing_day_length
# print(paste0("sampling_prob = ", sampling_prob))

################
#Effort of anglers that were onsite for the duration of the time that the clerk
Expand Down Expand Up @@ -192,7 +193,14 @@ get_total_values <- function(data, start_time = NULL, end_time = NULL,


#Scale triplength based upon the sampling probability
data$trip_length_adj <- data$trip_length/sampling_prob
data <-
data %>%
mutate(trip_length_adj = trip_length/sampling_prob,
trip_length_adj = ifelse(trip_length_adj > fishing_day_length,
fishing_day_length,
trip_length_adj))

# print(data %>% head(10))

observed_trips <- data$trip_length_adj[c(entire_time, arrivals, which_angler_departures, which_arr_dep)]
n_observed_trips <- length(observed_trips)
Expand Down
6 changes: 4 additions & 2 deletions tests/testthat/test_conduct_multiple_surveys.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ test_that("Conducting n_simulations produces n_sims rows", {
sampling_prob <- wait_time/fishing_day_length

vals <- conduct_multiple_surveys(n_sims = n_sims,
start_time = start_time, wait_time = wait_time,
n_anglers = n_anglers, n_sites = n_sites,
start_time = start_time,
wait_time = wait_time,
n_anglers = n_anglers,
n_sites = n_sites,
sampling_prob = sampling_prob,
mean_catch_rate = mean_catch_rate,
fishing_day_length = fishing_day_length)
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test_get_total_values.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ test_that("When wait time is zero, effort, completed trips, and catch is 0", {

vals <- get_total_values(anglers, wait_time = wait_time, mean_catch_rate = mean_catch_rate)

expect_equal(vals$total_observed_trip_effort, wait_time)
expect_equal(is.na(vals$total_observed_trip_effort), TRUE)
expect_equal(vals$n_completed_trips, wait_time)
expect_equal(vals$total_completed_trip_effort, wait_time)
expect_equal(vals$total_completed_trip_catch, wait_time)
Expand Down

0 comments on commit 75b897f

Please sign in to comment.