Skip to content

Commit 4eefbae

Browse files
committed
Include information about program run in metadata
1 parent 0f089e6 commit 4eefbae

3 files changed

Lines changed: 35 additions & 10 deletions

File tree

src/output.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -236,9 +236,10 @@ impl DataWriter {
236236
/// # Arguments
237237
///
238238
/// * `output_path` - Folder where files will be saved
239+
/// * `model_path` - Path to input model
239240
/// * `save_debug_info` - Whether to include extra CSV files for debugging model
240-
pub fn create(output_path: &Path, save_debug_info: bool) -> Result<Self> {
241-
write_metadata(output_path).context("Failed to save metadata")?;
241+
pub fn create(output_path: &Path, model_path: &Path, save_debug_info: bool) -> Result<Self> {
242+
write_metadata(output_path, model_path).context("Failed to save metadata")?;
242243

243244
let new_writer = |file_name| {
244245
let file_path = output_path.join(file_name);
@@ -345,7 +346,7 @@ mod tests {
345346

346347
// Write an asset
347348
{
348-
let mut writer = DataWriter::create(dir.path(), false).unwrap();
349+
let mut writer = DataWriter::create(dir.path(), dir.path(), false).unwrap();
349350
writer.write_assets(milestone_year, assets.iter()).unwrap();
350351
writer.flush().unwrap();
351352
}
@@ -372,7 +373,7 @@ mod tests {
372373
// Write a flow
373374
let dir = tempdir().unwrap();
374375
{
375-
let mut writer = DataWriter::create(dir.path(), false).unwrap();
376+
let mut writer = DataWriter::create(dir.path(), dir.path(), false).unwrap();
376377
writer.write_flows(milestone_year, &flow_map).unwrap();
377378
writer.flush().unwrap();
378379
}
@@ -403,7 +404,7 @@ mod tests {
403404

404405
// Write a price
405406
{
406-
let mut writer = DataWriter::create(dir.path(), false).unwrap();
407+
let mut writer = DataWriter::create(dir.path(), dir.path(), false).unwrap();
407408
writer.write_prices(milestone_year, &prices).unwrap();
408409
writer.flush().unwrap();
409410
}

src/output/metadata.rs

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
//! Code for writing metadata to file
22
use anyhow::Result;
3+
use chrono::prelude::*;
34
use platform_info::{PlatformInfo, PlatformInfoAPI, UNameAPI};
45
use serde::Serialize;
56
use std::fs;
@@ -27,13 +28,32 @@ fn get_git_hash() -> String {
2728
}
2829
}
2930

30-
#[derive(Serialize, Default)]
31+
#[derive(Serialize)]
3132
struct Metadata<'a> {
33+
run: RunMetadata<'a>,
3234
program: ProgramMetadata<'a>,
3335
platform: PlatformMetadata,
3436
}
3537

36-
/// Information about the version and build of MUSE
38+
/// Information about the model run
39+
#[derive(Serialize)]
40+
struct RunMetadata<'a> {
41+
/// Path to the model which was run
42+
model_path: &'a Path,
43+
/// The date and time on which the run started
44+
datetime: String,
45+
}
46+
47+
impl<'a> RunMetadata<'a> {
48+
fn new(model_path: &'a Path) -> Self {
49+
let dt = Local::now();
50+
Self {
51+
model_path,
52+
datetime: dt.to_rfc2822(),
53+
}
54+
}
55+
}
56+
3757
#[derive(Serialize)]
3858
struct ProgramMetadata<'a> {
3959
/// The program name
@@ -94,8 +114,12 @@ impl Default for PlatformMetadata {
94114
}
95115

96116
/// Write metadata to the specified output path in TOML format
97-
pub fn write_metadata(output_path: &Path) -> Result<()> {
98-
let metadata = Metadata::default();
117+
pub fn write_metadata(output_path: &Path, model_path: &Path) -> Result<()> {
118+
let metadata = Metadata {
119+
run: RunMetadata::new(model_path),
120+
program: ProgramMetadata::default(),
121+
platform: PlatformMetadata::default(),
122+
};
99123
let file_path = output_path.join(METADATA_FILE_NAME);
100124
fs::write(&file_path, toml::to_string(&metadata)?)?;
101125

src/simulation.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ pub fn run(
2727
output_path: &Path,
2828
debug_model: bool,
2929
) -> Result<()> {
30-
let mut writer = DataWriter::create(output_path, debug_model)?;
30+
let mut writer = DataWriter::create(output_path, &model.model_path, debug_model)?;
3131

3232
// Iterate over milestone years
3333
let mut year_iter = model.iter_years();

0 commit comments

Comments
 (0)