Skip to content
Snippets Groups Projects
Commit 432f440c authored by Udo Eisenbarth's avatar Udo Eisenbarth :speech_balloon:
Browse files

refactor: Cleanup AnalysisReport and NodeReport.

parent 557c1541
No related branches found
No related tags found
No related merge requests found
......@@ -2,7 +2,7 @@
<div class="col">
<div class="card">
<div class="card-header">
<span class="h5">{node}</span> <small class="muted">{node_type}</small>
<span class="h5">{node_name}</span> <small class="muted">{node_type}</small>
</div>
<div class="card-body">
<table class="table table-sm table-bordered">
......
......@@ -329,7 +329,7 @@ impl NodeGroup {
info!("toplevel report data for node {node_name}");
let uuid = node.uuid().as_simple().to_string();
if let Some(node_report) = node.optical_ref.borrow().report(&uuid) {
analysis_report.add_detector(node_report);
analysis_report.add_node_report(node_report);
}
}
Ok(analysis_report)
......
......@@ -11,7 +11,7 @@ use serde::{Deserialize, Serialize};
use std::collections::BTreeMap;
use std::fmt::Debug;
use self::property::HtmlProperty;
use crate::reporting::html_report::HtmlProperty;
/// A general set of (optical) properties.
///
......
......@@ -4,12 +4,7 @@ use plotters::coord::combinators::LogScalable;
use serde::{Deserialize, Serialize};
use std::mem;
#[derive(Serialize)]
pub struct HtmlProperty {
pub name: String,
pub description: String,
pub prop_value: String,
}
/// (optical) Property
///
/// A property consists of the actual value (stored as [`Proptype`]), a description and optionally a list of value conditions
......
......@@ -144,7 +144,7 @@ impl Proptype {
}
Self::NodeReport(report) => {
let html_node_report = HtmlNodeReport {
node: report.name().into(),
node_name: report.name().into(),
node_type: report.node_type().into(),
props: report.properties().html_props(report.name(), uuid),
uuid: uuid.to_string(),
......
......@@ -4,10 +4,7 @@ use log::info;
use serde::Serialize;
use tinytemplate::TinyTemplate;
use crate::{
error::{OpmResult, OpossumError},
properties::property::HtmlProperty,
};
use crate::error::{OpmResult, OpossumError};
static HTML_REPORT: &str = include_str!("../html/html_report.html");
static HTML_NODE_REPORT: &str = include_str!("../html/node_report.html");
......@@ -59,7 +56,7 @@ impl HtmlReport {
#[derive(Serialize)]
pub struct HtmlNodeReport {
/// node name
pub node: String,
pub node_name: String,
/// node type
pub node_type: String,
/// properties of the node
......@@ -67,3 +64,10 @@ pub struct HtmlNodeReport {
/// uuid of the node (needed for constructing filenames)
pub uuid: String,
}
#[derive(Serialize)]
pub struct HtmlProperty {
pub name: String,
pub description: String,
pub prop_value: String,
}
\ No newline at end of file
......@@ -2,7 +2,7 @@
//! Module handling analysis reports and converting them to HTML.
use crate::{
error::{OpmResult, OpossumError}, nodes::{ray_propagation_visualizer::RayPositionHistories, NodeGroup}, optic_node::OpticNode, properties::{Properties, Proptype}
error::{OpmResult, OpossumError}, nodes::NodeGroup, optic_node::OpticNode, properties::{Properties, Proptype}
};
use chrono::{DateTime, Local};
use serde::{Deserialize, Serialize};
......@@ -33,26 +33,15 @@ impl AnalysisReport {
pub fn add_scenery(&mut self, scenery: &NodeGroup) {
self.scenery = Some(scenery.clone());
}
/// Add an (detector) [`NodeReport`] to this [`AnalysisReport`].
/// Add a [`NodeReport`] to this [`AnalysisReport`].
///
/// After analysis of a [`NodeGroup`], each node can generate a [`NodeReport`] using the
/// [`report`](crate::optic_node::OpticNode::report) trait function. While assembling a report this
/// function adds the node data to it. This is mostly interesting for detector nodes which deliver
/// their particular analysis result.
pub fn add_detector(&mut self, report: NodeReport) {
pub fn add_node_report(&mut self, report: NodeReport) {
self.node_reports.push(report);
}
/// Returns the ray history for the first found [`RayPropagationVisualizer`](crate::nodes::RayPropagationVisualizer) in this [`AnalysisReport`].
/// **Note**: This function is only a hack for displaying rays in the bevy engine.
#[must_use]
pub fn get_ray_hist(&self) -> Option<&RayPositionHistories> {
for node in &self.node_reports {
if let Some(ray_hist) = node.get_ray_history() {
return Some(ray_hist);
}
}
None
}
/// Generate an [`HtmlReport`] from this [`AnalysisReport`].
///
/// # Errors
......@@ -114,36 +103,12 @@ impl NodeReport {
#[must_use]
pub fn to_html_node_report(&self) -> HtmlNodeReport {
HtmlNodeReport {
node: self.name.clone(),
node_name: self.name.clone(),
node_type: self.node_type.clone(),
props: self.properties.html_props(self.name(), &self.uuid),
uuid: self.uuid.clone(),
}
}
/// Returns the ray history of this [`NodeReport`] if it describe either a ray propagation
/// visualizer node or a group containing such a node. Otherwise the return value is `None`.
///
/// **Note**: This is a temporary function to be used in combination with the Bevy visualizer.
#[must_use]
pub fn get_ray_history(&self) -> Option<&RayPositionHistories> {
if self.node_type == "group" {
for prop in &self.properties {
if let Proptype::NodeReport(node) = prop.1.prop() {
let data = node.get_ray_history();
if data.is_some() {
return data;
}
}
}
} else if self.node_type == "ray propagation" {
if let Ok(Proptype::RayPositionHistory(ray_hist)) =
self.properties.get("Ray Propagation visualization plot")
{
return Some(ray_hist);
}
}
None
}
/// Returns a reference to the uuid of this [`NodeReport`].
#[must_use]
pub fn uuid(&self) -> &str {
......@@ -177,7 +142,7 @@ mod test {
#[test]
fn analysis_report_add_detector() {
let mut report = AnalysisReport::new(String::from("test"), DateTime::default());
report.add_detector(NodeReport::new(
report.add_node_report(NodeReport::new(
"test detector",
"detector name",
"123",
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment