Skip to content

Commit

Permalink
999999999_521850.py (#43): hxltm__data_sort()
Browse files Browse the repository at this point in the history
  • Loading branch information
fititnt committed Aug 3, 2022
1 parent 0a88819 commit 3da0784
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 38 deletions.
42 changes: 4 additions & 38 deletions officina/999999999/0/999999999_521850.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
from L999999999_0 import (
# hxltm_carricato,
NUMERORDINATIO_BASIM,
hxltm__data_sort,
numerordinatio_neo_separatum,
# TabulaAdHXLTM
)
Expand Down Expand Up @@ -903,43 +904,6 @@ def _codicem(self, res: str, strictum: bool = False, index: int = 0) -> str:
# return _v
return None if strictum else str(900 + index)

def _data_sort(self, fonti: str) -> list:
# with open(objetivum, 'w') as _objetivum:
# @TODO move to L9999~
# @TODO create an dedicated function to explode datasets with
# '#item+rem+i_qcc+is_zxxx+ix_xyadhxltrivio' reference and
# '+ix_xyexhxltrivio' as attribute
_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)

# @TODO do the sorting here

_codicem_index = caput.index('#item+conceptum+codicem')

if '#item+rem+i_qcc+is_zxxx+ix_xyadhxltrivio' in caput:
_adtrivio_index = caput.index(
'#item+rem+i_qcc+is_zxxx+ix_xyadhxltrivio')
_data = sorted(
_data,
key=lambda row: (
int(row[_codicem_index]), row[_adtrivio_index])
)
else:
_data = sorted(_data, key=lambda row: int(row[_codicem_index]))
resultatum = []
resultatum.append(caput)
resultatum.extend(_data)

return resultatum

def _hxlize_dummy(self, caput: list):
resultatum = []
for res in caput:
Expand Down Expand Up @@ -1187,7 +1151,9 @@ def de_hxltm_ad_hxltm_wide(
objetivum (str): _description_
"""

data_sorted = self._data_sort(fonti)
# data_sorted = self._data_sort(fonti)
data_sorted = hxltm__data_sort(
fonti, ['#item+rem+i_qcc+is_zxxx+ix_xyadhxltrivio'])

# print(data_sorted[0:10])

Expand Down
52 changes: 52 additions & 0 deletions officina/999999999/0/L999999999_0.py
Original file line number Diff line number Diff line change
Expand Up @@ -5393,6 +5393,58 @@ def hxltm__data_referentibus(
return ''


def hxltm__data_sort(fonti: str, sortkeys: list = None) -> list:
"""hxltm__data_sort sort contents of HXLTM on disk
Load all data into memory. Return full List[List]. Header first row
Args:
fonti (str): path to file
sortkeys (list, optional): List of keys to sort. Defaults to None.
Returns:
list: sorted data
"""

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 resultatum


def hxltm__concat(
# al1: str, b2: str,
significatus: dict,
Expand Down

0 comments on commit 3da0784

Please sign in to comment.