mirror of
https://github.com/Xevion/fusion-fission-choices.git
synced 2025-12-05 23:15:06 -06:00
reverseOrder configuration overhaul
This commit is contained in:
@@ -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)
|
`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.
|
A set of elements with the score (-1, 5) would get filtered out, while a set with the scores (78, 12) would not.
|
||||||
|
|||||||
BIN
__pycache__/fusion.cpython-37.pyc
Normal file
BIN
__pycache__/fusion.cpython-37.pyc
Normal file
Binary file not shown.
15
config.json
15
config.json
@@ -11,7 +11,7 @@
|
|||||||
"9": -1,
|
"9": -1,
|
||||||
"10": -1,
|
"10": -1,
|
||||||
"11": -1,
|
"11": -1,
|
||||||
"12": -1,
|
"12": 3,
|
||||||
"13": -1,
|
"13": -1,
|
||||||
"14": -1,
|
"14": -1,
|
||||||
"15": -1,
|
"15": -1,
|
||||||
@@ -19,22 +19,22 @@
|
|||||||
"17": -1,
|
"17": -1,
|
||||||
"18": -1,
|
"18": -1,
|
||||||
"19": -1,
|
"19": -1,
|
||||||
"20": -1,
|
"20": 3,
|
||||||
"21": -1,
|
"21": -1,
|
||||||
"22": -1,
|
"22": -1,
|
||||||
"23": -1,
|
"23": -1,
|
||||||
"24": -1,
|
"24": -1,
|
||||||
"25": -1,
|
"25": -1,
|
||||||
"26": -1,
|
"26": -1,
|
||||||
"27": -1,
|
"27": 1,
|
||||||
"28": -1,
|
"28": -1,
|
||||||
"29": -1,
|
"29": -1,
|
||||||
"30": -1,
|
"30": -1,
|
||||||
"31": -1,
|
"31": -1,
|
||||||
"32": -1,
|
"32": -1,
|
||||||
"33": -1,
|
"33": 1,
|
||||||
"34": -1,
|
"34": 1,
|
||||||
"35": -1,
|
"35": 1,
|
||||||
"36": -1,
|
"36": -1,
|
||||||
"37": -1,
|
"37": -1,
|
||||||
"38": -1,
|
"38": -1,
|
||||||
@@ -120,7 +120,8 @@
|
|||||||
"118": -1
|
"118": -1
|
||||||
},
|
},
|
||||||
"minimumScore": 1,
|
"minimumScore": 1,
|
||||||
"reverseSorting": false,
|
"reverseInnerOrder": false,
|
||||||
|
"reverseOrder" : false,
|
||||||
"noNegatives" : true,
|
"noNegatives" : true,
|
||||||
"fullPrint" : true
|
"fullPrint" : true
|
||||||
}
|
}
|
||||||
30
fusion.py
30
fusion.py
@@ -19,16 +19,20 @@ def formatting(e1, e2):
|
|||||||
def hasNegatives(item):
|
def hasNegatives(item):
|
||||||
return score(item[0]) < 0 or score(item[1]) < 0
|
return score(item[0]) < 0 or score(item[1]) < 0
|
||||||
|
|
||||||
|
# get the element based on two letters or a digit and attempt to map it to a number
|
||||||
def getElement(element):
|
def getElement(element):
|
||||||
if re.match(r'\d+', element):
|
if re.match(r'\d+', element):
|
||||||
return mdv.element(int(element))
|
element = int(element)
|
||||||
|
if element >= 1 and element <= 118:
|
||||||
|
return mdv.element(element)
|
||||||
|
raise ValueError(f'Unknown Element Atomic Number \'{element}\'')
|
||||||
elif re.match(r'\w{1,2}', element):
|
elif re.match(r'\w{1,2}', element):
|
||||||
try:
|
try:
|
||||||
return mdv.element(element.strip().title())
|
return mdv.element(element.strip().title())
|
||||||
except:
|
except:
|
||||||
raise ValueError('Unknown Element \'{}\''.format(element))
|
raise ValueError(f'Unknown Element \'{element}\'')
|
||||||
else:
|
else:
|
||||||
raise ValueError('Unknown Element Format \'{}\''.format(element))
|
raise ValueError(f'Unknown Element Format \'{element}\'')
|
||||||
|
|
||||||
def bestSelection(select):
|
def bestSelection(select):
|
||||||
select = select.atomic_number
|
select = select.atomic_number
|
||||||
@@ -42,14 +46,20 @@ def bestSelection(select):
|
|||||||
# Filter out elements that do not meet the minimum/maximum set
|
# Filter out elements that do not meet the minimum/maximum set
|
||||||
posi = list(filter(lambda item : scoreSum(item)[0] >= config['minimumScore'], posi))
|
posi = list(filter(lambda item : scoreSum(item)[0] >= config['minimumScore'], posi))
|
||||||
# Sort the elements by the sum of their scores
|
# 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))
|
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 '\t{No elements matched the configuration specified}'
|
||||||
|
|
||||||
selection = input("Choose elements, delimited by whitespace and/or punctuation...\n")
|
# Driver code
|
||||||
selection = [getElement(e) for e in selection.split()]
|
def main():
|
||||||
print('\n\n'.join(
|
selection = input("Choose elements, delimited by whitespace and/or punctuation...\n")
|
||||||
sorted(['{}\n{}'.format(*bestSelection(E)) for E in selection], key=lambda string : len(string.split('\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'])
|
||||||
|
))
|
||||||
Reference in New Issue
Block a user