# Copyright 2024 The TensorTrade and TensorTrade-NG Authors.## Licensed under the Apache License, Version 2.0 (the "License");# you may not use this file except in compliance with the License.# You may obtain a copy of the License at## http://www.apache.org/licenses/LICENSE-2.0## Unless required by applicable law or agreed to in writing, software# distributed under the License is distributed on an "AS IS" BASIS,# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.# See the License for the specific language governing permissions and# limitations under the Licensefrom__future__importannotationsimportosimporttypingfromdatetimeimportdatetimefromtensortrade.env.mixins.schemeimportSchemeMixinfromtensortrade.env.plotters.abstractimportAbstractPlotteriftyping.TYPE_CHECKING:fromtypingimportListfromtensortrade.envimportTradingEnv
[docs]defcheck_path(path:str,auto_create:bool=True)->None:ifnotpathoros.path.exists(path):returnifauto_create:os.mkdir(path)else:raiseOSError(f"Path '{path}' not found.")
[docs]defcheck_valid_format(valid_formats:list,save_format:str)->None:ifsave_formatnotinvalid_formats:raiseValueError("Acceptable formats are '{}'. Found '{}'".format("', '".join(valid_formats),save_format))
[docs]classAggregatePlotter(AbstractPlotter):"""A renderer that aggregates compatible plotters so they can all be used to render a view of the environment. Parameters ---------- renderers : List[Renderer] A list of plotters to aggregate. Attributes ---------- renderers : List[Renderer] A list of plotters to aggregate. """registered_name="aggregate_renderer"def__init__(self,renderers:List[AbstractPlotter])->None:super().__init__()self.renderers=renderers@SchemeMixin.trading_env.setterdeftrading_env(self,value:TradingEnv):"""Sets the :class:`TradingEnv` instance. This setter allows for the initialization of the `_trading_env` attribute. :param value: The `TradingEnv` instance to be assigned to `_trading_env`. :type value: TradingEnv """self._trading_env=valueforrendererinself.renderers:renderer.trading_env=value