From fceb3a7f46870fdb2be985387f39fe72dbaa4bc1 Mon Sep 17 00:00:00 2001 From: Emerson Rocha Date: Wed, 3 Aug 2022 16:37:53 -0300 Subject: [PATCH] 999999999_521850.py (#43): hxltm__data_pivot_wide() started --- officina/999999999/0/999999999_521850.py | 6 +- officina/999999999/0/L999999999_0.py | 115 +++++++++++++++++++++++ 2 files changed, 120 insertions(+), 1 deletion(-) diff --git a/officina/999999999/0/999999999_521850.py b/officina/999999999/0/999999999_521850.py index ee7e2d1..b1eb663 100755 --- a/officina/999999999/0/999999999_521850.py +++ b/officina/999999999/0/999999999_521850.py @@ -53,6 +53,7 @@ from L999999999_0 import ( # hxltm_carricato, NUMERORDINATIO_BASIM, + hxltm__data_pivot_wide, hxltm__data_sort, numerordinatio_neo_separatum, # TabulaAdHXLTM @@ -1155,9 +1156,12 @@ def de_hxltm_ad_hxltm_wide( data_sorted = hxltm__data_sort( fonti, ['#item+rem+i_qcc+is_zxxx+ix_xyadhxltrivio']) + caput, data = hxltm__data_pivot_wide(data_sorted[0], data_sorted[1:]) + # print(data_sorted[0:10]) + print(caput, data[0:10]) - # raise NotImplementedError + raise NotImplementedError with open(objetivum, 'w') as _objetivum: # with open(fonti, 'r') as _fons: diff --git a/officina/999999999/0/L999999999_0.py b/officina/999999999/0/L999999999_0.py index 829c76b..a9feba9 100644 --- a/officina/999999999/0/L999999999_0.py +++ b/officina/999999999/0/L999999999_0.py @@ -5445,6 +5445,121 @@ def hxltm__data_sort(fonti: str, sortkeys: list = None) -> list: return resultatum +def hxltm__data_pivot_wide(caput: list, data: list) -> list: + + referens_columnae = '#item+rem+i_qcc+is_zxxx+ix_xyadhxltrivio' + + # No + as prefix here + hxlatt_ex = 'ix_xyexhxltrivio' + if referens_columnae not in caput: + raise SyntaxError('[{}] must exist on header <{}>'.format( + referens_columnae, caput)) + + referens_per_indici = caput.index(referens_columnae) + referens_ad_indici = [] + for item in caput: + if hxlatt_ex in item: + referens_ad_indici.append(caput.index(item)) + if len(referens_ad_indici) == 0: + raise SyntaxError('{} not in header <{}>'.format(hxlatt_ex, caput)) + + referens_hxlattrs = [] + for linea in data: + if linea[referens_per_indici] not in referens_hxlattrs: + referens_hxlattrs.append(linea[referens_per_indici]) + + sorted(referens_hxlattrs) + + columna_novae__list = [] + columna_novae__mapping = {} + + for item_I in referens_hxlattrs: + for item_II in referens_ad_indici: + + res = hxl_hashtag_normalizatio( + caput[item_II].replace(hxlatt_ex, item_I)) + if res in columna_novae__list: + continue + columna_novae__list.append(res) + # columna_novae__mapping[item_I] = columna_novae__list.index(res) + columna_novae__mapping[item_I] = len(columna_novae__list) - 1 + # pass + # columna_novae__list + + data_novae__dict = {} + _codice_indici = caput.index('#item+conceptum+codicem') + for linea in data: + _codicem = linea[_codice_indici] + _referens = linea[referens_per_indici] + __start = columna_novae__mapping[_referens] + __diff = len(columna_novae__list) + if _codicem not in data_novae__dict: + data_novae__dict[_codicem] = { + 'originalis': linea, + # 'data_novae': [''] * len(columna_novae__list), + 'data_novae': [''] * (len(columna_novae__list) + 1), + } + + __loop = 0 + # print(len(data_novae__dict[_codicem]['data_novae'])) + for index_originalis in referens_ad_indici: + # index_novae = __start + index_originalis + # print(__loop, len(data_novae__dict[_codicem]['data_novae'])) + index_novae = __start + __loop + if index_novae not in data_novae__dict[_codicem]['data_novae']: + print('error', index_novae, len(data_novae__dict[_codicem]['data_novae'])) + continue + data_novae__dict[_codicem]['data_novae'][index_novae] = \ + linea[index_originalis] + __loop += 1 + + # for item in caput: + # for item_II in referens_ad_indici: + + # pass + + raise NotImplementedError(data_novae__dict['4']) + raise NotImplementedError(columna_novae__list, columna_novae__mapping) + + # if not sortkeys: + # sortkeys = [] + + # if '#item+conceptum+codicem' not in sortkeys: + # sortkeys.insert(0, '#item+conceptum+codicem') + + # _data = [] + # caput = [] + # with open(fonti, 'r') as _fons: + # _csv_reader = csv.reader(_fons) + # # started = False + # for linea in _csv_reader: + # if len(caput) == 0: + # caput = linea + # continue + # _data.append(linea) + + # _i0 = caput.index(sortkeys[0]) + # if len(sortkeys) == 1: + # _data = sorted(_data, key=lambda row: int(row[_i0])) + # elif len(sortkeys) == 2: + # _i1 = caput.index(sortkeys[1]) + # _data = sorted(_data, key=lambda row: (int(row[_i0]), row[_i1])) + # elif len(sortkeys) == 3: + # _i1 = caput.index(sortkeys[1]) + # _i2 = caput.index(sortkeys[2]) + # _data = sorted( + # _data, key=lambda row: (int(row[_i0]), row[_i1], row[_i2])) + # else: + # raise NotImplementedError('len > 3; [{}] <{}>'.format( + # len(sortkeys), sortkeys)) + + # resultatum = [] + # resultatum.append(caput) + # resultatum.extend(_data) + + return caput, data + + def hxltm__concat( # al1: str, b2: str, significatus: dict,