From 03ec5319ad97e55e45d9efef36b4d600897c02cb Mon Sep 17 00:00:00 2001 From: Emerson Rocha Date: Sun, 17 Apr 2022 22:25:53 -0300 Subject: [PATCH] 1603_1.py (#29): improved natural sorting of Numerordinatio (the codex numbers) --- officinam/999999999/0/1603_1.py | 75 ++++++++++++++++++++++++++++++++- 1 file changed, 74 insertions(+), 1 deletion(-) diff --git a/officinam/999999999/0/1603_1.py b/officinam/999999999/0/1603_1.py index 74b668d..0ec3cb3 100755 --- a/officinam/999999999/0/1603_1.py +++ b/officinam/999999999/0/1603_1.py @@ -478,6 +478,35 @@ def qhxl_attr_2_bcp47(hxlatt: str): return resultatum +def sort_numerodinatio_clavem(item): + """sort_numerodinatio_clavem + + Hotfix to force order somewhat intuitive order with Numerordinatio keys. + Coerces each part to it's numeric value and group by upper orderring + + Args: + item (_type_): _description_ + + Returns: + _type_: _description_ + """ + # Use case status['librarium'].items() + ordo_simples = 0 + # codex_crudum = item[0] + codex_crudum = item[0].split('_') + # ordo_simples = (100000 - int(codex_crudum[0])) * (10 ** 4) + ordo_simples = (int(codex_crudum[0]) * (1000 ** 3)) + + if len(codex_crudum) >= 2: + ordo_simples = ordo_simples + (int(codex_crudum[1]) * (1000 ** 2)) + if len(codex_crudum) >= 3: + ordo_simples = ordo_simples + (int(codex_crudum[2]) * (1000 ** 1)) + if len(codex_crudum) >= 4: + ordo_simples = ordo_simples + (int(codex_crudum[3]) * (1000 ** 0)) + + return ordo_simples + + def mathematica(quero: str, meta: str = '') -> bool: """mathematica @@ -3151,7 +3180,17 @@ def imprimere_in_markdown(self): status['status_quo']['summa']['concepta_non_unicum'])) paginae.append('') - for codex, item in status['librarium'].items(): + items_sorted = status['librarium'].items() + + # items_sorted = items_sorted.sort(key=sort_numerodinatio_clavem) + items_sorted = sorted(items_sorted, key=sort_numerodinatio_clavem) + + paginae.extend(self.imprimere_in_markdown_tabula_contentorum( + items_sorted + )) + + # for codex, item in status['librarium'].items(): + for codex, item in items_sorted: caveat_lector = self.imprimere_res_caveat_lector(item) corde = self.imprimere_res_methodi_ex_dictionariorum_corde(item) @@ -3161,6 +3200,20 @@ def imprimere_in_markdown(self): paginae.append('') + # # DEBUG + # paginae.append( + # '{0} {1} {2} {3}'.format( + # '1603_45_3', + # sort_numerodinatio_clavem(['1603_45_3', 'a']), + # '1603_44_101', + # sort_numerodinatio_clavem(['1603_44_101', 'a']) + # ) + # ) + + paginae.append('') + paginae.append('ยง {0}'.format(codex)) + paginae.append('') + paginae.append('- status_quo') paginae.append( ' - concepta: {0}'.format(item['status_quo']['summa']['concepta'])) @@ -3206,6 +3259,26 @@ def imprimere_in_markdown(self): # status, allow_unicode=True)] return paginae + def imprimere_in_markdown_tabula_contentorum(self, items_sorted): + paginae = [] + paginae.append('') + paginae.append('----') + paginae.append('**Tabula contentorum**') + for codex, item in items_sorted: + paginae.append( + '- {0} ' + 'C.{1} r.I.{2} r.L.{3}'.format( + codex, + item['status_quo']['summa']['concepta'], + item['status_quo']['summa']['res_interlingualibus'], + item['status_quo']['summa']['res_lingualibus'], + )) + + paginae.append('') + paginae.append('----') + paginae.append('') + return paginae + def imprimere_res_caveat_lector(self, item): if item and 'meta' in item and \ 'caveat_lector' in item['meta'] and \