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):
"""" as stub function for not displaying a progress bar """ """" as stub function for not displaying a progress bar """
return iterator 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): def _get_log_file_path(settings):
""" constructs the path to the log file """ """ constructs the path to the log file """
@ -102,11 +112,8 @@ def _get_log_file_path(settings):
def _log_measurement_info(logger, settings): def _log_measurement_info(logger, settings):
""" logs all measurement info """ """ logs all measurement info """
nr_of_measurements = 1 + (
settings.duration.seconds // settings.interval.seconds
)
measurement_info = { measurement_info = {
"Measurements": nr_of_measurements, "Measurements": settings.measurements,
"Duration": f"{settings.duration.value}{settings.duration.unit}", "Duration": f"{settings.duration.value}{settings.duration.unit}",
"Interval": f"{settings.interval.value}{settings.interval.unit}", "Interval": f"{settings.interval.value}{settings.interval.unit}",
"Com-Port": settings.port, "Com-Port": settings.port,
@ -148,13 +155,12 @@ def measure_series(settings, progress_bar=no_progress_bar, data_logger=None):
"Measured Data", [headers], append_empty_line=False "Measured Data", [headers], append_empty_line=False
) )
nr_of_measurements = measurement_info["Measurements"] for i in progress_bar(range(1, settings.measurements)):
for i in progress_bar(range(1, nr_of_measurements)):
data = _measure_and_log(i, conn, logger) data = _measure_and_log(i, conn, logger)
data_collection.append(data) data_collection.append(data)
time.sleep(settings.interval.seconds) 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_collection.append(data)
data_df = pandas.DataFrame(data_collection).set_index("time") data_df = pandas.DataFrame(data_collection).set_index("time")
@ -181,11 +187,16 @@ def cli():
) )
export_as_excel(result) 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(): def gui():
settings = parse_gui_arguments() settings = parse_gui_arguments()
log_file_path = _get_log_file_path(settings) log_file_path = _get_log_file_path(settings)
gpb = gui_progress_factory(settings)
result = measure_series( 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) export_as_excel(result)

10
sartorius_logger/parsers.py

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

Loading…
Cancel
Save