aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/argaze/utils/MiscFeatures.py85
1 files changed, 62 insertions, 23 deletions
diff --git a/src/argaze/utils/MiscFeatures.py b/src/argaze/utils/MiscFeatures.py
index a06d82f..7971167 100644
--- a/src/argaze/utils/MiscFeatures.py
+++ b/src/argaze/utils/MiscFeatures.py
@@ -1,25 +1,30 @@
#!/usr/bin/env python
-""" """
+"""Miscellaneous class and functions used in utils script."""
__author__ = "Théo de la Hogue"
__credits__ = []
__copyright__ = "Copyright 2023, Ecole Nationale de l'Aviation Civile (ENAC)"
__license__ = "BSD"
-import time
+from typing import Tuple
+import time
+import types
def printProgressBar (iteration:int, total:int, prefix:str = '', suffix:str = '', decimals:int = 1, length:int = 100, fill:str = '█', printEnd:str = "\r"):
- """Print iterations progress.
+ """
+ Print iterations progress.
Call in a loop to create terminal progress bar.
- - current iteration
- - total iterations
- - prefix string
- - suffix string
- - positive number of decimals in percent complete
- - character length of bar
- - bar fill character
- - end character (e.g. "\r", "\r\n")
+
+ Parameters:
+ iteration: current iteration
+ total: total iterations
+ prefix: string to print before progress bar
+ suffix: string to print after progress bar
+ decimals: positive number of decimals in percent complete
+ length: character length of bar
+ fill: bar fill character
+ printEnd: end character (e.g. \\r, \\r\\n)
"""
percent = ("{0:." + str(decimals) + "f}").format(100 * (iteration / float(total)))
filledLength = int(length * iteration // total)
@@ -30,10 +35,16 @@ def printProgressBar (iteration:int, total:int, prefix:str = '', suffix:str = ''
if iteration == total:
print()
-def importFromTestPackage(module: str):
- """Import module from ArGaze test package.
+def importFromTestPackage(module: str) -> types.ModuleType:
+ """
+ Import module from ArGaze test package.
+
+ Parameters:
+ module: module name <Module> into ArGaze package
+
Returns:
- a module named <Module>Test"""
+ module named <Module>Test
+ """
import argaze
import importlib.util
@@ -51,7 +62,10 @@ def importFromTestPackage(module: str):
return TestModule
class ExitSignalHandler():
- """Handle exit event"""
+ """
+ Handle exit event
+ """
+
def __init__(self):
import signal
@@ -68,25 +82,42 @@ class ExitSignalHandler():
for sig in ('TERM', 'HUP', 'INT'):
signal.signal(getattr(signal, 'SIG'+sig), __on_exit_signal)
- def status(self):
+ def status(self) -> bool:
+ """
+ Get exit status.
+
+ Returns:
+ exit status
+ """
return __exit_event.is_set()
class TimeProbe():
- """Assess temporal performance"""
+ """
+ Assess temporal performance.
+ """
def __init__(self):
self.start()
def start(self):
- """Start chronometer."""
+ """
+ Start chronometer.
+ """
self.__last_time = time.perf_counter()
self.__lap_counter = 0
self.__elapsed_time = 0
- def lap(self):
- """Get the last lap time, number of laps and total elapsed time in millisecond."""
+ def lap(self) -> Tuple[float, int, float]:
+ """
+ Get lap info.
+
+ Returns:
+ last lap time (millisecond)
+ number of laps
+ total elapsed time (millisecond)
+ """
lap_time = time.perf_counter() - self.__last_time
@@ -96,14 +127,22 @@ class TimeProbe():
return lap_time * 1e3, self.__lap_counter, self.__elapsed_time * 1e3
- def end(self):
- """Stop chronometer and get elapsed time in millisecond."""
+ def end(self) -> float:
+ """
+ Stop chronometer
+
+ Returns:
+ elapsed time (millisecond)
+ """
self.__elapsed_time += time.perf_counter() - self.__last_time
return self.__elapsed_time * 1e3, self.__lap_counter
def restart(self):
-
+ """
+ Restart chronometer.
+ """
+
self.start()