mirror of
https://github.com/Xevion/fusion-fission-choices.git
synced 2025-12-08 12:07:17 -06:00
eliminateEmpty config
This commit is contained in:
@@ -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
|
`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.
|
||||||
Binary file not shown.
@@ -123,5 +123,6 @@
|
|||||||
"reverseInnerOrder": false,
|
"reverseInnerOrder": false,
|
||||||
"reverseOrder" : false,
|
"reverseOrder" : false,
|
||||||
"noNegatives" : true,
|
"noNegatives" : true,
|
||||||
"fullPrint" : true
|
"fullPrint" : true,
|
||||||
|
"eliminateEmpty" : false
|
||||||
}
|
}
|
||||||
19
fusion.py
19
fusion.py
@@ -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(
|
||||||
|
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
|
# hacky solution for reverseOrder config option
|
||||||
key=lambda string : len([line for line in string.split('\n') if
|
key=lambda item : len(item[1]) if item[1] != noElements else 0,
|
||||||
'\t{No elements matched the configuration specified}' not in line]),
|
|
||||||
reverse=not config['reverseOrder'])
|
reverse=not config['reverseOrder'])
|
||||||
|
)
|
||||||
|
)
|
||||||
))
|
))
|
||||||
Reference in New Issue
Block a user