From a69953c75c8b9ef6846be4c6902295ffe760efd6 Mon Sep 17 00:00:00 2001 From: Sven Augustin Date: Tue, 3 Nov 2020 17:56:22 +0100 Subject: [PATCH] refactored common logic for printing the outcome; incl. case where nothing needs to be done --- commands.py | 16 +++------------- utils/consts.py | 1 + utils/printing.py | 16 +++++++++++++++- 3 files changed, 19 insertions(+), 14 deletions(-) diff --git a/commands.py b/commands.py index 0824849..8f7d9b3 100644 --- a/commands.py +++ b/commands.py @@ -7,7 +7,7 @@ from utils.df import drop_col, compare_dfs, count_true from utils.epics import DataGetter, DataPutter from utils.execute import parallel, serial from utils.fileio import load_config, load_csv, store_csv -from utils.printing import print_good, print_bad, itemize +from utils.printing import print_good, print_bad, print_outcome, itemize from utils.seq import is_empty @@ -35,12 +35,7 @@ def run_check(clargs): # print(df.dtypes) connected = df["connected"] - if connected.all(): - print_good("all connections OK") - else: - ntotal = len(connected) - ngood = count_true(connected) - print_bad(f"only {ngood}/{ntotal} connections OK") + print_outcome(connected, "connections OK") output = clargs.output if not output: @@ -104,12 +99,7 @@ def run_goto(clargs): status = run(put_data, pvs, values) status = np.array(status) - if status.all(): - print_good("all puts successful") - else: - ntotal = len(status) - ngood = count_true(status) - print_bad(f"only {ngood}/{ntotal} puts successful") + print_outcome(status, "puts successful") diff --git a/utils/consts.py b/utils/consts.py index a09683d..407302e 100644 --- a/utils/consts.py +++ b/utils/consts.py @@ -11,6 +11,7 @@ MSG_SUCCESS = "OK" SYM_GOOD = "👍" SYM_BAD = "💔" +SYM_NOTHING = "😱" diff --git a/utils/printing.py b/utils/printing.py index 5b25f79..0816a8a 100644 --- a/utils/printing.py +++ b/utils/printing.py @@ -1,6 +1,20 @@ -from .consts import SYM_GOOD, SYM_BAD +from .consts import SYM_NOTHING, SYM_GOOD, SYM_BAD +from .seq import is_empty +def print_outcome(state, units): + if is_empty(state): + print_nothing("nothing to do") + elif all(state): + print_good(f"all {units}") + else: + ntotal = len(state) + ngood = count_true(state) + print_bad(f"only {ngood}/{ntotal} {units}") + +def print_nothing(*args, **kwargs): + return print(SYM_NOTHING, *args, **kwargs) + def print_good(*args, **kwargs): return print(SYM_GOOD, *args, **kwargs)