From 6865d0f372d4fa5ff8a0dd51be6eed74c6168a84 Mon Sep 17 00:00:00 2001 From: Xevion Date: Sun, 11 Aug 2019 03:30:25 -0500 Subject: [PATCH] simplify to lambdas --- README.md | 8 ++++++++ fusion.py | 16 +++++++--------- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index a525aac..8977ceb 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/fusion.py b/fusion.py index 6661841..599cdc9 100644 --- a/fusion.py +++ b/fusion.py @@ -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']) )) \ No newline at end of file