From be0e5005d5eaa71f1f0878f6f0a6952b678d4e36 Mon Sep 17 00:00:00 2001 From: Sven Augustin Date: Tue, 3 Nov 2020 18:17:48 +0100 Subject: [PATCH] refactored common logic for printing ignored entries --- commands.py | 17 +++-------------- utils/printing.py | 9 +++++++++ 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/commands.py b/commands.py index 8f7d9b3..0911ee7 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, print_outcome, itemize +from utils.printing import print_good, print_bad, print_outcome, print_ignored from utils.seq import is_empty @@ -70,24 +70,13 @@ def run_goto(clargs): if clargs.ignore_alarm: which = (df["status"] == 0) & (df["severity"] == 0) if not clargs.quiet: - all_names = df.index - ignored = all_names[~which] - if not is_empty(ignored): - print("ignored due to alarm state:") - print(itemize(ignored)) - print() + print_ignored(df, which, "alarm state") df = df.loc[which] df = df["value"] if not clargs.quiet: - which = df.notnull() - all_names = df.index - ignored = all_names[~which] - if not is_empty(ignored): - print("ignored due to NaN value:") - print(itemize(ignored)) - print() + print_ignored(df, df.notnull(), "NaN value") df.dropna(inplace=True) #TODO: can NaN be a valid value? values = df.values diff --git a/utils/printing.py b/utils/printing.py index 0816a8a..27464c5 100644 --- a/utils/printing.py +++ b/utils/printing.py @@ -1,4 +1,5 @@ from .consts import SYM_NOTHING, SYM_GOOD, SYM_BAD +from .df import count_true from .seq import is_empty @@ -22,6 +23,14 @@ def print_bad(*args, **kwargs): return print(SYM_BAD, *args, **kwargs) +def print_ignored(df, which, reason): #TODO: should df be the argument or df.index? + all_names = df.index + ignored = all_names[~which] + if not is_empty(ignored): + print(f"ignored due to {reason}:") + print(itemize(ignored)) + print() + def itemize(iterable, bullet="•"): if not bullet.endswith(" "): bullet += " "