Browse Source

working gooey version with progress bar

master
Holger Frey 5 years ago
parent
commit
6c1cb177f6
  1. 29
      sartorius_logger/__init__.py
  2. 10
      sartorius_logger/parsers.py

29
sartorius_logger/__init__.py

@ -91,6 +91,16 @@ def no_progress_bar(iterator): @@ -91,6 +91,16 @@ def no_progress_bar(iterator):
"""" as stub function for not displaying a progress bar """
return iterator
def gui_progress_factory(settings):
"""" as stub function for not displaying a progress bar """
total = settings.measurements
print(f"measuring every {settings.interval.value}{settings.interval.unit} for {settings.duration.value}{settings.duration.unit}")
def gui_progress(iterator):
for i in iterator:
print(f"measurement {i} of {total}")
yield i
print(f"measurement {total} of {total}")
return gui_progress
def _get_log_file_path(settings):
""" constructs the path to the log file """
@ -102,11 +112,8 @@ def _get_log_file_path(settings): @@ -102,11 +112,8 @@ def _get_log_file_path(settings):
def _log_measurement_info(logger, settings):
""" logs all measurement info """
nr_of_measurements = 1 + (
settings.duration.seconds // settings.interval.seconds
)
measurement_info = {
"Measurements": nr_of_measurements,
"Measurements": settings.measurements,
"Duration": f"{settings.duration.value}{settings.duration.unit}",
"Interval": f"{settings.interval.value}{settings.interval.unit}",
"Com-Port": settings.port,
@ -148,13 +155,12 @@ def measure_series(settings, progress_bar=no_progress_bar, data_logger=None): @@ -148,13 +155,12 @@ def measure_series(settings, progress_bar=no_progress_bar, data_logger=None):
"Measured Data", [headers], append_empty_line=False
)
nr_of_measurements = measurement_info["Measurements"]
for i in progress_bar(range(1, nr_of_measurements)):
for i in progress_bar(range(1, settings.measurements)):
data = _measure_and_log(i, conn, logger)
data_collection.append(data)
time.sleep(settings.interval.seconds)
data = _measure_and_log(nr_of_measurements, conn, logger)
data = _measure_and_log(settings.measurements, conn, logger)
data_collection.append(data)
data_df = pandas.DataFrame(data_collection).set_index("time")
@ -181,11 +187,16 @@ def cli(): @@ -181,11 +187,16 @@ def cli():
)
export_as_excel(result)
@Gooey(program_name="SartoriusLogger")
@Gooey(program_name="SartoriusLogger",
progress_regex="^measurement (?P<current>\d+) of (?P<total>\d+)",
progress_expr="current / total * 100"
)
def gui():
settings = parse_gui_arguments()
log_file_path = _get_log_file_path(settings)
gpb = gui_progress_factory(settings)
result = measure_series(
settings, progress_bar=tqdm, data_logger=DataLogger(log_file_path)
settings, progress_bar=gpb, data_logger=DataLogger(log_file_path)
)
export_as_excel(result)

10
sartorius_logger/parsers.py

@ -14,7 +14,7 @@ TIME_UNIT_FACTORS = { @@ -14,7 +14,7 @@ TIME_UNIT_FACTORS = {
ParsedDuration = namedtuple("ParsedDuration", ["value", "unit", "seconds"])
Settings = namedtuple(
"Settings", ["duration", "interval", "directory", "port"]
"Settings", ["duration", "interval", "directory", "port", "measurements"]
)
@ -91,12 +91,16 @@ def _normalize_cli_arguments(raw_arguments): @@ -91,12 +91,16 @@ def _normalize_cli_arguments(raw_arguments):
# directory stuff
dir_path = _check_output_directory_path(raw_arguments.output)
return Settings(duration, interval, dir_path, raw_arguments.port)
measurements = 1 + (
duration.seconds // interval.seconds
)
return Settings(duration, interval, dir_path, raw_arguments.port, measurements)
def _check_output_directory_path(raw_path):
""" returns the absolue path of the output directory
s
The desktop path (~/Desktop) is considered the default directory. If a
relative path is provided, it is considered relative to the desktop.
"""

Loading…
Cancel
Save