ResSimpy.Nexus.nexus_add_new_object_to_file.AddObjectOperations

class ResSimpy.Nexus.nexus_add_new_object_to_file.AddObjectOperations(obj_type: type[T] | None, table_header: str, table_footer: str, model: NexusSimulator)[source]

Bases: object

Methods:

__init__(obj_type, table_header, ...)

find_which_file_from_id(obj_id, ...)

Finds a file based on the presence of an object in the file.

get_and_write_new_header(additional_headers, ...)

Gets the header and works out if any additional headers should be added based on the new obj attributes being added.

fill_in_nas(additional_headers, ...)

Check the validity of the line, if its valid add as many NAs as required for the new columns.

write_out_new_table_containing_object(...)

Writes out the existing table for an object being added at a new time stamp.

check_name_date(object_properties)

Checks for the presence of a name and a date in the additional object properties provided.

add_object_to_file(date, file_as_list, ...)

Finds where the object should be added based on the date and existing tables.

add_network_obj(node_to_add, obj_type, network)


__init__(obj_type: type[T] | None, table_header: str, table_footer: str, model: NexusSimulator) None[source]
find_which_file_from_id(obj_id: UUID, file_type_to_search: str) NexusFile[source]

Finds a file based on the presence of an object in the file.

Parameters:
  • obj_id (UUID) – object id to match on

  • file_type_to_search (str) – file type from within the fcsfile. e.g. ‘well_files’

Returns:

NexusFile that contains the object of interest in the object_locations attribute.

static get_and_write_new_header(additional_headers: list[str], object_properties: dict[str, None | str | float | int], file_content: list[str], index: int, nexus_mapping: dict[str, tuple[str, type]], file: File) tuple[int, list[str], list[str]][source]

Gets the header and works out if any additional headers should be added based on the new obj attributes being added.

Parameters:
  • additional_headers (list[str]) – New headers required for the objects new columns.

  • object_properties (dict[str, None | str | float | int]) – dictionary containing new attributes of the object.

  • file_content (list[str]) – flattened file content as a list of strings.

  • index (int) – index to start reading the new headers from.

  • nexus_mapping (dict[str, tuple[str, type]]) – dictionary controlling the mapping from keyword to attribute.

  • file (NexusFile) – file to write the new header to.

Returns:

tuple[int, list[str], list[str]] – index of the new headers, a list of the headers, the original set of headers.

static fill_in_nas(additional_headers: list[str], headers_original: list[str], index: int, line: str, file: File, file_content: list[str]) int[source]

Check the validity of the line, if its valid add as many NAs as required for the new columns.

Parameters:
  • additional_headers (list[str]) – New headers added to the table.

  • headers_original (list[str]) – headers from the original table in the file.

  • index (int) – index of the line to start filling NAs from.

  • line (str) – line to add additional NAs to.

  • file (NexusFile) – file to add NAs to

  • file_content (list[str]) – flattened content of the file being read

Returns:

int – index of the line if a valid line has been found otherwise returns -1.

write_out_new_table_containing_object(obj_date: str, object_properties: dict[str, None | str | float | int], date_found: bool, new_obj: Any) tuple[list[str], int][source]

Writes out the existing table for an object being added at a new time stamp.

Parameters:
  • obj_date (str) – date for the object to be added at.

  • object_properties (dict[str, None | str | float | int]) – dictionary containing new attributes of the object.

  • date_found (bool) – Whether a new TIME card is required or not.

  • new_obj (Any) – The object getting added that requires the new table to represent it.

Returns:

list[str], int – first return arg is a new table containing the requested object and the second representing the line location of the new object within the table.

static check_name_date(object_properties: dict[str, None | str | float | int]) tuple[str, str][source]

Checks for the presence of a name and a date in the additional object properties provided.

add_object_to_file(date: str, file_as_list: list[str], file_to_add_to: File, new_object: T, object_properties: dict[str, None | str | float | int]) None[source]

Finds where the object should be added based on the date and existing tables.

Parameters:
  • date (str) – date to add the node at.

  • file_as_list (list[str]) – flattened file as a list of strings.

  • file_to_add_to (NexusFile) – file to add the new text to.

  • new_object (Any) – an object with a to_dict, table_header, table_footer, get_keyword_mapping and to_string

  • methods.

  • object_properties (dict[str, None | str | float | int]) – dictionary containing new attributes of the object.