Skip to content

Commit

Permalink
better csv for end_results and end_statistics
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasWeise committed Apr 26, 2024
1 parent 9587346 commit 100b4bb
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 7 deletions.
1 change: 1 addition & 0 deletions moptipy/evaluation/ecdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ def to_csv(self, file: str,
"""
path: Final[Path] = Path(file)
logger(f"Writing ECDF to CSV file {path!r}.")
path.ensure_parent_dir_exists()

with path.open_for_write() as out:
sep: Final[str] = CSV_SEPARATOR
Expand Down
10 changes: 8 additions & 2 deletions moptipy/evaluation/end_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,11 @@
num_to_str,
str_to_num,
)
from pycommons.types import check_int_range, check_to_int_range, type_error
from pycommons.types import (
check_int_range,
check_to_int_range,
type_error,
)

from moptipy.api.logging import (
FILE_SUFFIX,
Expand Down Expand Up @@ -559,6 +563,7 @@ def to_csv(results: Iterable[EndResult], file: str) -> Path:
"""
path: Final[Path] = Path(file)
logger(f"Writing end results to CSV file {path!r}.")
path.ensure_parent_dir_exists()
with path.open_for_write() as wt:
csv_write(data=sorted(results),
consumer=line_writer(wt),
Expand Down Expand Up @@ -633,7 +638,8 @@ def setup(self, data: Iterable[EndResult]) -> "CsvWriter":
:returns: this writer
"""
if self.__setup:
raise ValueError("CSV writer has already been set up.")
raise ValueError(
"EndResults CsvWriter has already been set up.")
self.__setup = True

no_encoding: bool = True
Expand Down
15 changes: 12 additions & 3 deletions moptipy/evaluation/end_statistics.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,12 @@
num_or_none_to_str,
str_to_num,
)
from pycommons.types import check_int_range, type_error, type_name_of
from pycommons.types import (
check_int_range,
reiterable,
type_error,
type_name_of,
)

from moptipy.api.logging import (
KEY_ALGORITHM,
Expand Down Expand Up @@ -839,6 +844,7 @@ def to_csv(data: EndStatistics | Iterable[EndStatistics],
"""
path: Final[Path] = Path(file)
logger(f"Writing end result statistics to CSV file {path!r}.")
path.ensure_parent_dir_exists()
with path.open_for_write() as wt:
csv_write(
data=[data] if isinstance(data, EndStatistics) else sorted(data),
Expand Down Expand Up @@ -1084,10 +1090,13 @@ def setup(self, data: Iterable[EndStatistics]) -> "CsvWriter":
:returns: this writer
"""
if self.__setup:
raise ValueError("CSV writer has already been set up.")
raise ValueError(
"EndStatistics CsvWriter has already been set up.")
self.__setup = True
checker: int = 127

data = reiterable(data)

checker: int = 127
for es in data:
if es.algorithm is not None:
self.__has_algorithm = True
Expand Down
1 change: 1 addition & 0 deletions moptipy/evaluation/ert.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ def to_csv(self, file: str,
"""
path: Final[Path] = Path(file)
logger(f"Writing ERT to CSV file {path!r}.")
path.ensure_parent_dir_exists()

with path.open_for_write() as out:
sep: Final[str] = CSV_SEPARATOR
Expand Down
1 change: 1 addition & 0 deletions moptipy/evaluation/progress.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ def to_csv(self, file: str,
"""
path: Final[Path] = Path(file)
logger(f"Writing progress object to CSV file {path!r}.")
path.ensure_parent_dir_exists()

with path.open_for_write() as out:
sep: Final[str] = CSV_SEPARATOR
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ psutil == 5.9.5

# pycommons offers many of the tools and utilities used in moptipy that are
# not related to optimization.
pycommons == 0.8.30
pycommons == 0.8.31

# scikit-learn is used to obtain some clusters of JSSP instances for our
# experiments.
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ install_requires =
matplotlib >= 3.8.0
pdfo >= 1.3.1
psutil >= 5.9.5
pycommons >= 0.8.30
pycommons >= 0.8.31
scikit-learn >= 1.3.1
scipy >= 1.11.3
packages = find:
Expand Down

0 comments on commit 100b4bb

Please sign in to comment.