Skip to content

Commit ce669f4

Browse files
jochenklarphuang26
authored andcommitted
Process identifiers in output table headers for XYData
1 parent 75355e5 commit ce669f4

1 file changed

Lines changed: 20 additions & 10 deletions

File tree

converter_app/converters.py

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -65,15 +65,7 @@ def __init__(self, profile, file_data):
6565

6666
def match(self):
6767
for identifier in self.identifiers:
68-
if identifier.get('type') == 'fileMetadata':
69-
match = self.match_file_metadata(identifier, self.file_metadata)
70-
elif identifier.get('type') == 'tableMetadata':
71-
match = self.match_table_metadata(identifier, self.input_tables)
72-
elif identifier.get('type') == 'tableHeader':
73-
match = self.match_table_header(identifier, self.input_tables)
74-
else:
75-
return False
76-
68+
match = self.match_identifier(identifier)
7769
if match is False and not identifier.get('optional'):
7870
# return immediately if one (non optional) identifier does not match
7971
return False
@@ -87,6 +79,16 @@ def match(self):
8779
# if everything matched, return how many identifiers matched
8880
return len(self.matches)
8981

82+
def match_identifier(self, identifier):
83+
if identifier.get('type') == 'fileMetadata':
84+
return self.match_file_metadata(identifier, self.file_metadata)
85+
elif identifier.get('type') == 'tableMetadata':
86+
return self.match_table_metadata(identifier, self.input_tables)
87+
elif identifier.get('type') == 'tableHeader':
88+
return self.match_table_header(identifier, self.input_tables)
89+
else:
90+
return False
91+
9092
def match_file_metadata(self, identifier, metadata):
9193
input_key = identifier.get('key')
9294
input_value = metadata.get(input_key)
@@ -181,7 +183,15 @@ def match_value(self, identifier, value):
181183

182184
def process(self):
183185
for output_table_index, output_table in enumerate(self.output_tables):
184-
header = output_table.get('header', {})
186+
header = {}
187+
for key, value in output_table.get('header', {}).items():
188+
if isinstance(value, dict):
189+
# this is a table identifier, e.g. FIRSTX
190+
match = self.match_identifier(value)
191+
if match:
192+
header[key] = match['value']
193+
else:
194+
header[key] = value
185195

186196
# merge the metadata from the profile (header) with the metadata
187197
# extracted using the identifiers (see self.match)

0 commit comments

Comments
 (0)