diff --git a/NAMESPACE b/NAMESPACE index 464fa0c34..b231864c4 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -112,6 +112,7 @@ export(portal_ndvi_href) export(portal_project_href) export(portal_weather_href) export(portalcast) +export(post_process) export(prefab_datasets) export(prefab_datasets_controls) export(prefab_models) diff --git a/R/fill_dir.R b/R/fill_dir.R index 30dc660bd..fa5d22303 100644 --- a/R/fill_dir.R +++ b/R/fill_dir.R @@ -242,18 +242,12 @@ fill_forecasts <- function (main = ".") { messageq(paste0(" Located ", length(files), " forecast file(s) in resources to be moved to directory ..."), quiet = settings$quiet) messageq(" ... moving ... ", quiet = settings$quiet) - - # zip the forecast files before copying them back - zip_unzip("zip", forecast_path = forecasts_path(main = main)) - copied <- file.copy(from = files, to = forecasts_path(main = main), recursive = TRUE) messageq(paste0(" ... ", sum(copied), " files moved. "), quiet = settings$quiet) - # zip the forecast zipped files - zip_unzip("zip", forecast_path = forecasts_path(main = main)) invisible( ) } @@ -319,3 +313,13 @@ fill_models <- function (main = ".", } +#' After portalcast and evaluate_forecast run post_process to zip files +#' +#' @param main location of main directory with a forecast dir +#' +#' @export +#' +post_process <- function(main= ".") { + settings <- read_directory_settings(main = main) + zip_unzip("zip", forecasts_path(main = main)) +} diff --git a/R/zip_unzip_forecasts.R b/R/zip_unzip_forecasts.R index ef5405947..6a26197f6 100644 --- a/R/zip_unzip_forecasts.R +++ b/R/zip_unzip_forecasts.R @@ -20,36 +20,39 @@ zip_unzip <- function(type = NULL, utils::zip(zipfile, files) unlink(files) } - + messageq("Preparing forecasts files") proj_path <- forecast_path forecasts_metadata <- paste0(proj_path, "/forecasts_metadata.csv") - + proj_path <- normalizePath(proj_path, mustWork = FALSE) - forecasts_metadata <- normalizePath(forecasts_metadata, mustWork = FALSE) + forecasts_metadata <- + normalizePath(forecasts_metadata, mustWork = FALSE) metadata <- read.csv(forecasts_metadata) unique_dates <- sort(unique(metadata$"forecast_date")) - + if (type == "zip") { csv_file <- "_forecast_table.csv" yaml_file <- "_metadata.yaml" json_file <- "_model_forecast.json" - + if (!is.null(date)) { unique_dates <- c(date) messageq(paste0("Zipping forecasts files for ", date)) } - + for (forecast_day in unique_dates) { id_date_files <- c() - zipfile <- paste0(proj_path, "/forecast_id_", forecast_day, ".zip") - + zipfile <- + paste0(proj_path, "/forecast_id_", forecast_day, ".zip") + # Get all the values of that particular day in a data frame - newdata <- subset(metadata, + newdata <- subset( + metadata, forecast_date == forecast_day, select = c("forecast_id", "forecast_date") ) - + # For each forecast_id get 3 files All_ids <- newdata$"forecast_id" for (id in All_ids) { @@ -57,31 +60,33 @@ zip_unzip <- function(type = NULL, if (file.exists(csv_file_path)) { id_date_files <- c(id_date_files, csv_file_path) } - yaml_file_path <- paste0(proj_path, "/forecast_id_", id, yaml_file) + yaml_file_path <- + paste0(proj_path, "/forecast_id_", id, yaml_file) if (file.exists(yaml_file_path)) { id_date_files <- c(id_date_files, yaml_file_path) } - json_file_path <- paste0(proj_path, "/forecast_id_", id, json_file) + json_file_path <- + paste0(proj_path, "/forecast_id_", id, json_file) if (file.exists(json_file_path)) { id_date_files <- c(id_date_files, json_file_path) } } - + if (length(id_date_files)) { # Zip forecast files for the current date zip_files(zipfile, id_date_files) } } - + # Zip forecasts_evaluations.csv eval_file <- paste0(proj_path, "/forecasts_evaluations.csv") zipfile <- paste0(proj_path, "/forecasts_evaluations.zip") zip_files(zipfile, eval_file) } - + if (type == "unzip") { messageq("Unzipping forecasts files") - + # Unzip files based on unique_dates for (forecast_day in unique_dates) { zipfile <- paste0(proj_path, "/forecast_id_", forecast_day, ".zip") @@ -91,7 +96,7 @@ zip_unzip <- function(type = NULL, unlink(zipfile) } } - + # Unzip forecasts_evaluations.csv eval_zip <- paste0(proj_path, "/forecasts_evaluations.zip") eval_zip <- normalizePath(eval_zip, mustWork = FALSE) diff --git a/man/post_process.Rd b/man/post_process.Rd new file mode 100644 index 000000000..9cf0ffb98 --- /dev/null +++ b/man/post_process.Rd @@ -0,0 +1,14 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/fill_dir.R +\name{post_process} +\alias{post_process} +\title{After portalcast and evaluate_forecast run post_process to zip files} +\usage{ +post_process(main = ".") +} +\arguments{ +\item{main}{location of main directory with a forecast dir} +} +\description{ +After portalcast and evaluate_forecast run post_process to zip files +}