1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
//! Provides functions to set up and update a progress bar.
//!
//! A progress bar has a label, a maximum progress value, and its current progress, which
//! starts at zero. The maximum and current progress values are constrained to be of type
//! `usize`. However, convenience methods are provided for the common case of a progress bar
//! for the timeline that take `f64` time values and rounds them to nearest integers for you.
//!
//! Only one progress bar can be active at a time. If you try to set a second progress bar, the
//! new progress bar will replace this first. This is useful if you want to track the progress
//! of a simulation in multiple phases. Keep in mind, however, that if you define a timeline
//! progress bar, the `Context` will try to update it in its event loop with the current time,
//! which might not be what you want if you have replaced the progress bar with a new one.
//!
//! # Timeline Progress Bar
//!
//! ```ignore
//! /// Initialize the progress bar with the maximum time until the simulation ends.
//! pub fn init_timeline_progress_bar(max_time: f64);
//! /// Updates the progress bar with the current time. Finalizes the progress bar when
//! /// `current_time >= max_time`.
//! pub fn update_timeline_progress(mut current_time: f64);
//! ```
//!
//! # Custom Progress Bar
//!
//! If the timeline is not a good indication of progress for your simulation, you can set up a
//! custom progress bar.
//!
//! ```ignore
//! /// Initializes a custom progress bar with the given label and max value.
//! pub fn init_custom_progress_bar(label: &str, max_value: usize);
//!
//! /// Updates the current value of the custom progress bar.
//! pub fn update_custom_progress(current_value: usize);
//!
//! /// Increments the custom progress bar by 1. Use this if you don't want to keep track of the
//! /// current value.
//! pub fn increment_custom_progress()
//! ```
//!
//! # Custom Example: People Infected
//!
//! Suppose you want a progress bar that tracks how much of the population has been infected (or
//! infected and then recovered). You first initialize a custom progress bar before executing
//! the simulation.
//!
//! ```ignore
//! use crate::progress_bar::{init_custom_progress_bar};
//!
//! init_custom_progress_bar("People Infected", POPULATION_SIZE);
//! ```
//!
//! To update the progress bar, we need to listen to the infection status property change event.
//!
//! ```ignore
//! use crate::progress_bar::{increment_custom_progress};
//!
//! // You might already have this event defined for other purposes.
//! pub type InfectionStatusEvent = PersonPropertyChangeEvent<InfectionStatus>;
//!
//! // This will handle the status change event, updating the progress bar
//! // if there is a new infection.
//! fn handle_infection_status_change(context: &mut Context, event: InfectionStatusEvent) {
//! // We only increment the progress bar when a new infection occurs.
//! if (InfectionStatusValue::Susceptible, InfectionStatusValue::Infected)
//! == (event.previous, event.current)
//! {
//! increment_custom_progress();
//! }
//! }
//!
//! // Be sure to subscribe to the event when you initialize the context.
//! pub fn init(context: &mut Context) -> Result<(), IxaError> {
//! // ... other initialization code ...
//! context.subscribe_to_event::<InfectionStatusEvent>(handle_infection_status_change);
//! // ...
//! Ok(())
//! }
//! ```
//!
// Requires at least rustc@1.70
use OnceLock;
use ;
use crate;
/// We want to store the original `f64` max value, not the `usize` we initialized the progress
/// bar with.
pub static MAX_TIME: = new;
/// Initialize the progress bar with the maximum time until the simulation ends.
/// Updates the timeline progress bar with the current time.
pub
/// Initializes a custom progress bar with the given label and max value.
///
/// Note: If you attempt to set two progress bars, the second progress bar will replace the first.
/// Updates the current value of the custom progress bar.
/// Increments the custom progress bar by 1. Use this if you don't want to keep track of the
/// current value.