Skip to content

Commit 473ca28

Browse files
Merge pull request #54 from NREL/hotfix/hive-config-override-output-suffix
modify HiveConfig to parameterize output directory suffix
2 parents 36d91a4 + 73f1569 commit 473ca28

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

hive/config/hive_config.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import os
66
from datetime import datetime
77
from pathlib import Path
8-
from typing import NamedTuple, Dict, Union, Tuple
8+
from typing import NamedTuple, Dict, Union, Tuple, Optional
99

1010
import pkg_resources
1111
import yaml
@@ -31,16 +31,28 @@ class HiveConfig(NamedTuple):
3131
scenario_output_directory: Path = Path("")
3232

3333
@classmethod
34-
def build(cls, scenario_file_path: Path, config: Dict = None) -> Union[Exception, HiveConfig]:
34+
def build(cls,
35+
scenario_file_path: Path,
36+
config: Dict = None,
37+
output_suffix: Optional[str] = datetime.now().strftime('%Y-%m-%d_%H-%M-%S')
38+
) -> Union[Exception, HiveConfig]:
39+
"""
40+
builds a hive config by reading from a scenario file. optionally append additional key/value
41+
pairs and modify the datetime convention for naming output directories.
42+
:param scenario_file_path: path to the file to load as a HiveConfig
43+
:param config: optional overrides to the default config values (Default: None)
44+
:param output_suffix: directory name suffix to append to sim_name (by default, timestamp for now)
45+
:return: a hive config or an error
46+
"""
3547
return ConfigBuilder.build(
3648
default_config={},
3749
required_config=(),
38-
config_constructor=lambda c: HiveConfig.from_dict(c, scenario_file_path),
50+
config_constructor=lambda c: HiveConfig.from_dict(c, scenario_file_path, output_suffix),
3951
config=config
4052
)
4153

4254
@classmethod
43-
def from_dict(cls, d: Dict, scenario_file_path: Path) -> Union[Exception, HiveConfig]:
55+
def from_dict(cls, d: Dict, scenario_file_path: Path, output_suffix: Optional[str]) -> Union[Exception, HiveConfig]:
4456
# collect the global hive configuration
4557
global_config = fs.global_hive_config_search()
4658

@@ -81,7 +93,7 @@ def from_dict(cls, d: Dict, scenario_file_path: Path) -> Union[Exception, HiveCo
8193
nconfig = Network.build(conf.get('network'))
8294
dconfig = DispatcherConfig.build(conf.get('dispatcher'))
8395

84-
scenario_name = sconfig.sim_name + "_" + datetime.now().strftime('%Y-%m-%d_%H-%M-%S')
96+
scenario_name = sconfig.sim_name + "_" + output_suffix if output_suffix is not None else sconfig.sim_name
8597
scenario_output_directory = Path(global_config.output_base_directory) / Path(scenario_name)
8698

8799
hive_config = HiveConfig(

0 commit comments

Comments
 (0)