aboutsummaryrefslogtreecommitdiff
path: root/quality_control/utils.py
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2022-05-19 10:25:18 +0300
committerFrederick Muriuki Muriithi2022-05-19 15:23:47 +0300
commit27f6e9e28f2a3244bdd00336cf918de97b2ceed6 (patch)
tree35ad7aeea324b0cbe60c44d652b4a5387321f4bd /quality_control/utils.py
parent6865d8621e6fadb915813951068ee950c781ee0d (diff)
downloadgn-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/utils.py')
-rw-r--r--quality_control/utils.py21
1 files changed, 21 insertions, 0 deletions
diff --git a/quality_control/utils.py b/quality_control/utils.py
new file mode 100644
index 0000000..0072608
--- /dev/null
+++ b/quality_control/utils.py
@@ -0,0 +1,21 @@
+"""Utilities that might be useful elsewhere."""
+
+from collections import namedtuple
+
+ProgressIndicator = namedtuple(
+ "ProgressIndicator", ("filesize", "processedsize", "currentline", "percent"))
+
+def make_progress_calculator(filesize: int):
+ """
+ Returns a function that takes two arguments, `linenumber` and `linetext` and
+ return a `ProgressIndicator` object with the computed progress.
+ """
+ processedsize = 0
+ def __calculator__(linenumber: int, linetext: str) -> ProgressIndicator:
+ nonlocal processedsize
+ processedsize = processedsize + len(linetext)
+ return ProgressIndicator(
+ filesize, processedsize, linenumber,
+ ((processedsize/filesize) * 100))
+
+ return __calculator__