From 2d0f91c5c93f2c9412907efec997780b657243d1 Mon Sep 17 00:00:00 2001 From: Xevion Date: Sun, 11 Aug 2019 03:26:09 -0500 Subject: [PATCH] reverseOrder configuration overhaul --- README.md | 9 +++++++++ __pycache__/fusion.cpython-37.pyc | Bin 0 -> 3557 bytes config.json | 15 ++++++++------- fusion.py | 30 ++++++++++++++++++++---------- main.py | 4 ++++ 5 files changed, 41 insertions(+), 17 deletions(-) create mode 100644 __pycache__/fusion.cpython-37.pyc create mode 100644 main.py diff --git a/README.md b/README.md index 489d1a9..a525aac 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,15 @@ The `elements` portion refers to the scores of each element, each being the atom --- +`reverseIndividualOrder` refers to whether or not the program should reverse the output of the lists so that individual list printouts should have elements with higher scores + +--- + +`reverseOrder` refers to the order in which the list of lists is sorted, `False` being longer lists at the top and `True` being shorter lists at the top, and vice-verse for the bottom. + +--- + + `noNegatives` refers to whether it should filter out elements that have a negative score (ie. while using default configs, filter out elements without a score set) A set of elements with the score (-1, 5) would get filtered out, while a set with the scores (78, 12) would not. diff --git a/__pycache__/fusion.cpython-37.pyc b/__pycache__/fusion.cpython-37.pyc new file mode 100644 index 0000000000000000000000000000000000000000..ebafa185640b945f9f87e3f86218a13f5b228bdb GIT binary patch literal 3557 zcmbVP&u=706|So8>G|QY*PbjJ8zIsJfjwk1!7C(CWK77iL~xj_WPy^7S7e7xu*Ws^^!Dvj@iNs_Lrhs;}Pr-uKGy zudY@YelP#?;j@3PF!mL_%zgzl-ouk#qmWGUE(`LS2i(4kK-k&|99z3VL9tVBTvYtj zlWdDgF%f~M#JHr&%9GBOnDC$?U0L{?1uN2%MbuSUl4aDZvLaVdugR)hMSV}M$$O~R z<+|KJy&?GltJhut4Qmco+DY6Aj~l0H5@%euId$VlwS(s|o^&0B0rD+o_>f(p#tNdD zl~h+nDmH0dWL~~d=A=f~c~+bb{e$TuzJ9r{-aUM(lVjbAqA)%_e0pI{lKAig6)WB9 z9(MX^n8a^)!qnF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ERwg| z<6htBALA`6^yvDjN!*ak5Tr^@g*7PWxef7u3qt17ra!?aDQPCdU4m{9Yus}*d9+^3 zM3Uk^h>J9E=^qlkh2EeHl|dLNb#65vb9*gwlJD$xla|cfq^DxLyZxsiS9y{+n_euv qZ4}#0mM~dYSVbu9MTzWp)jp9ZC8638_xZXgIruA<+|pX= 1 and element <= 118: + return mdv.element(element) + raise ValueError(f'Unknown Element Atomic Number \'{element}\'') elif re.match(r'\w{1,2}', element): try: return mdv.element(element.strip().title()) except: - raise ValueError('Unknown Element \'{}\''.format(element)) + raise ValueError(f'Unknown Element \'{element}\'') else: - raise ValueError('Unknown Element Format \'{}\''.format(element)) + raise ValueError(f'Unknown Element Format \'{element}\'') def bestSelection(select): select = select.atomic_number @@ -42,14 +46,20 @@ def bestSelection(select): # Filter out elements that do not meet the minimum/maximum set posi = list(filter(lambda item : scoreSum(item)[0] >= config['minimumScore'], posi)) # Sort the elements by the sum of their scores - posi.sort(key=lambda item : scoreSum(item), reverse=not config['reverseSorting']) - + posi.sort(key=lambda item : scoreSum(item), reverse=not config['reverseInnerOrder']) + # Build the strings string1 = '[Best Elements for Element {}, {}]'.format(select, mdv.element(select).name if config['fullPrint'] else mdv.element(select.symbol)) string2 = '\n'.join([formatting(element1, element2) for element1, element2 in posi]) return string1, string2 or '\t{No elements matched the configuration specified}' -selection = input("Choose elements, delimited by whitespace and/or punctuation...\n") -selection = [getElement(e) for e in selection.split()] -print('\n\n'.join( - sorted(['{}\n{}'.format(*bestSelection(E)) for E in selection], key=lambda string : len(string.split('\n'))) -)) \ No newline at end of file +# Driver code +def main(): + selection = input("Choose elements, delimited by whitespace and/or punctuation...\n") + selection = [getElement(e) for e in selection.split()] + print('\n\n'.join( + sorted(['{}\n{}'.format(*bestSelection(E)) for E in selection], + key=lambda string : len([line for line in string.split('\n') if + # hacky solution for reverseOrder config option + '\t{No elements matched the configuration specified}' not in line]), + reverse=not config['reverseOrder']) + )) \ No newline at end of file diff --git a/main.py b/main.py new file mode 100644 index 0000000..3a996c4 --- /dev/null +++ b/main.py @@ -0,0 +1,4 @@ +if __name__ == "__main__": + import sys + from fusion import main + sys.exit(main()) \ No newline at end of file