### ===================================================================================================================
### FUNCTION: Collect the required template for the report
### ===================================================================================================================
# Copyright ©VIIA 2024
### ===================================================================================================================
### 1. Import modules
### ===================================================================================================================
# General imports
from __future__ import annotations
from typing import TYPE_CHECKING, Dict
import yaml
# References for functions and classes in the viiaPackage
if TYPE_CHECKING:
from viiapackage.viiaStatus import ViiaProject
### ===================================================================================================================
### 2. Function to collect templates
### ===================================================================================================================
[docs]def viia_collect_templates(
project: ViiaProject, report_type: str = None, tender_specification: str = None) -> Dict[str, str]:
"""
This function sets up the folder locations for the model/result pictures.
Input:
- project (obj): VIIA project object containing collections of fem objects and project variables.
- report_type (str): Report type, choosing from 'opname', 'opnameplan', 'engineering' or 'beoordeling'.
- tender_specification (str): Tender specification (NL: vraagspecificatie) that relates to the required template
version . For example '2021_09082021'.
Output:
- Templates are collected and stored in a dictionary for all requested reports.
"""
template_locations = {}
# Read yaml with template references
with open(project.viia_settings.project_specific_package_location / 'reporting' / 'reports.yaml') as f:
report_templates = yaml.load(f, Loader=yaml.FullLoader)
# Set template (collect all templates for defined template version)
report_type_scope = report_templates[report_type]
if report_type == 'opname':
if project.project_information.get('inspection_subtype', None) == 'VAL-C':
if tender_specification in report_type_scope:
template_location = report_type_scope[tender_specification]['checklist']
else:
template_location = report_type_scope['other']['checklist']
else:
if tender_specification in report_type_scope:
template_location = \
report_type_scope[tender_specification][project.project_information['building_type_simple']]
else:
template_location = report_type_scope['other'][project.project_information['building_type_simple']]
template_locations.update({report_type: template_location})
elif report_type == 'engineering':
for key, value in report_type_scope.items():
template_location = None
if tender_specification in value.keys():
if isinstance(value[tender_specification], dict):
if project.analysis_type in value[tender_specification].keys():
template_location = value[tender_specification][project.analysis_type]
else:
template_location = value[tender_specification]
if template_location:
template_locations.update({key: template_location})
elif report_type in ['crm', 'bkg', 'opnameplan', 'beoordeling', 'kostenraming', 'urenmonitor', 'uo',
'ontwerpnotitie', 'bevindingen']:
if tender_specification in report_type_scope:
template_locations.update({report_type: report_type_scope[tender_specification]})
else:
template_locations.update({report_type: report_type_scope['other']})
# Check if any templates are available
if not template_locations:
raise ValueError(f"ERROR: Cannot collect templates for {report_type} report {tender_specification}.")
# Return the collected templates for the report
return template_locations
### ===================================================================================================================
### 3. End of script
### ===================================================================================================================