### ===================================================================================================================
### FUNCTION: Get data for the ontwerpnotitie report
### ===================================================================================================================
# Copyright ©VIIA 2024
### ===================================================================================================================
### 1. Import modules
### ===================================================================================================================
# General imports
from __future__ import annotations
from typing import TYPE_CHECKING, Optional, List
from datetime import datetime
# References for functions and classes in the viiaPackage
if TYPE_CHECKING:
from viiapackage.viiaStatus import ViiaProject
from viiapackage.database import myviia_get_eng_measure
from viiapackage.strengthening import GMCMeasures
from viiapackage.reporting.helper_functions.viia_get_address_info import viia_get_address_info
### ===================================================================================================================
### 2. Function to collect the data required for the ontwerpnotitie report
### ===================================================================================================================
[docs]def get_ontwerpnotitie_report_data(project: ViiaProject, extra_object_parts: Optional[List[str]] = None) -> dict:
"""
This function will generate dictionary keys for ontwerpnotitie report data that can later be used as jinja tags for
templating.
Input
- project (obj): VIIA project object containing collections of fem objects and project variables.
- extra_object_parts (list of str): List of names of extra object parts to include in the report. Default value
is None.
Output
- Dictionary of jinja tags assigned to corresponding info.
"""
# Collect the general info which is retrieved from MYVIIA at project initialisation
general_info = project.project_information
# Check if general info is retrieved from MYVIIA
if 'id' not in general_info:
project.write_log(
f"WARNING: No general information is retrieved from MYVIIA database for this object. General information "
f"is not replaced in the ontwerpnotitie report.")
return {}
# Collect the data for the template of the UO-report
context = {}
# Find project info to use in report
context['objectnaam'] = general_info.get('objectnaam', '')
context['projectnaam'] = general_info['opdracht_id'].get('projectnaam', '')
context['status'] = general_info.get('object_status_id', {}).get('status', 'ONBEKEND').capitalize()
# Find the deliverable, category strengthening, and rekenmethodiek
deliverable_ontwerpnotitie = None
if 'objectdelen' in general_info and general_info['objectdelen']:
for objectpart in general_info['objectdelen']:
if objectpart['naam'] == 'Gehele object':
for deliverable in objectpart['deliverables']:
if deliverable['deliverable_id']['deliverable'] == "Ontwerpnotitie":
deliverable_ontwerpnotitie = deliverable
if deliverable_ontwerpnotitie:
context['versienummer'] = deliverable_ontwerpnotitie.get('versienummer', 'ONBEKEND')
context['AD_nummer'] = general_info.get('projectnummer_og', 'ONBEKEND')
context['npr_versie'] = general_info.get('npr_versie', 'ONBEKENDE NPR')
context['tijdsperiode'] = general_info.get('reference_period', 'ONBEKENDE TIJDSPERIODE')
context['PGA'] = general_info.get('pga', 'onbekend')
context['gevolgklasse'] = general_info.get('gevolgklasse', 'onbekend')
# Collect the current date
current_date = datetime.now()
date_dict = {
1: 'januari', 2: 'februari', 3: 'maart', 4: 'april', 5: 'mei', 6: 'juni', 7: 'juli', 8: 'augustus',
9: 'september', 10: 'oktober', 11: 'november', 12: 'december'}
context['datum'] = f"{current_date.day} {date_dict[current_date.month]} {current_date.year}"
# Collect the address(es) and related info for the object
address_string, address_list, dossier_nrs, postcode, municipality = \
viia_get_address_info(project=project, myviia_data_object_address=general_info.get('object_adressen', []))
context['adres'] = address_string
context['monument'] = general_info.get('erfgoed_status', 'ONBEKEND')
context['rekenmethodiek'] = ','.join(set([deel['rekenmethodiek_id'].get('rekenmethodiek', '') for
deel in general_info.get('objectdelen', []) if
deel.get('rekenmethodiek_id', None)]))
# Check the bureau opteller and TVA
context['tva_deliverables'] = []
if 'objectdelen' in general_info and general_info['objectdelen']:
for objectpart in general_info['objectdelen']:
if objectpart['naam'] == 'Gehele object':
for deliverable in objectpart['deliverables']:
if deliverable['deliverable_id']['deliverable'] == 'TVA':
context['bureau_opteller'] = 'VIIA'
break
else:
context['bureau_opteller'] = None
else:
for deliverable in objectpart['deliverables']:
if deliverable['deliverable_id']['deliverable'] == 'TVA':
context['tva_deliverables'].append(f"TVA - {objectpart['naam']}")
break
if len(context['tva_deliverables']) == 0:
context['tva_deliverables'] = ['TVA']
# Check the category versterking KMG
if 'versterking benodigd' in general_info.get('conclusie_analyse'):
context['categorie_versterking_KMG'] = general_info['conclusie_analyse'].capitalize()
# Check the BVVA besproken met bewoners
if general_info.get('vg_projectleider_fase3') and len(fase3 := general_info.get('vg_projectleider_fase3')) > 0:
if fase3[-1].get('eerste_gespreksverslag') and fase3[-1].get('vrijgave_bevindingenrapport') and \
fase3[-1].get('vrijgave_ontwerpnotitie'):
context['bvva'] = 'ja'
else:
context['bvva'] = 'nee'
# Get the measures
if not general_info.get('engineering_measures', None):
object_deel_id = project.get_myviia_object_deel_id()
engineering_measures = myviia_get_eng_measure(object_deel_id=object_deel_id, token=project.token)
if extra_object_parts:
for object_part_name in extra_object_parts:
for objectpart in general_info['objectdelen']:
if objectpart['naam'] == object_part_name:
engineering_measures = [
*engineering_measures,
*myviia_get_eng_measure(object_deel_id=objectpart['id'], token=project.token)]
break
context['engineering_measures'] = engineering_measures
measure_description = GMCMeasures().get_strengthening_measures(project)
for measure in context['engineering_measures']:
measure['description'] = measure_description.get(measure['name'], {}).get('description_nl', '')
else:
context['engineering_measures'] = general_info['engineering_measures']
return context
### ===================================================================================================================
### 3. End of script
### ===================================================================================================================