Skip to content

Commit

Permalink
turn on complete.
Browse files Browse the repository at this point in the history
  • Loading branch information
joethorley committed Apr 23, 2024
1 parent 96ff937 commit ae04a11
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 17 deletions.
11 changes: 10 additions & 1 deletion R/internal.R
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ complete_dates <- function(x, start_date, end_date) {
end_temp = 4,
window_width = window_width,
msgs = FALSE,
complete = TRUE,
.rollmean = TRUE), .keep = TRUE)

if(!nrow(x)) {
Expand Down Expand Up @@ -268,7 +269,14 @@ complete_dates <- function(x, start_date, end_date) {
x <- x |>
dplyr::summarise(gsdd = gsdd_vctr(
.data$temperature,
ignore_truncation = ignore_truncation, min_length = min_length, start_temp, end_temp = end_temp, window_width = window_width, pick = pick, msgs = msgs), .groups = "keep") |>
ignore_truncation = ignore_truncation,
min_length = min_length,
start_temp = start_temp,
end_temp = end_temp,
window_width = window_width,
pick = pick,
complete = TRUE,
msgs = msgs), .groups = "keep") |>
dplyr::ungroup()

return(x)
Expand All @@ -284,6 +292,7 @@ complete_dates <- function(x, start_date, end_date) {
end_temp = end_temp,
window_width = window_width,
pick = pick,
complete = TRUE,
msgs = msgs), .keep = TRUE)

