aboutsummaryrefslogtreecommitdiff
path: root/quality_control/utils.py
diff options
context:
space:
mode:
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__