Skip to content

Commit

Permalink
Consolidate code in out-of-service.R
Browse files Browse the repository at this point in the history
  • Loading branch information
bpbond committed Dec 20, 2023
1 parent b212e8d commit a139224
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 53 deletions.
27 changes: 0 additions & 27 deletions synoptic/helpers.R
Original file line number Diff line number Diff line change
Expand Up @@ -351,30 +351,3 @@ ret <- valid_entries(objects = c(1, 1),
valid_through = c(1, 1))
stopifnot(ret == c(TRUE, FALSE))


# We read in a version of the Aquatroll Calibration/Removal Log
# (in Monitoring Documents on the COMPASS Google Drive) and restructure it
# into a form ready for out-of-service calculations in L1_normalize.qmd
prep_troll_oos_table <- function(troll) {
# If no time_pulled given, assume 6 AM
tp <- troll$Time_pulled
tp[is.na(tp) | tp == ""] <- "06:00"

# If no time_replaced given, assume 6 PM
tr <- troll$Time_replaced
tr[is.na(tr) | tr == ""] <- "18:00"

# If no date_replaced given, assume ongoing
dr <- troll$Date_replaced
dr[is.na(dr) | dr == ""] <- "12/31/2999"

# Calculate out of service windows
troll$oos_begin <- mdy(troll$Date_pulled, tz = "EST") + hm(tp)
troll$oos_end <- mdy(dr, tz = "EST") + hm(tr)
# Per Peter R., we throw out all data for 24 hours after replacement
troll$oos_end <- troll$oos_end + 60 * 60 * 24

troll$Sensor <- troll$Troll
troll$What <- "GW_BattV"
troll[c("Site", "Location", "Sensor", "oos_begin", "oos_end")]
}
54 changes: 28 additions & 26 deletions synoptic/out-of-service.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,32 @@
library(lubridate)


troll <- read.csv("data_TEST/out-of-service/troll_maintenance.csv")

# ===========================================================
# This code will be in L1_normalize?

# If no time_pulled given, assume 6 AM
tp <- troll$Time_pulled
tp[is.na(tp) | tp == ""] <- "06:00"

# If no time_replaced given, assume 6 PM
tr <- troll$Time_replaced
tr[is.na(tr) | tr == ""] <- "18:00"

# If no date_replaced given, assume ongoing
dr <- troll$Date_replaced
dr[is.na(dr) | dr == ""] <- "12/31/2999"

# Calculate out of service windows
troll$oos_begin <- mdy(troll$Date_pulled, tz = "EST") + hm(tp)
troll$oos_end <- mdy(dr, tz = "EST") + hm(tr)
# Per Peter R., we throw out all data for 24 hours after replacement
troll$oos_end <- troll$oos_end + 60 * 60 * 24
# ===========================================================

# We read in a version of the Aquatroll Calibration/Removal Log
# (in Monitoring Documents on the COMPASS Google Drive) and restructure it
# into a form ready for out-of-service calculations in L1_normalize.qmd
prep_troll_oos_table <- function(troll) {
# If no time_pulled given, assume 6 AM
tp <- troll$Time_pulled
tp[is.na(tp) | tp == ""] <- "06:00"

# If no time_replaced given, assume 6 PM
tr <- troll$Time_replaced
tr[is.na(tr) | tr == ""] <- "18:00"

# If no date_replaced given, assume ongoing
dr <- troll$Date_replaced
dr[is.na(dr) | dr == ""] <- "12/31/2999"

# Calculate out of service windows
troll$oos_begin <- mdy(troll$Date_pulled, tz = "EST") + hm(tp)
troll$oos_end <- mdy(dr, tz = "EST") + hm(tr)
# Per Peter R., we throw out all data for 24 hours after replacement
troll$oos_end <- troll$oos_end + 60 * 60 * 24

troll$Sensor <- troll$Troll
troll$What <- "GW_BattV"
troll[c("Site", "Location", "Sensor", "oos_begin", "oos_end")]
}


# We pass an oos_df data frame to oos()
Expand All @@ -37,8 +39,8 @@ troll$oos_end <- troll$oos_end + 60 * 60 * 24

# The second thing we pass is the observation data frame

# This function returns a logical vector that becomes F_OOS

# This function returns a logical vector, of the same length as the data_df
# input, that becomes F_OOS
oos <- function(oos_df, data_df) {

# Make sure that any 'extra' condition columns (in addition to the
Expand Down

0 comments on commit a139224

Please sign in to comment.