diff --git a/R/extremes_summaries.R b/R/extremes_summaries.R index b57360c..67c0c9a 100644 --- a/R/extremes_summaries.R +++ b/R/extremes_summaries.R @@ -16,33 +16,33 @@ extremes_summaries <- function(country, station_id, summaries = c("extremes_rain", "extremes_tmin", "extremes_tmax"), override = FALSE){ - list_return <- NULL - - # do the summaries exist already? - get_summaries <- get_summaries_data(country, station_id, summary = "extremes_summaries") - summary_data <- get_summaries[[1]] - - # if the summary data exists, and if you do not want to override it then: - if (nrow(summary_data) > 0 & override == FALSE) { - # what if the definitions is different? - file_name <- get_objects_in_bucket(country, station_id, timestamp = get_summaries[[2]]) - if (nrow(file_name) == 0) { - list_return[[1]] <- (definitions(country, station_id = station_id, summaries = summaries)) - } else { - list_return[[1]] <- (definitions(country, station_id = station_id, summaries = summaries, file = paste0(station_id, ".", get_summaries[[2]]))) - } - } else { - # Fetch daily data and preprocess - daily <- get_daily_data(country = country, station_id = station_id) - # For the variable names to be set as a certain default, set TRUE here, and run check_and_rename_variables - data_names <- data_definitions(names(daily), TRUE) - daily <- check_and_rename_variables(daily, data_names) - definitions <- epicsawrap::definitions(country = country, station_id = station_id, summaries = summaries) - summary_data <- purrr::map(.x = summaries, .f = ~ overall_extremes_summaries(daily = daily, data_names = data_names, definitions = definitions, summaries = .x)) - summary_data <- purrr::reduce(summary_data, dplyr::full_join) - summary_data[is.na(summary_data)] <- 0 - list_return[[1]] <- c(definitions) - } - list_return[[2]] <- summary_data - return(list_return) + # list_return <- NULL + # + # # do the summaries exist already? + # get_summaries <- get_summaries_data(country, station_id, summary = "extremes_summaries") + # summary_data <- get_summaries[[1]] + # + # # if the summary data exists, and if you do not want to override it then: + # if (nrow(summary_data) > 0 & override == FALSE) { + # # what if the definitions is different? + # file_name <- get_objects_in_bucket(country, station_id, timestamp = get_summaries[[2]]) + # if (nrow(file_name) == 0) { + # list_return[[1]] <- (definitions(country, station_id = station_id, summaries = summaries)) + # } else { + # list_return[[1]] <- (definitions(country, station_id = station_id, summaries = summaries, file = paste0(station_id, ".", get_summaries[[2]]))) + # } + # } else { + # # Fetch daily data and preprocess + # daily <- get_daily_data(country = country, station_id = station_id) + # # For the variable names to be set as a certain default, set TRUE here, and run check_and_rename_variables + # data_names <- data_definitions(names(daily), TRUE) + # daily <- check_and_rename_variables(daily, data_names) + # definitions <- epicsawrap::definitions(country = country, station_id = station_id, summaries = summaries) + # summary_data <- purrr::map(.x = summaries, .f = ~ overall_extremes_summaries(daily = daily, data_names = data_names, definitions = definitions, summaries = .x)) + # summary_data <- purrr::reduce(summary_data, dplyr::full_join) + # summary_data[is.na(summary_data)] <- 0 + # list_return[[1]] <- c(definitions) + # } + # list_return[[2]] <- summary_data + # return(list_return) } diff --git a/R/overall_extremes_summaries.R b/R/overall_extremes_summaries.R index 392b17e..2ea7adc 100644 --- a/R/overall_extremes_summaries.R +++ b/R/overall_extremes_summaries.R @@ -14,24 +14,24 @@ #' # Generate summary statistics for extreme rain events #' #rain_summary <- overall_extremes_summaries(daily_data, definitions_list, "extremes_rain") overall_extremes_summaries <- function(daily, data_names, definitions, summaries){ - if (is.null(definitions[[summaries]]$direction)){ - direction <- "greater" - } else { - direction <- as.character(definitions[[summaries]]$direction) - } - if (is.null(definitions[[summaries]]$type)){ - type <- "greater" - } else { - type <- as.character(definitions[[summaries]]$type) - } - - summary_data <- rpicsa::get_extremes(data = daily, - station = data_names$station, - year = data_names$year, - element = if (summaries == "extremes_rain") data_names$rain else if (summaries == "extremes_tmin") data_names$tmin else if (summaries == "extremes_tmax") data_names$tmax else NULL, - type = type, - direction = direction, - value = as.integer(definitions[[summaries]]$value)) - summary_data <- summary_data %>% dplyr::rename(!!summaries := "count") - return(summary_data) + # if (is.null(definitions[[summaries]]$direction)){ + # direction <- "greater" + # } else { + # direction <- as.character(definitions[[summaries]]$direction) + # } + # if (is.null(definitions[[summaries]]$type)){ + # type <- "greater" + # } else { + # type <- as.character(definitions[[summaries]]$type) + # } + # + # summary_data <- rpicsa::get_extremes(data = daily, + # station = data_names$station, + # year = data_names$year, + # element = if (summaries == "extremes_rain") data_names$rain else if (summaries == "extremes_tmin") data_names$tmin else if (summaries == "extremes_tmax") data_names$tmax else NULL, + # type = type, + # direction = direction, + # value = as.integer(definitions[[summaries]]$value)) + # summary_data <- summary_data %>% dplyr::rename(!!summaries := "count") + # return(summary_data) } \ No newline at end of file