|
35 | 35 | transform_matrix_to_hub_df <- |
36 | 36 | function(fc_matrix, forecast_date, fips_code, target_name, n_samples = NULL, |
37 | 37 | quantile_levels = c(0.025, 0.25, 0.5, 0.75, 0.975), h_ahead = 56, |
38 | | - keep_bottommost_only = TRUE) { |
| 38 | + temp_res = 1, keep_bottommost_only = TRUE) { |
39 | 39 | if (!is.null(n_samples)) { |
40 | 40 | if (n_samples > nrow(fc_matrix)) { |
41 | 41 | stop("Requested number of samples cannot exceed the number that have been provided") |
@@ -67,18 +67,27 @@ transform_matrix_to_hub_df <- |
67 | 67 | ) |> |
68 | 68 | dplyr::mutate( |
69 | 69 | forecast_date = forecast_date, |
| 70 | + level = .data[["k"]], |
70 | 71 | location = fips_code, |
71 | 72 | horizon = as.numeric(.data[["h"]]) * .data[["k"]], |
72 | | - temporal_resolution = "daily", |
| 73 | + temporal_resolution = dplyr::case_when( |
| 74 | + temp_res == 1 ~ "daily", |
| 75 | + temp_res == 7 ~ "weekly", |
| 76 | + temp_res == 30 ~ "monthly", |
| 77 | + temp_res == 365 ~ "yearly", |
| 78 | + .default = as.character(temp_res) |
| 79 | + ), |
73 | 80 | target = target_name, |
74 | | - target_end_date = forecast_date + .data[["horizon"]], |
| 81 | + target_end_date = forecast_date + .data[["horizon"]] * temp_res, |
75 | 82 | type = ifelse(as.numeric(.data[["Var1"]] < 1), "quantile", "sample"), |
76 | 83 | quantile = as.numeric(.data[["Var1"]]), |
77 | 84 | value = ifelse(.data[["Freq"]] < 0, 0, .data[["Freq"]]), |
78 | 85 | ) |
79 | 86 |
|
80 | 87 | if (keep_bottommost_only) { |
81 | | - hub_df <- dplyr::filter(hub_df, .data[["k"]] == min(hub_df$k)) |
| 88 | + hub_df <- hub_df |> |
| 89 | + dplyr::filter(.data[["k"]] == min(hub_df$k)) |> |
| 90 | + dplyr::select(-"level") |
82 | 91 | } |
83 | 92 |
|
84 | 93 | hub_df |> |
|
0 commit comments