if(!nrow(x)) {
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/_snaps/gsdd.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
# A tibble: 1 x 2
year gsdd
<int> <dbl>
1 2019 545.
1 2019 529.

# gsdd ignore truncation tiny window

Expand Down
Binary file modified tests/testthat/_snaps/gss-plot/gss_plot8.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/testthat/_snaps/gss-plot/gss_plot9.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
30 changes: 22 additions & 8 deletions tests/testthat/_snaps/gss.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
# Groups: year [1]
year start_dayte end_dayte gsdd truncation
<int> <date> <date> <dbl> <chr>
1 2019 1971-03-20 1971-11-07 3899. start
1 2019 1971-03-20 1971-11-07 3899. none

# gss preserves if shift before leap year

Expand Down Expand Up @@ -104,6 +104,17 @@
# i 5 variables: year <int>, start_dayte <date>, end_dayte <date>, gsdd <dbl>,
# truncation <chr>

# gss works shortened truncated

Code
gss
Output
# A tibble: 1 x 5
# Groups: year [1]
year start_dayte end_dayte gsdd truncation
<int> <date> <date> <dbl> <chr>
1 2019 1971-03-20 1971-09-28 3580. end

# gss NA if stops before

Code
Expand Down Expand Up @@ -257,7 +268,7 @@
# Groups: year [1]
year start_dayte end_dayte gsdd truncation
<int> <date> <date> <dbl> <chr>
1 2019 1971-03-01 1971-06-04 742 start
1 2019 1971-03-02 1971-06-04 736 start
2 2019 1971-07-15 1971-09-03 800 none

# gss truncation end
Expand All @@ -270,7 +281,7 @@
year start_dayte end_dayte gsdd truncation
<int> <date> <date> <dbl> <chr>
1 2019 1971-04-08 1971-06-04 500 none
2 2019 1971-07-15 1971-11-30 1255 end
2 2019 1971-07-15 1971-11-29 1250 end

# gss truncation both ends

Expand All @@ -281,8 +292,8 @@
# Groups: year [1]
year start_dayte end_dayte gsdd truncation
<int> <date> <date> <dbl> <chr>
1 2019 1971-03-01 1971-06-04 742 start
2 2019 1971-07-15 1971-11-30 1255 end
1 2019 1971-03-02 1971-06-04 736 start
2 2019 1971-07-15 1971-11-29 1250 end

# gss truncation all

Expand All @@ -293,7 +304,7 @@
# Groups: year [1]
year start_dayte end_dayte gsdd truncation
<int> <date> <date> <dbl> <chr>
1 2019 1971-03-01 1971-11-30 1650 both
1 2019 1971-03-02 1971-11-29 1638 both

# gss not shift

Expand All @@ -309,13 +320,16 @@
# gss above from start to finish

Code
gss_ignore
gss
Output
# A tibble: 1 x 5
# Groups: year [1]
year start_dayte end_dayte gsdd truncation
<int> <date> <date> <dbl> <chr>
1 2019 1971-03-01 1971-11-30 1650 both
1 2019 1971-03-01 1971-11-30 1650 none

# gss truncated if missing

Code
gss
Output
Expand Down
8 changes: 6 additions & 2 deletions tests/testthat/test-gsdd.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,19 @@ test_that("gsdd NA if earlier truncation", {
})

test_that("gsdd NA if truncated", {
gsdd <- gsdd(temperature_data, start_date = as.Date("1972-05-01"), end_date = as.Date("1972-05-30"),
data <- temperature_data
data <- data[data$date >= as.Date("2019-05-02"),]
gsdd <- gsdd(data, start_date = as.Date("1972-05-01"), end_date = as.Date("1972-05-30"),
msgs = FALSE)
expect_snapshot({
gsdd
})
})

test_that("gsdd ignore truncation", {
gsdd <- gsdd(temperature_data, start_date = as.Date("1972-05-01"), end_date = as.Date("1972-05-30"),
data <- temperature_data
data <- data[data$date >= as.Date("2019-05-02"),]
gsdd <- gsdd(data, start_date = as.Date("1972-05-01"), end_date = as.Date("1972-05-30"),
msgs = FALSE, ignore_truncation = TRUE)
expect_snapshot({
gsdd
Expand Down
32 changes: 27 additions & 5 deletions tests/testthat/test-gss.R
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,24 @@ test_that("gss works", {
})

test_that("gss works shortened", {
expect_message(gss <- gss(temperature_data, min_length = 100, end_date = as.Date("1972-09-29")),
data <- temperature_data
data <- data[data$date <= as.Date("2019-09-28"),]
expect_message(gss <- gss(data, min_length = 100, end_date = as.Date("1972-09-29")),
"The growing season is truncated at the end of the sequence.")
expect_snapshot({
gss
})
})

test_that("gss works shortened truncated", {
data <- temperature_data
data <- data[data$date <= as.Date("2019-09-28"),]
gss <- gss(data, min_length = 100, end_date = as.Date("1972-09-29"), ignore_truncation = "end")
expect_snapshot({
gss
})
})

test_that("gss NA if stops before", {
data <- temperature_data
data <- data[data$date < as.Date("2019-09-30"),]
Expand Down Expand Up @@ -200,6 +211,7 @@ test_that("gss truncation start", {
data <- gsdd::temperature_data
data$temperature <- data$temperature2
data$temperature[data$date <= as.Date("2019-04-11")] <- 6
data <- data[data$date >= as.Date("2019-03-02"),]
gss <- gss(data, ignore_truncation =TRUE)
expect_snapshot({
gss
Expand All @@ -210,6 +222,7 @@ test_that("gss truncation end", {
data <- gsdd::temperature_data
data$temperature <- data$temperature2
data$temperature[data$date >= as.Date("2019-08-28")] <- 5
data <- data[data$date <= as.Date("2019-11-29"),]
gss <- gss(data, ignore_truncation =TRUE)
expect_snapshot({
gss
Expand All @@ -221,7 +234,8 @@ test_that("gss truncation both ends", {
data$temperature <- data$temperature2
data$temperature[data$date <= as.Date("2019-04-11")] <- 6
data$temperature[data$date >= as.Date("2019-08-28")] <- 5
gss <- gss(data, ignore_truncation =TRUE)
data <- data[data$date >= as.Date("2019-03-02") & data$date <= as.Date("2019-11-29"),]
gss <- gss(data, min_length = 100, ignore_truncation =TRUE)
expect_snapshot({
gss
})
Expand All @@ -231,7 +245,8 @@ test_that("gss truncation all", {
data <- gsdd::temperature_data
data$temperature <- data$temperature2
data$temperature <- 6
gss <- gss(data, ignore_truncation =TRUE)
data <- data[data$date >= as.Date("2019-03-02") & data$date <= as.Date("2019-11-29"),]
gss <- gss(data, min_length = 100, ignore_truncation =TRUE)
expect_snapshot({
gss
})
Expand Down Expand Up @@ -327,11 +342,18 @@ test_that("gss not shift", {
test_that("gss above from start to finish", {
data <- gsdd::temperature_data
data$temperature <- 6
gss_ignore <- gss(data, ignore_truncation = TRUE)
gss <- gss(data)
expect_snapshot({
gss_ignore
gss
})
})

test_that("gss truncated if missing", {
data <- gsdd::temperature_data
data <- data[data$date >= as.Date("2019-03-02"),]
data$temperature <- 6
expect_message(gss <- gss(data), "The growing season is truncated at the start of the sequence.")
expect_snapshot({
gss
})
})

0 comments on commit ae04a11

Please sign in to comment.