diff --git a/src/easyreflectometry/summary/html_templates.py b/src/easyreflectometry/summary/html_templates.py index a2299784..883c611f 100644 --- a/src/easyreflectometry/summary/html_templates.py +++ b/src/easyreflectometry/summary/html_templates.py @@ -2,67 +2,45 @@ - - - - - - - - - - - - - - - - - - - project_information_section - - - - - - - - - - - - sample_section - - - - - - - - - - - - experiments_section - - - - - - refinement_section - -

Summary

Sample

Experiments

- - - + + + + + + + + + + + project_information_section + + + + + + sample_section + + + + + + experiments_section + + + + + + refinement_section + +

Summary

Sample

Experiments

Refinement

+ """ @@ -71,8 +49,6 @@

Project information

- - Title project_title @@ -87,6 +63,15 @@ """ +HTML_PARAMETER_HEADER_TEMPLATE = """ + + parameter_name + parameter_value + parameter_unit + parameter_error + +""" + HTML_PARAMETER_TEMPLATE = """ parameter_name @@ -120,12 +105,6 @@ """ HTML_REFINEMENT_TEMPLATE = """ - -

Refinement

- - - - Calculation engine calculation_engine diff --git a/src/easyreflectometry/summary/summary.py b/src/easyreflectometry/summary/summary.py index 01284379..f587eede 100644 --- a/src/easyreflectometry/summary/summary.py +++ b/src/easyreflectometry/summary/summary.py @@ -3,6 +3,7 @@ from easyreflectometry.utils import count_free_parameters from .html_templates import HTML_DATA_COLLECTION_TEMPLATE +from .html_templates import HTML_PARAMETER_HEADER_TEMPLATE from .html_templates import HTML_PARAMETER_TEMPLATE from .html_templates import HTML_PROJECT_INFORMATION_TEMPLATE from .html_templates import HTML_REFINEMENT_TEMPLATE @@ -17,20 +18,25 @@ def compile_html_summary(self): html = HTML_TEMPLATE project_information_section = self._project_information_section() if project_information_section == '': # no project information - project_information_section = 'No project information' + project_information_section = 'No project information' html = html.replace('project_information_section', project_information_section) html = html.replace('sample_section', self._sample_section()) experiments_section = self._experiments_section() if experiments_section == '': # no experiments - experiments_section = 'No experiments' + experiments_section = 'No experiments' html = html.replace('experiments_section', experiments_section) html = html.replace('refinement_section', self._refinement_section()) return html + def save_html_summary(self, filename: str) -> None: + html = self.compile_html_summary() + with open(filename, 'w') as f: + f.write(html) + def _project_information_section(self) -> None: html_project = '' if self._project.created: @@ -46,11 +52,11 @@ def _project_information_section(self) -> None: def _sample_section(self) -> None: html_parameters = [] - html_parameter = HTML_PARAMETER_TEMPLATE - html_parameter = html_parameter.replace('parameter_name', 'Name') - html_parameter = html_parameter.replace('parameter_value', 'Value') - html_parameter = html_parameter.replace('parameter_unit', 'Unit') - html_parameter = html_parameter.replace('parameter_error', 'Error') + html_parameter = HTML_PARAMETER_HEADER_TEMPLATE + html_parameter = html_parameter.replace('parameter_name', 'Name') + html_parameter = html_parameter.replace('parameter_value', 'Value') + html_parameter = html_parameter.replace('parameter_unit', 'Unit') + html_parameter = html_parameter.replace('parameter_error', 'Error') html_parameters.append(html_parameter) for parameter in self._project.parameters: @@ -87,7 +93,6 @@ def _sample_section(self) -> None: # html_phase = html_phase.replace('angle_beta', f'{angle_beta}') # html_phase = html_phase.replace('angle_gamma', f'{angle_gamma}') - html_parameters.append('/n') html_parameters_str = '\n'.join(html_parameters) return html_parameters_str diff --git a/tests/summary/test_summary.py b/tests/summary/test_summary.py index 0318807a..e9f56424 100644 --- a/tests/summary/test_summary.py +++ b/tests/summary/test_summary.py @@ -44,6 +44,20 @@ def test_compile_html_summary(self, project: Project) -> None: assert 'experiments results html' in result assert 'refinement result html' in result + def test_save_html_summary(self, project: Project, tmp_path) -> None: + # When + project._created = True + summary = Summary(project) + # summary.compile_html_summary = MagicMock(return_value='html') + + # Then + summary.save_html_summary(tmp_path / 'filename.html') + + # Expect + assert os.path.exists(tmp_path / 'filename.html') + # with open('filename', 'r') as f: + # assert f.read() == 'html' + def test_project_information_section(self, project: Project) -> None: # When project._created = True