def get_categories_mrs(meta, vtype, vvalues, child, child_name, text_key): if is_mapped_meta(vvalues): vvalues = get_mapped_meta(meta, vvalues) var_code = [] mval = 1 if vtype == 'single' else len(vvalues) var_code.append(MaxValue(0, child, mval)) for value in vvalues: name = '{}a{}'.format(child_name, value['value']) vlabel = get_text(value['text'], text_key) var_code.extend([ CreateElement(0, name, vlabel), ElementType(0), AddElement(0, child, 'newElement')]) return var_code
def mask_to_mrs(meta, mask, name, text_key): mask_code = [] mask_name = name.split('.')[0] field_name = '{}_grid'.format(mask_name) mitem0_name = mask['items'][0]['source'].split('@')[-1] mitem0 = get_mapped_meta(meta, mask['items'][0]['source'])[mitem0_name] mtype = mitem0['type'] if mtype in ['single', 'delimited set']: mvalues = mask['values'] mlabel = get_text(mask['text'], text_key) mask_code.extend([ section_break(20), comment(0, '{}'.format(mask_name)), CreateGrid(0, mask_name, mlabel) ]) for i, item in enumerate(mask['items'], start=0): name = mask['items'][i]['source'].split('@')[-1].split('.')[0] name = name.replace('[{', '').replace('}]', '').replace(mask_name, '', 1) ilabel = get_text(mask['items'][i]['text'], text_key) mask_code.extend([ CreateElement(0, name, ilabel), AddElement(0, 'newGrid', 'newElement') ]) mask_code.extend([ CreateVariable(0, field_name, mlabel), DataType(0, 'newVar', QTYPES[mtype]) ]) if mtype in ['single', 'delimited set']: mask_code.extend( get_categories_mrs(meta=meta, vtype=mtype, vvalues=mvalues, child='newVar', child_name=mask_name, text_key=text_key)) mask_code.extend( [AddField(0, 'newGrid', 'newVar'), AddField(0, 'MDM', 'newGrid')]) return mask_code
def get_categories_mrs(meta, vtype, vvalues, child, child_name, text_key): if is_mapped_meta(vvalues): vvalues = get_mapped_meta(meta, vvalues) var_code = [] lang = [] ltype = [] mval = 1 if vtype == 'single' else len(vvalues) var_code.append(MaxValue(0, child, mval)) for value in vvalues: if value['value'] < 0: name = '{}aminus{}'.format(child_name, -1 * value['value']) else: name = '{}a{}'.format(child_name, value['value']) labels = DimLabels(name, text_key) labels.add_text(value['text']) var_code.extend([ CreateElement(0, name), get_lab_mrs(0, 'newElement', labels), ElementType(0), AddElement(0, child, 'newElement') ]) lang += labels.incl_languages ltype += labels.incl_labeltypes return var_code, list(set(lang)), list(set(ltype))