#' @export
c2_phs_of_date <- function(date) {
mo <- month(date)
wd <- wday(date, week_start = 1)
hr <- hour(date) + 1
seas <- "E"
htype <- "HC"
if (hr %in% 7:22) {
htype <- "HP"
}
if (mo %in% c(1:3, 11:12)) {
seas <- "H"
if ((hr %in% c(10,11,19,20)) & (wd != 7)) {
seas <- ""
htype <- "Pte"
}
}
phs <- paste0(htype, seas)
phs
}
#' @export
df_with_c2_phs <- function(df, date_col="date") {
df$phs <- sapply(df$date, c2_phs_of_date)
df
}
#' @export
df_with_peak <- function(df, date_col="date") {
dfm <- df %>%
dplyr::mutate(
yr = year(df[,date_col]),
qr = quarter(df[,date_col]),
mo = month(df[,date_col]),
wd = wday(df[,date_col], week_start = 1),
hr = hour(df[,date_col]) + 1,
tl = ifelse((hr %in% 9:20) & (!wd %in% 6:7), "Peak", "Offpeak") %>% as.factor()
)
dfm
}
#' @export
format_spot <- function(spot, date_format="%Y-%m-%d") {
spot %>%
gather(key = "hour", value = "price", H0:H23) %>%
mutate(dt = with_tz(
as.POSIXct(paste(date, hour), format = paste(date_format, "H%H"),
tz = "Europe/Paris"),
Sys.getenv("TZ")
)) %>%
select(dt, price, -date, -hour) %>%
arrange(dt) %>%
na.omit() %>%
distinct(dt, .keep_all = T)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.