simplify to lambdas

This commit is contained in:
Xevion
2019-08-11 03:30:25 -05:00
parent 2d0f91c5c9
commit 6865d0f372
2 changed files with 15 additions and 9 deletions

View File

@@ -8,6 +8,14 @@
As of now, I have only implemented the fusion part, since it's drastically easier. The fission module for this will come later, if I decide I need it, but since the fission recipes come in JEI automatically... I'll be okay.
## To-do
* Implement Fission
* Better configuration options
* Automatic scoring system
## Configuration Options
The `elements` portion refers to the scores of each element, each being the atomic number of the element.

View File

@@ -1,14 +1,15 @@
import os, sys, json, re, mendeleev as mdv
# Configuration reading
path = os.path.join(sys.path[0], 'config.json')
config = json.load(open(path, 'r'))
def score(element):
return config['elements'][str(element)]
def scoreSum(item):
return (score(item[0]) + score(item[1])), item
# Lambdas
score = lambda element : config['elements'][str(element)]
scoreSum = lambda item : ((score(item[0]) + score(item[1])), item)
hasNegatives = lambda item : score(item[0]) < 0 or score(item[1]) < 0
# Formatting for a single element report line
def formatting(e1, e2):
e1, e2 = mdv.element(e1), mdv.element(e2)
return '\t[{} {}] + [{} {}]'.format(e1.symbol if not config['fullPrint'] else e1.name,
@@ -16,9 +17,6 @@ def formatting(e1, e2):
e2.symbol if not config['fullPrint'] else e2.name,
e2.atomic_number)
def hasNegatives(item):
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):
if re.match(r'\d+', element):
@@ -58,8 +56,8 @@ def main():
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
key=lambda string : len([line for line in string.split('\n') if
'\t{No elements matched the configuration specified}' not in line]),
reverse=not config['reverseOrder'])
))