diff options
author | Frederick Muriuki Muriithi | 2022-05-19 10:25:18 +0300 |
---|---|---|
committer | Frederick Muriuki Muriithi | 2022-05-19 15:23:47 +0300 |
commit | 27f6e9e28f2a3244bdd00336cf918de97b2ceed6 (patch) | |
tree | 35ad7aeea324b0cbe60c44d652b4a5387321f4bd /quality_control/parsing.py | |
parent | 6865d8621e6fadb915813951068ee950c781ee0d (diff) | |
download | gn-uploader-27f6e9e28f2a3244bdd00336cf918de97b2ceed6.tar.gz |
Extract progress indication from the parsing
Since progress indication is not part of the parsing, this commit
extracts the progress indication into functions with well defined
input arguments that hide the progress indication logic from the
parsing function.
Diffstat (limited to 'quality_control/parsing.py')
-rw-r--r-- | quality_control/parsing.py | 12 |
1 files changed, 3 insertions, 9 deletions
diff --git a/quality_control/parsing.py b/quality_control/parsing.py index 655b98a..5b1809b 100644 --- a/quality_control/parsing.py +++ b/quality_control/parsing.py @@ -65,7 +65,7 @@ def se_errors(line_number, fields): def collect_errors( filepath: str, filetype: FileType, strains: list, - updater: Union[Callable, None] = None) -> Generator: + update_progress: Union[Callable, None] = None) -> Generator: """Run checks against file and collect all the errors""" errors = tuple() def __process_errors__(line_number, line, error_checker_fn, errors = tuple()): @@ -78,8 +78,6 @@ def collect_errors( return errors + tuple(error for error in errs if error is not None) return errors + (errs,) - filesize = os.stat(filepath).st_size - processed_size = 0 with open(filepath, encoding="utf-8") as input_file: for line_number, line in enumerate(input_file, start=1): if line_number == 1: @@ -96,12 +94,8 @@ def collect_errors( errors): yield error - processed_size = processed_size + len(line) - if updater: - updater({ - "line_number": line_number, - "percent": (processed_size/filesize) * 100 - }) + if update_progress: + update_progress(line_number, line) def take(iterable: Iterable, num: int) -> list: """Take at most `num` items from `iterable`.""" |