Skip to content

Commit 0cd9403

Browse files
committed
refactor(process_replications): change to more informative name get_run_results() + lint + rerun (off charge so slower)
1 parent a16eb55 commit 0cd9403

18 files changed

+85
-66
lines changed

NAMESPACE

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# Generated by roxygen2: do not edit by hand
22

33
export(confidence_interval_method)
4+
export(get_run_results)
45
export(model)
56
export(parameters)
6-
export(process_replications)
77
export(run_scenarios)
88
export(runner)
99
export(valid_inputs)
@@ -36,6 +36,7 @@ importFrom(simmer,add_generator)
3636
importFrom(simmer,add_resource)
3737
importFrom(simmer,get_mon_arrivals)
3838
importFrom(simmer,get_mon_resources)
39+
importFrom(simmer,now)
3940
importFrom(simmer,release)
4041
importFrom(simmer,run)
4142
importFrom(simmer,seize)

R/choose_replications.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ confidence_interval_method <- function(replications, desired_precision, metric,
2121
# Run model for specified number of replications
2222
param <- parameters(number_of_runs = replications)
2323
raw_results <- runner(param)
24-
results <- process_replications(raw_results)
24+
results <- get_run_results(raw_results)
2525

2626
# If mean of metric is less than 1, multiply by 100
2727
if (mean(results[[metric]]) < 1L) {
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#' Process results from each replication.
1+
#' Get results from each replication.
22
#'
33
#' For each replication (there can be one or many), calculate the: (1) number
44
#' of arrivals, (2) mean wait time for each resource, (3) mean activity time
@@ -22,14 +22,14 @@
2222
#' @importFrom dplyr group_by summarise n_distinct mutate lead full_join
2323
#' @importFrom purrr reduce
2424
#' @importFrom rlang .data
25-
#' @importFrom simmer get_mon_resources get_mon_arrivals
25+
#' @importFrom simmer get_mon_resources get_mon_arrivals now
2626
#' @importFrom tidyr pivot_wider drop_na
2727
#' @importFrom tidyselect any_of
2828
#'
2929
#' @return Tibble with results from each replication.
3030
#' @export
3131

32-
process_replications <- function(results) {
32+
get_run_results <- function(results) {
3333

3434
# Remove patients who were still waiting and had not completed
3535
results[["arrivals"]] <- results[["arrivals"]] %>%

R/runner.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ runner <- function(param) {
3636

3737
# Combine the results from multiple replications into just two dataframes
3838
if (param[["number_of_runs"]] == 1L) {
39-
results <- results[[1]]
39+
results <- results[[1L]]
4040
} else {
4141
all_arrivals <- do.call(
4242
rbind, lapply(results, function(x) x[["arrivals"]])

R/scenarios.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ run_scenarios <- function(scenarios, base_list) {
4242

4343
# Run replications for the current scenario and process results
4444
raw_results <- runner(param)
45-
scenario_result <- process_replications(raw_results)
45+
scenario_result <- get_run_results(raw_results)
4646

4747
# Append scenario parameters to the results
4848
scenario_result[["scenario"]] <- index
Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

outputs/cores1.png

-2.2 KB
Loading

outputs/cores2.png

2.89 KB
Loading

rmarkdown/analysis.Rmd

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ The run time is provided at the end of the notebook.
2323
Install the latest version of the local simulation package.
2424

2525
```{r}
26-
# devtools::install()
2726
devtools::load_all()
2827
```
2928

@@ -66,7 +65,7 @@ raw_results <- runner(param = parameters())
6665
Process results and save to `.csv`.
6766

6867
```{r}
69-
run_results <- process_replications(raw_results)
68+
run_results <- get_run_results(raw_results)
7069
head(run_results)
7170
7271
write.csv(run_results, file.path(output_dir, "base_run_results.csv"))

rmarkdown/analysis.md

Lines changed: 45 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ The run time is provided at the end of the notebook.
3737
Install the latest version of the local simulation package.
3838

3939
``` r
40-
# devtools::install()
4140
devtools::load_all()
4241
```
4342

@@ -82,7 +81,7 @@ raw_results <- runner(param = parameters())
8281
Process results and save to `.csv`.
8382

8483
``` r
85-
run_results <- process_replications(raw_results)
84+
run_results <- get_run_results(raw_results)
8685
head(run_results)
8786
```
8887

@@ -348,7 +347,7 @@ print(table_latex)
348347
```
349348

350349
## % latex table generated in R 4.4.1 by xtable 1.8-4 package
351-
## % Tue Mar 4 15:30:46 2025
350+
## % Tue Mar 4 15:50:08 2025
352351
## \begin{table}[ht]
353352
## \centering
354353
## \begin{tabular}{rrllll}
@@ -574,7 +573,7 @@ print(sensitivity_table_latex)
574573
```
575574

576575
## % latex table generated in R 4.4.1 by xtable 1.8-4 package
577-
## % Tue Mar 4 15:30:53 2025
576+
## % Tue Mar 4 15:50:24 2025
578577
## \begin{table}[ht]
579578
## \centering
580579
## \begin{tabular}{rrl}
@@ -615,12 +614,19 @@ tail(result[["arrivals"]])
615614
```
616615

617616
## name start_time end_time activity_time resource replication
618-
## 160 patient156 77.59569 NA NA nurse 0
619-
## 161 patient109 53.05827 NA NA nurse 0
620-
## 162 patient157 77.98085 NA NA nurse 0
621-
## 163 patient158 78.34954 NA NA nurse 0
622-
## 164 patient64 34.31794 NA NA nurse 0
623-
## 165 patient159 78.37804 NA NA nurse 0
617+
## 160 patient148 74.24750 NA NA nurse 0
618+
## 161 patient151 75.76834 NA NA nurse 0
619+
## 162 patient153 76.74319 NA NA nurse 0
620+
## 163 patient159 78.37804 NA NA nurse 0
621+
## 164 patient43 20.56980 NA NA nurse 0
622+
## 165 patient160 78.41585 NA NA nurse 0
623+
## q_time_unseen
624+
## 160 5.752504
625+
## 161 4.231663
626+
## 162 3.256809
627+
## 163 1.621961
628+
## 164 59.430201
629+
## 165 1.584149
624630

625631
## Example run with logs
626632

@@ -863,6 +869,34 @@ verbose_run[["arrivals"]]
863869
## 25 patient26 99.0189155 NA NA nurse 0
864870
## 26 patient24 84.4587897 NA NA nurse 0
865871
## 27 patient23 82.4020925 NA NA nurse 0
872+
## q_time_unseen
873+
## 1 NA
874+
## 2 NA
875+
## 3 NA
876+
## 4 NA
877+
## 5 NA
878+
## 6 NA
879+
## 7 NA
880+
## 8 NA
881+
## 9 NA
882+
## 10 NA
883+
## 11 NA
884+
## 12 NA
885+
## 13 NA
886+
## 14 NA
887+
## 15 NA
888+
## 16 NA
889+
## 17 NA
890+
## 18 NA
891+
## 19 NA
892+
## 20 NA
893+
## 21 NA
894+
## 22 NA
895+
## 23 NA
896+
## 24 NA
897+
## 25 0.9810845
898+
## 26 15.5412103
899+
## 27 17.5979075
866900

867901
## Calculate run time
868902

@@ -877,4 +911,4 @@ seconds <- as.integer(runtime %% 60L)
877911
print(sprintf("Notebook run time: %dm %ds", minutes, seconds))
878912
```
879913

880-
## [1] "Notebook run time: 0m 19s"
914+
## [1] "Notebook run time: 0m 43s"

0 commit comments

Comments
 (0)