Field Utilities

Module: ppc_robot_lib.utils.field

get_base_name(field_name, suffixes, separator='_', max_expansions=3)[source]

Tries to find a suffix that is appended after a separator. The suffix must be defined in the suffixes dictionary. This can be used to extract base name and a suffix from fixed range field names, e.g. Cost_7_day.

This method tries to find the longest suffix that is present in the dictionary. It finds all separators in the string and tries to match the suffix with the dictionary. If no match is found, it moves onto the next separator, until the max_expansions is reached.

Parameters:
  • field_name (str) – Name of the field to analyze.

  • suffixes (dict[str, TypeVar(T)]) – Dictionary of suffixes, keys are the suffix, values can be anything.

  • separator – Suffix separator.

  • max_expansions – Maximum number of expansions to perform.

Return type:

tuple[str, TypeVar(T)]

Returns:

Tuple with base name and value for given suffix.