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

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