From 0fa60f7508943f6077174aec9bf0a4ffb5af075c Mon Sep 17 00:00:00 2001 From: Ronit Jain Date: Tue, 26 Jul 2022 19:16:42 +0530 Subject: [PATCH 1/2] log backtest name in config if available --- lean/components/docker/lean_runner.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lean/components/docker/lean_runner.py b/lean/components/docker/lean_runner.py index fef3b0b3..24a901c6 100644 --- a/lean/components/docker/lean_runner.py +++ b/lean/components/docker/lean_runner.py @@ -323,6 +323,8 @@ def get_basic_docker_config(self, run_options["name"] = f"lean_cli_{str(uuid.uuid4()).replace('-', '')}" output_config = self._output_config_manager.get_output_config(output_dir) output_config.set("container", run_options["name"]) + if "backtest-name" in lean_config: + output_config.set("backtest-name", lean_config["backtest-name"]) if "environment" in lean_config and "environments" in lean_config: environment = lean_config["environments"][lean_config["environment"]] From f096b9259242232a593fd0eabdad7c5ae20d4a50 Mon Sep 17 00:00:00 2001 From: Ronit Jain Date: Tue, 26 Jul 2022 19:17:37 +0530 Subject: [PATCH 2/2] add helper methods to fetch backtest-name, container --- .../config/output_config_manager.py | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/lean/components/config/output_config_manager.py b/lean/components/config/output_config_manager.py index e2ad4577..74758608 100644 --- a/lean/components/config/output_config_manager.py +++ b/lean/components/config/output_config_manager.py @@ -45,6 +45,32 @@ def get_backtest_id(self, backtest_directory: Path) -> int: """ return self._get_id(backtest_directory, 1) + def get_backtest_name(self, backtest_directory: Path) -> int: + """Returns the name of a backtest. + + :param backtest_directory: the path to the backtest to retrieve the id of + :return: the name of the given backtest + """ + config = self.get_output_config(backtest_directory) + + if config.has("backtest-name"): + return config.get("backtest-name") + + raise ValueError("Backtest name is not set") + + def get_container_name(self, backtest_directory: Path) -> int: + """Returns the name of a the docker container lean is running in. + + :param backtest_directory: the path to the backtest to retrieve the id of + :return: the name of the docker container lean is running in. + """ + config = self.get_output_config(backtest_directory) + + if config.has("container"): + return config.get("container") + + raise ValueError("Container name is not set") + def get_backtest_by_id(self, backtest_id: int, root_directory: Optional[Path] = None) -> Path: """Finds the directory of a backtest by its id.