Skip to content

Commit

Permalink
fix fix! @fabian199827
Browse files Browse the repository at this point in the history
  • Loading branch information
jbkunst committed Sep 29, 2023
1 parent 4951a6d commit 533a110
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 17 deletions.
4 changes: 2 additions & 2 deletions R/daily_aggregation.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
23 changes: 15 additions & 8 deletions dev/00-download-data-raw-monthly-dmc.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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
Expand Down
22 changes: 15 additions & 7 deletions dev/01-daily-aggregation-dmc.R
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand All @@ -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}"))

Expand Down

0 comments on commit 533a110

Please sign in to comment.