Skip to content
Snippets Groups Projects
Commit d995182c authored by Oliver Charles Schubert's avatar Oliver Charles Schubert
Browse files

Adds functionality to print results as .html file.

parent 0a290207
Branches
No related tags found
No related merge requests found
......@@ -5,7 +5,6 @@
<file_name Desc="Name" Unit="-" Default="">newFormat-CSMR-2020.xml</file_name>
<design_directory Desc="Path" Unit="-" Default="">./test-upstream-files/</design_directory>
</aircraft_design>
<other_aircraft_designs Desc="Further designs to be compared against the reference (IODir/IOFileName)">1</other_aircraft_designs>
<aircraft_design ID="1">
<name Desc="Name" Unit="-" Default="">CSR nr1</name>
<file_name Desc="Name" Unit="-" Default="">newFormat-CSMR-2020_0.xml</file_name>
......@@ -24,8 +23,9 @@
</program_settings>
<parameters Desc="parameters to be compared">
<something>
<sub_path ID="1" Name="MTOM">analysis/masses_cg_inertia/maximum_takeoff_mass/mass_properties/mass/value</sub_path>
<sub_path ID="0" Name="MTOM">analysis/masses_cg_inertia/maximum_takeoff_mass/mass_properties/mass/value</sub_path>
</something>
<sub_path ID="1" Name="Moment of Inertia">analysis/masses_cg_inertia/maximum_takeoff_mass/mass_properties/inertia/j_xx/value</sub_path>
<sub_path ID="2" Name="OME">analysis/masses_cg_inertia/operating_mass_empty/mass_properties/mass/value</sub_path>
<sub_path ID="3" Name="Some Name">requirements_and_specifications/design_specification/propulsion/propulsor@1/energy_carrier_ID/value</sub_path>
<sub_path ID="4" Name="Another Name">requirements_and_specifications/design_specification/propulsion/propulsor@123/energy_carrier_ID/value</sub_path>
......
......@@ -3,6 +3,17 @@
#include <boost/property_tree/xml_parser.hpp>
#include <boost/property_tree/ptree.hpp>
// Function to remove a substring from the end of a string
std::string substractStringFromEnd(const std::string& string, const std::string& string_to_substract) {
if (string.size() >= string_to_substract.size() &&
string.compare(string.size() - string_to_substract.size(), string_to_substract.size(), string_to_substract) == 0) {
// If the string ends with the substring, remove it
return string.substr(0, string.size() - string_to_substract.size());
}
// Otherwise, return the original string unchanged
return string;
}
void printPtree(const boost::property_tree::ptree &tree, const std::string &prefix = "") {
for (const auto &node : tree) {
// Print current node name
......@@ -238,6 +249,7 @@ int main () {
std::string node_path{"aircraft_exchange_file/" + node.second.data()};
double upstream_value{NAN};
double local_value{NAN};
std::string unit{"?"};
if (containsSymbol(node_path, "@")) {
std::string pre{node_path.substr(0, node_path.find_first_of('@'))};
......@@ -248,18 +260,22 @@ int main () {
boost::property_tree::ptree temp_upstream_tree{GetSubtreeByAttributevalue(aircraft_design_trees.at(0), pre, "ID", attribute_value)};
boost::property_tree::ptree temp_local_tree{GetSubtreeByAttributevalue(tree, pre, "ID", attribute_value)};
boost::property_tree::ptree temp_unit_tree{GetSubtreeByAttributevalue(tree, pre, "ID", attribute_value)};
upstream_value = temp_upstream_tree.get<double>(boost::property_tree::ptree::path_type(post, '/'));
local_value = temp_local_tree.get<double>(boost::property_tree::ptree::path_type(post, '/'));
unit = temp_unit_tree.get<std::string>(boost::property_tree::ptree::path_type(substractStringFromEnd(post, "value") + "unit", '/'));
} else {
upstream_value = aircraft_design_trees.at(0).get<double>(boost::property_tree::ptree::path_type(node_path, '/'));
local_value = tree.get<double>(boost::property_tree::ptree::path_type(node_path, '/'));
unit = tree.get<std::string>(boost::property_tree::ptree::path_type(substractStringFromEnd(node_path, "value") + "unit", '/'));
}
temp_tree.put(node.second.get<std::string>("<xmlattr>.Name"), upstream_value - local_value);
temp_tree.put(node.second.get<std::string>("<xmlattr>.Name") + ".<xmlattr>.unit", unit);
}
result_tree.push_back(temp_tree);
}
}
}
catch(const std::exception& e)
{
......@@ -278,24 +294,57 @@ int main () {
std::cout << "Current State: " << state << std::endl;
// Write Output
// Create header
boost::property_tree::ptree output_tree{};
output_tree.put("html.<xmlattr>.lang", "en");
output_tree.put("html.head.meta.<xmlattr>.content", "width=device-width, initial-scale=1.0");
output_tree.put("html.head.meta.<xmlattr>.name", "viewport");
output_tree.put("html.head.meta.<xmlattr>.charset", "utf-8");
output_tree.put("html.head.title", "<probably same as report name>");
output_tree.put("html.head.link.<xmlattr>.href", "style.css");
output_tree.put("html.head.link.<xmlattr>.rel", "stylesheet");
// Create body
boost::property_tree::ptree temp_tree{};
temp_tree.put("<xmlattr>.class", "content");
temp_tree.put("h1", "Report - <some name>");
temp_tree.put("div.<xmlattr>.class", "container");
// Create data tables
unsigned int aircraft_counter{0};
for (const auto& tree : result_tree) {
printPtree(tree);
++aircraft_counter;
boost::property_tree::ptree data_tree{};
data_tree.put("<xmlattr>.class", "box data");
boost::property_tree::ptree my_tree{GetSubtreeByAttributevalue(program_settings_tree, "aircraft_design", "ID", std::to_string(aircraft_counter))};
std::string myString{my_tree.get<std::string>("name")};
data_tree.put("h2", myString);
data_tree.put("table.<xmlattr>.class", "content-table");
data_tree.put("table.caption", "Residual Values");
data_tree.put("table.thead", "");
data_tree.put("table.tbody", "");
boost::property_tree::ptree thead{};
thead.add_child("th", boost::property_tree::ptree{"paramter"});
// thead.add_child("th", boost::property_tree::ptree{"symbol"});
thead.add_child("th", boost::property_tree::ptree{"value"});
thead.add_child("th", boost::property_tree::ptree{"unit"});
data_tree.add_child("table.thead.tr", thead);
for (const auto& node : tree) {
boost::property_tree::ptree tbody{};
tbody.add_child("td", boost::property_tree::ptree{node.first});
tbody.add_child("td", boost::property_tree::ptree{node.second.data()});
tbody.add_child("td", boost::property_tree::ptree{node.second.get<std::string>("<xmlattr>.unit")});
data_tree.add_child("table.tbody.tr", tbody);
}
temp_tree.add_child("div.div", data_tree);
}
// Questions:
// - Name of the dispalyed value? ANS: from config file
// Curretnly form config file, but if from acft_ex_file name will always be "value"
//
// - Output format? ANS: .html format
// - Where to get the file directories from? ANS: from config file program settings
// Next steps:
// - read file locations from config.xml
// - output as .html
// - multiple file comparisons
output_tree.add_child("html.body.div", temp_tree);
// Write .html file
boost::property_tree::xml_writer_settings<std::string> settings(' ', 4); // 4 spaces for indentation
boost::property_tree::write_xml("./projects/reporting/reportHTML/ReportXYZ.html",
output_tree,
std::locale(),
settings);
state = State::ProgrammFinished;
break;
......@@ -308,8 +357,21 @@ int main () {
}
default: {
// TODO(Oli): check why when nodes have the same name only one is printed in the result_tree
// Questions:
// where are filepath of output.html and config.xml specified?
break;
}
}
}
}
\ No newline at end of file
}
/*
for (auto element : result_tree) {
std::cout << "TREE: " << std::endl;
printPtree(element);
std::cout << std::endl;
}
*/
\ No newline at end of file
......@@ -794,7 +794,7 @@
<mass_properties description="maximum takeoff mass properties">
<inertia description="Inertia with regard to the total center of gravity.">
<j_xx description="Inertia in x.">
<value>1510141.8121567257</value>
<value>1500000</value>
<unit>kgm^2</unit>
<lower_boundary>-inf</lower_boundary>
<upper_boundary>inf</upper_boundary>
......@@ -869,7 +869,7 @@
</z>
</center_of_gravity>
<mass description="Mass">
<value>0</value>
<value>77777</value>
<unit>kg</unit>
<lower_boundary>0</lower_boundary>
<upper_boundary>inf</upper_boundary>
......@@ -955,7 +955,7 @@
</z>
</center_of_gravity>
<mass description="Mass">
<value>0</value>
<value>3456</value>
<unit>kg</unit>
<lower_boundary>0</lower_boundary>
<upper_boundary>inf</upper_boundary>
......
......@@ -794,7 +794,7 @@
<mass_properties description="maximum takeoff mass properties">
<inertia description="Inertia with regard to the total center of gravity.">
<j_xx description="Inertia in x.">
<value>1510141.8121567257</value>
<value>1400000</value>
<unit>kgm^2</unit>
<lower_boundary>-inf</lower_boundary>
<upper_boundary>inf</upper_boundary>
......@@ -869,7 +869,7 @@
</z>
</center_of_gravity>
<mass description="Mass">
<value>0</value>
<value>345345</value>
<unit>kg</unit>
<lower_boundary>0</lower_boundary>
<upper_boundary>inf</upper_boundary>
......@@ -955,7 +955,7 @@
</z>
</center_of_gravity>
<mass description="Mass">
<value>0</value>
<value>756756</value>
<unit>kg</unit>
<lower_boundary>0</lower_boundary>
<upper_boundary>inf</upper_boundary>
......
......@@ -794,7 +794,7 @@
<mass_properties description="maximum takeoff mass properties">
<inertia description="Inertia with regard to the total center of gravity.">
<j_xx description="Inertia in x.">
<value>1510141.8121567257</value>
<value>1510141.0</value>
<unit>kgm^2</unit>
<lower_boundary>-inf</lower_boundary>
<upper_boundary>inf</upper_boundary>
......@@ -869,7 +869,7 @@
</z>
</center_of_gravity>
<mass description="Mass">
<value>0</value>
<value>3209</value>
<unit>kg</unit>
<lower_boundary>0</lower_boundary>
<upper_boundary>inf</upper_boundary>
......
Source diff could not be displayed: it is too large. Options to address this: view the blob.
<?xml version="1.0" encoding="utf-8"?>
<html lang="en">
<head>
<meta content="width=device-width, initial-scale=1.0" name="viewport" charset="utf-8"/>
<title>&lt;probably same as report name&gt;</title>
<link href="style.css" rel="stylesheet"/>
</head>
<body>
<div class="content">
<h1>Report - &lt;some name&gt;</h1>
<div class="container">
<div class="box data">
<h2>CSR nr1</h2>
<table class="content-table">
<caption>Residual Values</caption>
<thead>
<tr>
<th>paramter</th>
<th>value</th>
<th>unit</th>
</tr>
</thead>
<tbody>
<tr>
<td>MTOM</td>
<td>1223.25</td>
<td>kg</td>
</tr>
<tr>
<td>Moment of Inertia</td>
<td>0.80000000004656613</td>
<td>kgm^2</td>
</tr>
<tr>
<td>OME</td>
<td>39544.5</td>
<td>kg</td>
</tr>
<tr>
<td>Some Name</td>
<td>-888</td>
<td>1</td>
</tr>
<tr>
<td>Another Name</td>
<td>-999</td>
<td>1</td>
</tr>
</tbody>
</table>
</div>
<div class="box data">
<h2>CSR nr2</h2>
<table class="content-table">
<caption>Residual Values</caption>
<thead>
<tr>
<th>paramter</th>
<th>value</th>
<th>unit</th>
</tr>
</thead>
<tbody>
<tr>
<td>MTOM</td>
<td>-266344.75</td>
<td>kg</td>
</tr>
<tr>
<td>Moment of Inertia</td>
<td>100000.80000000005</td>
<td>kgm^2</td>
</tr>
<tr>
<td>OME</td>
<td>-713755.5</td>
<td>kg</td>
</tr>
<tr>
<td>Some Name</td>
<td>-888</td>
<td>1</td>
</tr>
<tr>
<td>Another Name</td>
<td>-123</td>
<td>1</td>
</tr>
</tbody>
</table>
</div>
<div class="box data">
<h2>CSR nr3</h2>
<table class="content-table">
<caption>Residual Values</caption>
<thead>
<tr>
<th>paramter</th>
<th>value</th>
<th>unit</th>
</tr>
</thead>
<tbody>
<tr>
<td>MTOM</td>
<td>75791.25</td>
<td>kg</td>
</tr>
<tr>
<td>Moment of Inertia</td>
<td>-10140.199999999953</td>
<td>kgm^2</td>
</tr>
<tr>
<td>OME</td>
<td>43000.5</td>
<td>kg</td>
</tr>
<tr>
<td>Some Name</td>
<td>-888</td>
<td>1</td>
</tr>
<tr>
<td>Another Name</td>
<td>-9999</td>
<td>1</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</body>
</html>
*, *:before, *:after {
margin: 0;
padding: 0;
box-sizing: border-box;
}
html, body {
background-color: #2a2d33;
font-family: system-ui, sans-serif;
font-size: 1.3rem;
color: #2c3e50;
line-height: 1.3;
background-size: cover;
}
table {
margin-left: 0;
margin-right: auto;
}
.logo {
background-image: url('logoUNICADO_icon.svg');
height: 75vh;
width: 100%;
opacity: 0.2;
filter: grayscale(100%);
background-size: contain;
background-repeat: no-repeat;
background-position: center center;
position: relative center;
}
.content {
position: absolute;
width: 98%;
height: 85%;
top: 0rem;
left: 1rem;
padding-left: 0rem;
box-sizing: border-box;
min-width: fit-content;
}
.content h1 {
color: #ecf0f1;
margin: 1rem 0.1rem;
font-size: 2.7rem;
font-weight: lighter;
font-variant: small-caps;
}
.container {
position: absolute;
display: flex;
width: 100%;
height: 100%;
}
.box {
width: 50%;
overflow-y: auto;
overflow-x: auto;
scrollbar-width: none;
scrollbar-color: #f0f0f0 #f0f0f0;
padding: 0;
margin-right: 0.2rem;
background-color: #ecf0f1;
box-shadow: 5px 5px 5px black;
border-radius: 0.5rem;
min-width: fit-content;
text-align: center;
}
.data {
background-color: #ecf0f1;
padding: auto;
min-width: fit-content;
max-width: 50%;
}
.plot {
background-color: #ecf0f1;
text-align: center;
max-width: 50%;
}
.box h2 {
margin-left: 0.5rem;
font-weight: normal;
font-variant: small-caps;
font-size: 1.5rem;
text-align: left;
}
.box h3 {
margin-left: 0.5rem;
font-weight: normal;
font-variant: small-caps;
font-size: 1.2rem;
text-align: left;
}
.box h4 {
margin-left: 0.5rem;
font-weight: normal;
font-variant: small-caps;
font-size: 1.0rem;
text-align: left;
}
.box ul {
list-style-type: disc;
margin-left: 0rem;
padding-left: 2rem;
text-align: left;
}
.box ul li {
margin: 0 0 0 0;
padding-left: 0;
font-size: 0.9rem;
font-weight: lighter;
}
.content-table {
margin-left: 2rem;
padding: 0.50rem;
font-size:0.9rem;
flex-basis: 100rem;
font-weight: lighter;
padding-bottom: 2rem;
}
.content-table caption {
text-align: left;
font-weight:600;
font-size: larger;
font-variant: small-caps;
}
.content-table th {
text-align: left;
padding-right: 1rem;
white-space: nowrap;
min-width: 3rem;
font-weight: normal;
}
.content-table td {
padding-right: 1rem;
text-align: left;
}
.content-table td.row-header {
font-weight: normal;
text-align: left;
padding-right: 0.5rem;
}
.content-table td.content-data-number {
text-align: right;
}
.content-table tbody tr:hover {
color: #ee5253;
cursor: pointer;
}
.plot img.image-plot {
min-width: none;
width: 90%;
color: #ecf0f1;
}
......@@ -794,7 +794,7 @@
<mass_properties description="maximum takeoff mass properties">
<inertia description="Inertia with regard to the total center of gravity.">
<j_xx description="Inertia in x.">
<value>1510141.8121567257</value>
<value>1500000.80</value>
<unit>kgm^2</unit>
<lower_boundary>-inf</lower_boundary>
<upper_boundary>inf</upper_boundary>
......@@ -869,7 +869,7 @@
</z>
</center_of_gravity>
<mass description="Mass">
<value>79002.14738244547</value>
<value>79000.25</value>
<unit>kg</unit>
<lower_boundary>0</lower_boundary>
<upper_boundary>inf</upper_boundary>
......@@ -955,7 +955,7 @@
</z>
</center_of_gravity>
<mass description="Mass">
<value>42929.835124</value>
<value>43000.50</value>
<unit>kg</unit>
<lower_boundary>0</lower_boundary>
<upper_boundary>inf</upper_boundary>
......
Source diff could not be displayed: it is too large. Options to address this: view the blob.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment