Skip to content

Commit

Permalink
Added two reports examples
Browse files Browse the repository at this point in the history
  • Loading branch information
k88hudson-cfa committed Aug 20, 2024
1 parent ff973ea commit b2b5921
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 0 deletions.
3 changes: 3 additions & 0 deletions examples/reports-multi-threaded/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Reports - Multi-Threaded Scenarios

This example demonstrates report writing for several scenarios running in parallel.
24 changes: 24 additions & 0 deletions examples/reports-multi-threaded/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
use ixa::context::Context;
use std::thread;

fn main() {
let scenarios = vec!["Illinois", "Wisconsin", "Arizona", "California"];
let mut handles = vec![];

for scenario in scenarios {
let scenario = scenario.to_string();
let handle = thread::spawn(move || {
// Replace this with the actual example code, similar to the simple
// example in examples/reports/main.rs
let mut context = Context::new();
println!("Scenario: {}", scenario);

context.execute();
});
handles.push(handle);
}

for handle in handles {
handle.join().unwrap();
}
}
4 changes: 4 additions & 0 deletions examples/reports/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Reports - Simple Example

This example demonstrates creating two types of reports (incidence and death),
and writing the reports from plans.
33 changes: 33 additions & 0 deletions examples/reports/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
fn main() {}

#[cfg(feature = "reports")]
fn main() {
struct Incidence {
person_id: u32,
t: f64,
}
struct Death {
person_id: u32,
t: f64,
}

let mut context = ixa::context::Context::new();
context.add_report::<Incidence>("incidence");
context.add_report::<Death>("death");

context.add_plan(1.0, |context| {
context.send_report(Incidence {
person_id: 1,
t: context.get_current_time(),
});
});

context.add_plan(2.0, |context| {
context.send_report(Death {
person_id: 1,
t: context.get_current_time(),
});
});

context.execute();
}

0 comments on commit b2b5921

Please sign in to comment.