Skip to content

Commit

Permalink
base conditional requiremet on oed source type (#159)
Browse files Browse the repository at this point in the history
* base conditional requiremet on oed source type

* CR level 1 don't create requirements
  • Loading branch information
sstruzik authored and sambles committed Jul 4, 2023
1 parent 81d14d3 commit cb78b0c
Showing 1 changed file with 32 additions and 11 deletions.
43 changes: 32 additions & 11 deletions docker/extract_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,17 +262,38 @@ def get_cr_field(cr_field_df):
Returns:
conditional requirement dict
"""
cr_to_field = cr_field_df.groupby('Required Field')['Input Field Name'].apply(list).to_dict()
cr_field = {}
for cr, fields in cr_to_field.items():
for field in fields:
cur_cr_field = set(fields)
for i in range(cr.count('-') + 1):
cur_cr_field |= set(cr_to_field.get(cr.rsplit('-', i)[0], []))
if len(cur_cr_field) > 1: # we remove field that provide no extra requirement
cr_field[field] = list(cur_cr_field)

return cr_field
cr_field_df = (
cr_field_df
.assign(pd_dtype=cr_field_df['Data Type'].str.split('(', n=1, expand=True)[0].map(pd_converter))
.rename(columns={'File Name': 'File Names'})
)

# split ods_fields per File Name
split_df = cr_field_df['File Names'].str.split(';').apply(pd.Series, 1).stack()
split_df = (
split_df
.set_axis(split_df.index.droplevel(-1))
.rename('File Name')
.str.strip()
)
cr_field_df = cr_field_df.join(split_df).drop(columns='File Names')

cr_fields_by_file = {}
for file_name in cr_field_df['File Name'].unique():
cr_to_field = cr_field_df[cr_field_df['File Name'] == file_name].groupby('Required Field')['Input Field Name'].apply(list).to_dict()
cr_field = {}
for cr, fields in cr_to_field.items():
if '-' not in cr:
continue
for field in fields:
cur_cr_field = set(fields)
for i in range(cr.count('-') + 1):
cur_cr_field |= set(cr_to_field.get(cr.rsplit('-', i)[0], []))
if len(cur_cr_field) > 1: # we remove field that provide no extra requirement
cr_field[field] = list(cur_cr_field)
cr_fields_by_file[file_name] = cr_field

return cr_fields_by_file


def extract_valid_value_range(valid_value_range, dtype):
Expand Down

0 comments on commit cb78b0c

Please sign in to comment.