From 533a110239b6f5833dd0f25b38c5f43b0d515806 Mon Sep 17 00:00:00 2001 From: Joshua Kunst Date: Fri, 29 Sep 2023 17:36:24 -0300 Subject: [PATCH] fix fix! @fabian199827 --- R/daily_aggregation.R | 4 ++-- dev/00-download-data-raw-monthly-dmc.R | 23 +++++++++++++++-------- dev/01-daily-aggregation-dmc.R | 22 +++++++++++++++------- 3 files changed, 32 insertions(+), 17 deletions(-) diff --git a/R/daily_aggregation.R b/R/daily_aggregation.R index 7108246..09d9590 100644 --- a/R/daily_aggregation.R +++ b/R/daily_aggregation.R @@ -101,13 +101,13 @@ daily_aggregation_dmc <- function(d){ momento2 = lubridate::with_tz(momento, tzone = "America/Santiago"), fecha_hora = lubridate::floor_date(.data$momento2, "day"), .before = 1 ) |> - group_by(fecha_hora) |> + group_by(.data$station_id, fecha_hora) |> summarise(precipitacion_horaria2 = sum(prec_hora, na.rm = TRUE)) dprec ddiario <- ddiario |> - left_join(dprec, by = join_by(fecha_hora)) |> + left_join(dprec, by = join_by(station_id, fecha_hora)) |> mutate(precipitacion_horaria = precipitacion_horaria2) |> select(-precipitacion_horaria2) diff --git a/dev/00-download-data-raw-monthly-dmc.R b/dev/00-download-data-raw-monthly-dmc.R index 0796e01..bfbc194 100644 --- a/dev/00-download-data-raw-monthly-dmc.R +++ b/dev/00-download-data-raw-monthly-dmc.R @@ -18,15 +18,15 @@ fs::dir_create(folder_data) # tail(2) |> # fs::file_delete() # ) +# +# try( +# dir(folder_data, full.names = TRUE) |> +# tail(2) |> +# str_replace("raw", "daily") |> +# fs::file_delete() +# ) -try( - dir(folder_data, full.names = TRUE) |> - tail(2) |> - str_replace("raw", "daily") |> - fs::file_delete() -) - -walk(pers, function(per = 202307){ +walk(pers, function(per = 202308){ figletr::figlet(per) @@ -50,6 +50,13 @@ walk(pers, function(per = 202307){ verbose = TRUE ) + # dres |> + # # filter(station_id == "330020") |> + # agrometR:::daily_aggregation_dmc() |> + # filter(as.Date(fecha_hora) == ymd(20230823)) |> + # # filter(station_id == "330020") |> + # glimpse() + # agrometR::get_agro_data_from_api_dmc(950001, date_start = date_start, date_end = date_end) # corroboramos que todo esté dentro del periodo diff --git a/dev/01-daily-aggregation-dmc.R b/dev/01-daily-aggregation-dmc.R index 08d6670..213e4a6 100644 --- a/dev/01-daily-aggregation-dmc.R +++ b/dev/01-daily-aggregation-dmc.R @@ -10,11 +10,12 @@ try(dir.create("dev/data-daily-dmc")) # resumen diario ---------------------------------------------------------- dir(folder_data, full.names = TRUE) |> rev() |> - walk(function(f = "dev/data-raw-dmc/202107.rds"){ + walk(function(f = "dev/data-raw-dmc/202308.rds"){ # f = "dev/data-raw-dmc/202107.rds" # fs::file_delete(f) - message(f) + # message(f) + cli::cli_progress_step(f) fout <- stringr::str_replace(f, "data-raw-dmc", "data-daily-dmc") @@ -26,18 +27,25 @@ dir(folder_data, full.names = TRUE) |> if(nrow(d) == 0) return(TRUE) - glimpse(d) - + # glimpse(d) + # # removemos unidades # trimeamos # parsemos d <- d |> - mutate(across(everything(), ~ str_remove_all(.x, "°C$|kt$|°|%|Watt/m2$|hPas$|mm$"))) |> - mutate(across(where(is.character), str_trim)) |> - mutate(across(everything(), readr::parse_guess)) + # mutate(across(everything(), ~ str_remove_all(.x, "°C$|kt$|°|%|Watt/m2$|hPas$|mm$"))) |> + # mutate(across(where(is.character), str_trim)) |> + # mutate(across(everything(), readr::parse_guess)) |> + filter(TRUE) ddiario <- agrometR:::daily_aggregation_dmc(d) + # ddiario |> + # # agrometR:::daily_aggregation_dmc() |> + # filter(as.Date(fecha_hora) == ymd(20230823)) |> + # filter(station_id == "330020") |> + # glimpse() + ddiario <- ddiario |> filter(format(fecha_hora, "%Y%m") == str_extract(fout, "[0-9]{6}"))