### ===================================================================================================================
### FUNTION: Collect information for the inspection report
### ===================================================================================================================
# Copyright ©VIIA 2024
### ===================================================================================================================
### 1. Import modules
### ===================================================================================================================
# General imports
from __future__ import annotations
from typing import TYPE_CHECKING
# References for functions and classes in the viiaPackage
if TYPE_CHECKING:
from viiapackage.viiaStatus import ViiaProject
from viiapackage.database import myviia_get_object_deel, myviia_get_voortgang_deel
### ===================================================================================================================
### 2. Function get_inspection_data
### ===================================================================================================================
[docs]def get_inspection_data(project: ViiaProject) -> dict:
"""
This function will generate dictionary keys for inspection data that can later be used as jinja tags for templating.
.. note:: Currently only available in Dutch.
Input
- project (obj): VIIA project object containing collections of fem objects and project variables.
Output
- Dictionary of jinja tags assigned to corresponding info.
"""
def propose_typology(ctx):
if ctx['vraag_a2_1'] == ctx['vraag_a2_2']:
if ctx['vraag_a2_1'] == 'Hout':
if ctx['vraag_a4_2'] in ['1', '2']:
if ctx['vraag_a3_1'] == ctx['vraag_a3_2']:
if ctx['vraag_a3_1'] == 'Portalen':
return 'HOUT2'
elif ctx['vraag_a3_1'] in ['Schijfwerking gevels en wanden', 'Raamwerk']:
return 'HOUT1'
elif ctx['vraag_a2_1'] == 'Staal':
if ctx['vraag_a3_1'] == ctx['vraag_a3_2']:
if ctx['vraag_a4_2'] in ['1', '2']:
if ctx['vraag_a3_1'] == 'Raamwerk':
return 'STAAL1'
elif ctx['vraag_a3_1'] == 'Raamwerk stalen schoren':
return 'STAAL4'
elif ctx['vraag_a4_2'] in ['3', '4']:
if ctx['vraag_a3_1'] == 'Raamwerk':
return 'STAAL2'
elif ctx['vraag_a3_1'] == 'Raamwerk stalen schoren':
return 'STAAL5'
else:
if ctx['vraag_a3_1'] == 'Raamwerk':
return 'STAAL3'
elif ctx['vraag_a3_1'] == 'Raamwerk stalen schoren':
return 'STAAL6'
elif ctx['vraag_a2_1'] == 'Gewapend beton':
if ctx['vraag_a3_1'] == ctx['vraag_a3_2']:
if ctx['vraag_a3_1'] == 'Kolommen en balken':
return 'BETON4'
else:
if 'Schijfwerking gevels en wanden' in [ctx['vraag_a3_1'], ctx['vraag_a3_2']]:
if 'Raamwerk' in [ctx['vraag_a3_1'], ctx['vraag_a3_2']] \
or ctx['vraag_a3_1'] == ctx['vraag_a3_2']:
if ctx['vraag_a4_2'] in ['1', '2']:
return 'BETON1'
elif ctx['vraag_a4_2'] in ['3', '4']:
return 'BETON2'
else:
return 'BETON3'
if 'Portalen' in [ctx['vraag_a3_1'], ctx['vraag_a3_2']]:
if 'Schijfwerking gevels en wanden' in \
[ctx['vraag_a3_1'], ctx['vraag_a3_2']] or 'Raamwerk stalen schoren' in \
[ctx['vraag_a3_1'], ctx['vraag_a3_2']]:
# Windverbanden selection is not part of the checklist
if ctx['vraag_a4_2'] in ['1', '2']:
return 'BETON5'
elif ctx['vraag_a4_2'] in ['3', '4']:
return 'BETON6'
else:
return 'BETON7'
elif ctx['vraag_a2_1'] == 'Geprefabriceerd beton':
if 'Schijfwerking gevels en wanden' in [ctx['vraag_a3_1'], ctx['vraag_a3_2']]:
if 'Raamwerk' in [ctx['vraag_a3_1'], ctx['vraag_a3_2']] or \
ctx['vraag_a3_1'] == ctx['vraag_a3_2']:
if ctx['vraag_a4_2'] in ['1', '2']:
return 'PREFAB1'
elif ctx['vraag_a4_2'] in ['3', '4']:
return 'PREFAB2'
else:
return 'PREFAB3'
elif ctx['vraag_a2_1'] == 'Metselwerk':
if ctx['vraag_a1_1'] == 'ja':
if ctx['vraag_a3_1'] == ctx['vraag_a3_2'] == 'Schijfwerking gevels en wanden' and \
ctx['vraag_a4_2'] == '1':
if ctx['vraag_a5_2'] == 'Massief':
# TNO scheme uses 'Steens' instead of 'Massief', it's not the same
return 'METSELWERK5'
elif ctx['vraag_a5_2'] == 'Spouw':
if ctx['vraag_a5_1'] == 'Beton':
return 'METSELWERK6'
else:
return 'METSELWERK7'
elif ctx['vraag_a1_1'] == 'nee':
if ctx['vraag_a1_2'] == 'seriematig':
if ctx['vraag_a1_2'] == '<85%':
if ctx['vraag_a4_2'] in ['1', '2']:
if 'Schijfwerking gevels en wanden' in [ctx['vraag_a3_1'], ctx['vraag_a3_2']]:
if ctx['vraag_a5_2'] == 'Spouw':
if ctx['vraag_a5_1'] == 'Hout':
return 'METSELWERK3A'
elif ctx['vraag_a5_1'] == 'Beton':
return 'METSELWERK1'
elif ctx['vraag_a5_3'] == '85-100%':
if ctx['vraag_a4_2'] in ['1', '2']:
if 'Schijfwerking gevels en wanden' in [ctx['vraag_a3_1'],
ctx['vraag_a3_2']] and ctx[
'vraag_a3_1'] == ctx['vraag_a3_2'] or 'Raamwerk' in [ctx['vraag_a3_1'],
ctx['vraag_a3_2']]:
if ctx['vraag_a5_2'] == 'Spouw':
if ctx['vraag_a5_1'] == 'Beton':
return 'METSELWERK2'
elif ctx['vraag_a5_1'] == 'Hout':
return 'METSELWERK3B'
else:
if ctx['vraag_a4_2'] in ['3']:
if 'Betonnen vloeren op wanden' in [ctx['vraag_a3_1'], ctx['vraag_a3_2']]:
if 'Raamwerk' in [ctx['vraag_a3_1'], ctx['vraag_a3_2']]:
if ctx['vraag_a5_1'] == 'Beton':
if ctx['vraag_a5_2'] == 'Spouw':
return 'METSELWERK4'
if ctx['vraag_a1_2'] == 'niet-seriematig':
if ctx['vraag_a3_1'] == ctx['vraag_a3_2']:
if 'Schijfwerking gevels en wanden' in [ctx['vraag_a3_1']]:
if ctx['vraag_a4_2'] in ['1']:
if ctx['vraag_a5_2'] == 'Massief':
# TNO scheme uses 'Steens' instead of 'Massief', it's not the same
if ctx['vraag_a5_1'] == 'Hout':
return 'METSELWERK10'
else:
if ctx['vraag_a5_2'] == 'Spouw':
if ctx['vraag_a5_1'] == 'Beton':
return 'METSELWERK9'
else:
return 'METSELWERK8'
return 'MAATWERK'
inspection_info = None
if 'test-' != project.name[:5]:
# Obtain object part opname
objectpart_id = None
for objectpart in project.project_information['objectdelen']:
if objectpart['naam'] == project.project_information['objectdeel']:
objectpart_id = objectpart['id']
break
if not objectpart_id:
raise ValueError("ERROR: Could not find the correct objectpart.")
object_part_details = myviia_get_object_deel(object_deel_id=objectpart_id, token=project.token)
if project.project_information['inspection_type'] in ['TYPO', 'LOOV', 'EVS2']:
project.project_information['object_deel_opname'] = object_part_details['object_deel_opname']
project.project_information['opname_images_folder'] = 'opname_images'
elif project.project_information['inspection_subtype'] in ['VAL', 'VAL-P']:
project.project_information['object_deel_opname'] = object_part_details['object_deel_opname_val']
project.project_information['opname_images_folder'] = 'opname_val_images'
elif project.project_information['inspection_subtype'] in ['VAL-C']:
project.project_information['object_deel_opname'] = object_part_details['object_deel_opname_val2']
project.project_information['opname_images_folder'] = 'opname_val2_images'
else:
raise ValueError("ERROR: Could not find the correct opname data.")
# Obtain object part opname voortgang
object_part_progress = myviia_get_voortgang_deel(
object_deel_id=objectpart_id, token=project.token)['voortgang']
project.project_information['voortgang_deel_opname'] = None
for deliverable in object_part_progress:
if deliverable['deliverable'] == 'Opname':
project.project_information['voortgang_deel_opname'] = deliverable
if not project.project_information['voortgang_deel_opname']:
project.write_log(
"WARNING: No progress sheet for inspection found on MYVIIA. "
"Please check with datatool@viiagroningen.nl.")
inspection_info = project.project_information.get('object_deel_opname', None)
if not inspection_info:
project.write_log(
f"WARNING: No inspection information is retrieved from database for this object. Inspection information is "
f"not replaced in the inspection report.")
context = {}
if project.project_information.get('inspection_subtype', None) != 'VAL-C':
progress_info = project.project_information.get('voortgang_deel_opname', None)
if not progress_info:
project.write_log(
f"WARNING: No progress information is retrieved from database for this inspection. Progress "
f"information is not replaced in the inspection report.")
context['datum_opname'] = None
if progress_info:
inspection_date = progress_info.get('planning_start', '9999-99-99')
# Get 'datum_opname' from YYYY-MM-DD into DD-MM-YYYY
if context['datum_opname'] is None:
context['datum_opname'] = 'ONBEKEND'
else:
context['datum_opname'] = '-'.join(context['datum_opname'].split('-')[::-1])
if inspection_info:
# Remove the ID of the database
key_list = [x for x in inspection_info.keys() if x != 'id']
# All keys will have an entry (might be an empty string)
for key in key_list:
val = inspection_info.get(key) or ''
# If the data on MYVIIA is a list it will be converted to a string comma separated, except for the last
# element which will be added after an 'en'. All input is lowercase except for first letter of list.
if isinstance(val, list):
if len(val) > 1:
val = ', '.join([v.lower() for v in val]).capitalize()
k = val.rfind(', ')
val = f'{val[:k]} en {val[k+2:]}.'
else:
val = val[0].capitalize() + '.'
# Other cases the first letter only will be capitalised
elif isinstance(val, str) and val != '':
if len(val) == 1:
val = val[0].upper()
else:
val = val[0].upper() + val[1:]
context[key] = val
if 'typologie' in key_list:
context['voorgestelde_typologie'] = propose_typology(context)
# If VAL-C inspection information, data transformation is needed.
# For Chapter 3 (addition of pictures), only the number at the end is relevant
# For example: context['vraag_3_1'] = 'Vraag 1.17' => context['vraag_3_1'] = '17'
if project.project_information['inspection_subtype'] in ['VAL-C']:
chapter_3_keys = [x for x in key_list if 'vraag_3_' in x and not 'bestand' in x and not 'toelichting' in x]
chapter_3_explanations = [context[x] for x in key_list if 'vraag_3_' in x and 'toelichting' in x]
chapter_3_files = [context[x] for x in key_list if 'vraag_3_' in x and 'bestand' in x]
chapter_3_values = []
for key in chapter_3_keys:
if context[key] != '':
context[key] = context[key].split('.')[-1]
chapter_3_values.append(context[key])
else:
context[key] = '0'
chapter_3 = [list(a) for a in
zip(chapter_3_keys, chapter_3_values, chapter_3_explanations, chapter_3_files)]
chapter_3.sort(key = lambda x: int(x[1]))
context['hoofdstuk_3'] = chapter_3
return context
### ===================================================================================================================
### 3. End of script
### ===================================================================================================================