### ===================================================================================================================
### Preset the seleted objects for MYVIIA
### ===================================================================================================================
# Copyright ©VIIA 2024
### ===================================================================================================================
### 1. Import modules
### ===================================================================================================================
# General imports
from __future__ import annotations
from typing import TYPE_CHECKING, List
from datetime import date
# References for functions and classes in the viiaPackage
from viiapackage.database import myviia_get_selected_reference_objects, myviia_post_selected_reference_object
from viiapackage.reference_approach.viia_current_object import CurrentObject
from viiapackage.reference_approach.viia_convert_data_eng_database import MYVIIAEngDatabase
if TYPE_CHECKING:
from viiapackage.viiaStatus import ViiaProject
### ===================================================================================================================
### 2. Function to preset selected reference objects on MYVIIA
### ===================================================================================================================
[docs]def viia_preset_selected_reference_objects_myviia(
project: ViiaProject, reference_objects: List[MYVIIAEngDatabase], current_object: CurrentObject) -> None:
"""
This function will extend the information of the reference object with additional queries on MYVIIA. Currently, the
data is extended for the information on the strengthening measures applied.
Input:
- reference_object (obj): Object reference of the MYVIIAEngDatabase class.
Output:
- The instance is extended with data from MYVIIA.
"""
# Only perform this update for objects in reference approach
if project.analysis_type not in ['NLTH-REF', 'NLPO-REF']:
return None
# Check if there are already any selected reference objects
current_references = myviia_get_selected_reference_objects(
object_deel_id=project.get_myviia_object_deel_id(), token=project.token)
if current_references:
project.write_log(f"There are already selected object references on MYVIIA. No changes are applied on MYVIIA.")
return None
# Collect the data to be sent to MYVIIA
post_on_myviia = []
for reference_object in reference_objects:
post_on_myviia.append({
'date': str(date.today()),
'object_deel_id': project.get_myviia_object_deel_id(),
'ref_object_deel_id': reference_object.objectpart_id})
# Actual post on MYVIIA
for item in post_on_myviia:
myviia_post_selected_reference_object(data=item, token=project.token)
# Notify user
uploaded = [f"{obj_ref.objectnumber_viia} ({obj_ref.objectpart})" for obj_ref in reference_objects]
project.write_log(
f"The following objects have been set as reference objects on MYVIIA, please update for your final "
f"selection. Reference objects: {', '.join(uploaded)}.")
### ===================================================================================================================
### 3. End of script
### ===================================================================================================================