Skip to content

Commit

Permalink
Test only
Browse files Browse the repository at this point in the history
  • Loading branch information
henrykironde committed Dec 5, 2023
1 parent 44aa852 commit d008ca1
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 23 deletions.
38 changes: 19 additions & 19 deletions R/zip_unzip_forecasts.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
zip_unzip <- function(type = NULL,
forecast_path = "forecasts/",
date = NULL) {

# Function to zip a list of files
zip_files <- function(zipfile, files) {
zipfile <- normalizePath(zipfile, mustWork = FALSE)
Expand All @@ -18,40 +17,41 @@ zip_unzip <- function(type = NULL,
unlink(zipfile)

Check warning on line 17 in R/zip_unzip_forecasts.R

View check run for this annotation

Codecov / codecov/patch

R/zip_unzip_forecasts.R#L17

Added line #L17 was not covered by tests
}
# Zip all files in the list
zip(zipfile, files)
utils::zip(zipfile, files)
unlink(files)

Check warning on line 21 in R/zip_unzip_forecasts.R

View check run for this annotation

Codecov / codecov/patch

R/zip_unzip_forecasts.R#L20-L21

Added lines #L20 - L21 were not covered by tests
}

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)
metadata <- read.csv(forecasts_metadata)
unique_dates <- sort(unique(metadata$forecast_date))
unique_dates <- sort(unique(metadata$"forecast_date"))

if (type == "zip") {
csv_file <- "_forecast_table.csv"
yaml_file <- "_metadata.yaml"
json_file <- "_model_forecast.json"

Check warning on line 36 in R/zip_unzip_forecasts.R

View check run for this annotation

Codecov / codecov/patch

R/zip_unzip_forecasts.R#L34-L36

Added lines #L34 - L36 were not covered by tests

if (!is.null(date)) {
unique_dates = c(date)
unique_dates <- c(date)
messageq(paste0("Zipping forecasts files for ", date))

Check warning on line 40 in R/zip_unzip_forecasts.R

View check run for this annotation

Codecov / codecov/patch

R/zip_unzip_forecasts.R#L38-L40

Added lines #L38 - L40 were not covered by tests
}

for (forecast_day in unique_dates) {
id_date_files <- c()
zipfile <- paste0(proj_path, "/forecast_id_", forecast_day, ".zip")

Check warning on line 45 in R/zip_unzip_forecasts.R

View check run for this annotation

Codecov / codecov/patch

R/zip_unzip_forecasts.R#L43-L45

Added lines #L43 - L45 were not covered by tests

# Get all the values of that particular day in a data frame
newdata <- subset(metadata,
forecast_date == forecast_day,
select = c(forecast_id, forecast_date))

forecast_date == forecast_day,
select = c(forecast_id, forecast_date)

Check warning on line 50 in R/zip_unzip_forecasts.R

View check run for this annotation

Codecov / codecov/patch

R/zip_unzip_forecasts.R#L48-L50

Added lines #L48 - L50 were not covered by tests
)

# For each forecast_id get 3 files
All_ids <- newdata$forecast_id
All_ids <- newdata$"forecast_id"
for (id in All_ids) {
csv_file_path <- paste0(proj_path, "/forecast_id_", id, csv_file)
if (file.exists(csv_file_path)) {
Expand All @@ -66,22 +66,22 @@ zip_unzip <- function(type = NULL,
id_date_files <- c(id_date_files, json_file_path)

Check warning on line 66 in R/zip_unzip_forecasts.R

View check run for this annotation

Codecov / codecov/patch

R/zip_unzip_forecasts.R#L64-L66

Added lines #L64 - L66 were not covered by tests
}
}

if (length(id_date_files)) {

Check warning on line 70 in R/zip_unzip_forecasts.R

View check run for this annotation

Codecov / codecov/patch

R/zip_unzip_forecasts.R#L70

Added line #L70 was not covered by tests
# Zip forecast files for the current date
zip_files(zipfile, id_date_files)

Check warning on line 72 in R/zip_unzip_forecasts.R

View check run for this annotation

Codecov / codecov/patch

R/zip_unzip_forecasts.R#L72

Added line #L72 was not covered by tests
}
}

# Zip forecasts_evaluations.csv
eval_file <- paste0(proj_path, "/forecasts_evaluations.csv")
zipfile <- paste0(proj_path, "/forecasts_evaluations.zip")
zip_files(zipfile, eval_file)

Check warning on line 79 in R/zip_unzip_forecasts.R

View check run for this annotation

Codecov / codecov/patch

R/zip_unzip_forecasts.R#L77-L79

Added lines #L77 - L79 were not covered by tests
}

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")
Expand All @@ -91,7 +91,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)
Expand Down
6 changes: 3 additions & 3 deletions man/zip_unzip.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tests/testthat/test-62-webapp_server.R
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ test_that(desc = "server functions work off of global list", {

main <- main3

testServer(app_paths(main = main3)$file, {
shiny::testServer(app_paths(main = main3)$file, {

session$setInputs(forecast_tab_species = global$initial_forecast_tab_selected_species,
forecast_tab_dataset = global$initial_forecast_tab_selected_dataset,
Expand Down

0 comments on commit d008ca1

Please sign in to comment.