## ----setup, include = FALSE---------------------------------------------------
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)

## ----single-count, message = FALSE--------------------------------------------
library(tidycreel)

# Survey calendar: four days, two strata
calendar <- data.frame(
  date = as.Date(c("2024-06-01", "2024-06-02", "2024-06-03", "2024-06-04")),
  day_type = c("weekday", "weekday", "weekend", "weekend")
)

design <- creel_design(calendar, date = date, strata = day_type)

# One count per day
counts <- data.frame(
  date      = as.Date(c("2024-06-01", "2024-06-02", "2024-06-03", "2024-06-04")),
  day_type  = c("weekday", "weekday", "weekend", "weekend"),
  n_anglers = c(15L, 23L, 45L, 52L)
)

design <- add_counts(design, counts)
result <- estimate_effort(design)
result$estimates

## ----multi-count, message = FALSE---------------------------------------------
# Two circuits per day: morning ("am") and afternoon ("pm")
calendar_m <- data.frame(
  date = as.Date(c("2024-06-01", "2024-06-02", "2024-06-03", "2024-06-04")),
  day_type = c("weekday", "weekday", "weekend", "weekend")
)

design_m <- creel_design(calendar_m, date = date, strata = day_type)

multi_counts <- data.frame(
  date = as.Date(rep(c(
    "2024-06-01", "2024-06-02",
    "2024-06-03", "2024-06-04"
  ), each = 2)),
  day_type = rep(c("weekday", "weekday", "weekend", "weekend"), each = 2),
  count_time = rep(c("am", "pm"), 4),
  n_anglers = c(12L, 18L, 20L, 26L, 40L, 50L, 48L, 56L)
)

design_m <- add_counts(design_m, multi_counts, count_time_col = count_time)
result_m <- estimate_effort(design_m)
result_m$estimates

## ----progressive, message = FALSE---------------------------------------------
calendar_p <- data.frame(
  date       = as.Date(c("2024-06-01", "2024-06-02", "2024-06-03", "2024-06-04")),
  day_type   = c("weekday", "weekday", "weekend", "weekend")
)

design_p <- creel_design(calendar_p, date = date, strata = day_type)

prog_counts <- data.frame(
  date = as.Date(c("2024-06-01", "2024-06-02", "2024-06-03", "2024-06-04")),
  day_type = c("weekday", "weekday", "weekend", "weekend"),
  n_anglers = c(15L, 23L, 45L, 52L),
  shift_hours = rep(8, 4)
)

design_p <- add_counts(
  design_p, prog_counts,
  count_type = "progressive",
  circuit_time = 2,
  period_length_col = shift_hours
)

result_p <- estimate_effort(design_p)
result_p$estimates

## ----pope-example, message = FALSE--------------------------------------------
# Reproduce Pope et al. per-day calculation
cal_pope <- data.frame(
  date       = as.Date(c("2024-06-01", "2024-06-02")),
  day_type   = c("weekday", "weekday")
)
design_pope <- creel_design(cal_pope, date = date, strata = day_type)

cnt_pope <- data.frame(
  date        = as.Date(c("2024-06-01", "2024-06-02")),
  day_type    = c("weekday", "weekday"),
  n_anglers   = c(234L, 200L),
  shift_hours = c(8, 8)
)

design_pope <- add_counts(
  design_pope, cnt_pope,
  count_type = "progressive",
  circuit_time = 2,
  period_length_col = shift_hours
)

# Per-day Ê_d values stored in the design (first day = 1,872 angler-hours)
design_pope$counts

