diff --git a/.gitignore b/.gitignore index 802b1ab3c..9cc7438bc 100644 --- a/.gitignore +++ b/.gitignore @@ -31,4 +31,5 @@ op.csv covs.csv error_theta.csv lcov.info -Fortran/ \ No newline at end of file +Fortran/ +result.json diff --git a/examples/bimodal_ke/main.rs b/examples/bimodal_ke/main.rs index bbd92febe..939add61b 100644 --- a/examples/bimodal_ke/main.rs +++ b/examples/bimodal_ke/main.rs @@ -50,6 +50,7 @@ fn main() -> Result<()> { let mut algorithm = dispatch_algorithm(settings, eq, data)?; let mut result = algorithm.fit()?; result.write_outputs()?; + result.write_json()?; Ok(()) } diff --git a/src/routines/output/mod.rs b/src/routines/output/mod.rs index 2a9e43d69..5eb5b9f90 100644 --- a/src/routines/output/mod.rs +++ b/src/routines/output/mod.rs @@ -436,7 +436,22 @@ impl NPResult { Ok(()) } - /// Writes the covariates + /// Writes the entire NPResult to a JSON file + /// + /// This will not calculate predictions automatically, to do so, call [NPResult::calculate_predictions] first + pub fn write_json(&mut self) -> Result<()> { + tracing::debug!("Writing NPResult to JSON..."); + + let outputfile = OutputFile::new(&self.settings.output().path, "result.json") + .context("Failed to create output file for JSON")?; + + serde_json::to_writer_pretty(&outputfile.file, self) + .context("Failed to serialize NPResult to JSON")?; + + tracing::debug!("NPResult written to {:?}", &outputfile.relative_path()); + Ok(()) + } + pub fn write_covs(&self) -> Result<()> { tracing::debug!("Writing covariates..."); let outputfile = OutputFile::new(&self.settings.output().path, "covs.csv")?;