# 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__importannotationsfromabcimportabstractmethodfromdatetimeimportdatetimefromtensortrade.coreimportComponentfromtensortrade.env.mixins.schemeimportSchemeMixin
[docs]classAbstractPlotter(SchemeMixin,Component):"""A component for rendering a view of the environment at each step of an episode."""registered_name="renderer"def__init__(self):super().__init__()self._max_episodes=Noneself._max_steps=None
[docs]defsave(self)->None:"""Saves the rendered view of the environment."""pass
[docs]defreset(self)->None:"""Resets the renderer."""pass
[docs]defclose(self)->None:"""Closes the renderer."""pass
@staticmethoddef_create_log_entry(episode:int=None,max_episodes:int=None,step:int=None,max_steps:int=None,date_format:str="%Y-%m-%d %H:%M:%S")->str:""" Creates a log entry to be used by a renderer. Parameters ---------- episode : int The current episode. max_episodes : int The maximum number of episodes that can occur. step : int The current step of the current episode. max_steps : int The maximum number of steps within an episode that can occur. date_format : str The format for logging the date. Returns ------- str a log entry """log_entry=f"[{datetime.now().strftime(date_format)}]"ifepisodeisnotNone:log_entry+=f" Episode: {episode+1}/{max_episodesifmax_episodeselse''}"ifstepisnotNone:log_entry+=f" Step: {step}/{max_stepsifmax_stepselse''}"returnlog_entry