From 9e6439cf59de6e31796252f986d68554985acbe4 Mon Sep 17 00:00:00 2001 From: Adrian Herrmann Date: Tue, 4 Mar 2025 11:23:39 +0100 Subject: [PATCH] added operation type header_value --- converter_app/converters.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/converter_app/converters.py b/converter_app/converters.py index 9bbf4ce3..a11549b6 100644 --- a/converter_app/converters.py +++ b/converter_app/converters.py @@ -297,11 +297,25 @@ def _run_operation(self, rows, operation): str_value = operation.get('value') elif operation.get('type') == 'metadata_value': str_value = self.input_tables[int(operation.get('table'))]['metadata'].get(operation.get('value')) + elif operation.get('type') == 'header_value': + table = 0 + if operation.get('table') is not None: + table = int(operation.get('table')) + line = operation.get('line') + pattern = operation.get('regex') + if line is not None and pattern is not None: + str_value = self.input_tables[table]['header'][int(operation.get('line'))-1] + match = re.search(pattern, str_value) + if match is not None: + if len(match.regs) > 1: + str_value = match[1] + else: + str_value = match[0] else: raise ValueError(f"Unknown operation type: {operation.get('type')}") try: op_value = float(str_value) - except TypeError: + except (TypeError, ValueError): if operation.get('operator') in ('+', '-'): op_value = 0 else: