|
1 | 1 | #' Rscript to generate texts for the visualization webpage |
2 | 2 | #' To run: |
3 | | -#' Rscript src/get_webtext.R --reference-date "2025-02-22" --base-hub-path "." |
4 | | -#' --hub-reports-path "../covidhub-reports" |
| 3 | +#' Rscript src/get_webtext.R --reference-date "2025-02-22" |
| 4 | +#' --hub-reports-path "../covidhub-reports" |
5 | 5 |
|
6 | 6 | parser <- argparser::arg_parser( |
7 | 7 | "Generate text for the webpage." |
@@ -171,27 +171,28 @@ reporting_rate_flag <- if (length(latest_reporting_below80$location_name) > 0) { |
171 | 171 | "" |
172 | 172 | } |
173 | 173 |
|
174 | | -format_statistical_values <- function(median, pi_lower, pi_upper) { |
175 | | - half_width <- abs(pi_upper - pi_lower) / 2 |
176 | | - digits <- -floor(log10(half_width)) |
177 | | - c( |
178 | | - median = round(median, digits = digits), |
179 | | - lower = round(pi_lower, digits = digits), |
180 | | - upper = round(pi_upper, digits = digits) |
181 | | - ) |
| 174 | +round_to_place <- function(value) { |
| 175 | + if (value >= 1000) { |
| 176 | + rounded_val <- round(value, -2) |
| 177 | + } else if (value >= 10) { |
| 178 | + rounded_val <- round(value, -1) |
| 179 | + } else { |
| 180 | + rounded_val <- round(value, 0) |
| 181 | + } |
| 182 | + return(rounded_val) |
182 | 183 | } |
183 | 184 |
|
184 | 185 | # generate variables used in the web text |
185 | | -forecast_1wk_ahead <- |
186 | | - format_statistical_values( |
187 | | - ensemble_us_1wk_ahead$quantile_0.5_count, |
188 | | - ensemble_us_1wk_ahead$quantile_0.025_count, |
189 | | - ensemble_us_1wk_ahead$quantile_0.975_count |
190 | | - ) |
191 | 186 |
|
192 | | -median_forecast_1wk_ahead <- forecast_1wk_ahead["median"] |
193 | | -lower_95ci_forecast_1wk_ahead <- forecast_1wk_ahead["lower"] |
194 | | -upper_95ci_forecast_1wk_ahead <- forecast_1wk_ahead["upper"] |
| 187 | +median_forecast_1wk_ahead <- round_to_place( |
| 188 | + ensemble_us_1wk_ahead$quantile_0.5_count |
| 189 | +) |
| 190 | +lower_95ci_forecast_1wk_ahead <- round_to_place( |
| 191 | + ensemble_us_1wk_ahead$quantile_0.025_count |
| 192 | +) |
| 193 | +upper_95ci_forecast_1wk_ahead <- round_to_place( |
| 194 | + ensemble_us_1wk_ahead$quantile_0.975_count |
| 195 | +) |
195 | 196 |
|
196 | 197 | designated <- wkly_submissions[wkly_submissions$designated_model, ] |
197 | 198 | not_designated <- wkly_submissions[!wkly_submissions$designated_model, ] |
|
0 commit comments