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

## -----------------------------------------------------------------------------
library(TrackTrap)

example_path <- system.file(
  "extdata",
  "example_cimis_synthetic_daily.csv",
  package = "TrackTrap",
  mustWork = TRUE
)

example_weather <- read.csv(example_path)
names(example_weather)

expected_dates <- seq(
  as.Date("2024-04-01"),
  as.Date("2024-04-22"),
  by = "day"
)

weather_dates <- as.Date(example_weather$Date, format = "%m/%d/%Y")

stopifnot(
  !anyNA(weather_dates),
  !anyDuplicated(weather_dates),
  all(expected_dates %in% weather_dates)
)

## -----------------------------------------------------------------------------
trap_df <- data.frame(
  date = as.Date(c(
    "2024-04-01",
    "2024-04-08",
    "2024-04-15",
    "2024-04-22"
  )),
  trap_counts = c(0, 0, 3, 9)
)

result <- calc_pest_phenology(
  trap_data = trap_df,
  pest = NULL,
  weather_source = "cimis_csv",
  cimis_csv_path = example_path,
  custom_lower = 50,
  upper_cutoff = "none",
  custom_pest_label = "Illustrative trap series",
  weather_provenance = list(
    data_type = "Synthetic demonstration data",
    temperature_units = "Fahrenheit",
    description = "Daily Tmax = 85 and Tmin = 55; not station observations."
  )
)

## ----fig.width = 9, fig.height = 4.5------------------------------------------
plot_trap_phenology(result)

## ----fig.width = 9, fig.height = 4.5------------------------------------------
plot_trap_phenology(
  result,
  custom_thermal_requirement = 100,
  repeat_markers = TRUE
)

## -----------------------------------------------------------------------------
daily_calculations <- attr(result, "daily_weather")
calculation_metadata <- attr(result, "calculation_metadata")

head(daily_calculations)
calculation_metadata$biofix_date
calculation_metadata$upper_cutoff
calculation_metadata$accumulation_start
calculation_metadata$weather_provenance

