eliminateEmpty config

This commit is contained in:
Xevion
2019-08-11 03:45:55 -05:00
parent 6865d0f372
commit 9dc18ba8df
4 changed files with 24 additions and 8 deletions

View File

@@ -41,4 +41,8 @@ A set of elements with the score (-1, 5) would get filtered out, while a set wit
--- ---
`fullPrint` refers to whether it should print out the Symbol or the Name of the Element `fullPrint` refers to whether it should print out the Symbol or the Name of the Element
---
`eliminateEmpty` refers to whether the program should remove specified elements if they contained no matching tuples.

View File

Binary file not shown.

View File

@@ -123,5 +123,6 @@
"reverseInnerOrder": false, "reverseInnerOrder": false,
"reverseOrder" : false, "reverseOrder" : false,
"noNegatives" : true, "noNegatives" : true,
"fullPrint" : true "fullPrint" : true,
"eliminateEmpty" : false
} }

View File

@@ -4,6 +4,9 @@ import os, sys, json, re, mendeleev as mdv
path = os.path.join(sys.path[0], 'config.json') path = os.path.join(sys.path[0], 'config.json')
config = json.load(open(path, 'r')) config = json.load(open(path, 'r'))
# Constants
noElements = '\t{No elements matched the configuration specified}'
# Lambdas # Lambdas
score = lambda element : config['elements'][str(element)] score = lambda element : config['elements'][str(element)]
scoreSum = lambda item : ((score(item[0]) + score(item[1])), item) scoreSum = lambda item : ((score(item[0]) + score(item[1])), item)
@@ -48,16 +51,24 @@ def bestSelection(select):
# Build the strings # Build the strings
string1 = '[Best Elements for Element {}, {}]'.format(select, mdv.element(select).name if config['fullPrint'] else mdv.element(select.symbol)) 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]) string2 = '\n'.join([formatting(element1, element2) for element1, element2 in posi])
return string1, string2 or '\t{No elements matched the configuration specified}' return string1, string2 or noElements
# Driver code # Driver code
def main(): def main():
selection = input("Choose elements, delimited by whitespace and/or punctuation...\n") selection = input("Choose elements, delimited by whitespace and/or punctuation...\n")
selection = [getElement(e) for e in selection.split()] selection = [getElement(e) for e in selection.split()]
# No one:
# No one at all:
# Me:
print('\n\n'.join( print('\n\n'.join(
sorted(['{}\n{}'.format(*bestSelection(E)) for E in selection], map(
# hacky solution for reverseOrder config option lambda item : '{}\n{}'.format(item[0], item[1]),
key=lambda string : len([line for line in string.split('\n') if filter(
'\t{No elements matched the configuration specified}' not in line]), lambda item : (item[1] != noElements) if config['eliminateEmpty'] else True,
reverse=not config['reverseOrder']) sorted([bestSelection(E) for E in selection],
# hacky solution for reverseOrder config option
key=lambda item : len(item[1]) if item[1] != noElements else 0,
reverse=not config['reverseOrder'])
)
)
)) ))