Added dynamic print table function to hyperopt

This commit is contained in:
Fredrik81 2020-02-28 21:54:04 +01:00
parent ac7fa8252b
commit 349aa2f957
2 changed files with 16 additions and 8 deletions

View File

@ -51,7 +51,7 @@ def start_hyperopt_list(args: Dict[str, Any]) -> None:
try: try:
Hyperopt.print_result_table(config, trials, total_epochs, Hyperopt.print_result_table(config, trials, total_epochs,
not filteroptions['only_best'], print_colorized) not filteroptions['only_best'], print_colorized, 0)
except KeyboardInterrupt: except KeyboardInterrupt:
print('User interrupted..') print('User interrupted..')

View File

@ -116,6 +116,7 @@ class Hyperopt:
self.config['ask_strategy']['use_sell_signal'] = True self.config['ask_strategy']['use_sell_signal'] = True
self.print_all = self.config.get('print_all', False) self.print_all = self.config.get('print_all', False)
self.hyperopt_table_header = 0
self.print_colorized = self.config.get('print_colorized', False) self.print_colorized = self.config.get('print_colorized', False)
self.print_json = self.config.get('print_json', False) self.print_json = self.config.get('print_json', False)
@ -272,8 +273,13 @@ class Hyperopt:
if not self.print_all: if not self.print_all:
# Separate the results explanation string from dots # Separate the results explanation string from dots
print("\n") print("\n")
self.print_results_explanation(results, self.total_epochs, self.print_all, self.print_result_table(self.config, results, self.total_epochs,
self.print_colorized) self.print_all, self.print_colorized,
self.hyperopt_table_header)
if is_best:
self.hyperopt_table_header = 2
else:
self.hyperopt_table_header = 3
@staticmethod @staticmethod
def print_results_explanation(results, total_epochs, highlight_best: bool, def print_results_explanation(results, total_epochs, highlight_best: bool,
@ -299,7 +305,7 @@ class Hyperopt:
@staticmethod @staticmethod
def print_result_table(config: dict, results: list, total_epochs: int, highlight_best: bool, def print_result_table(config: dict, results: list, total_epochs: int, highlight_best: bool,
print_colorized: bool) -> None: print_colorized: bool, remove_header: int) -> None:
""" """
Log result table Log result table
""" """
@ -328,7 +334,7 @@ class Hyperopt:
trials['Profit'] = trials['Profit'].apply( trials['Profit'] = trials['Profit'].apply(
lambda x: '{:,.2f}%'.format(x) if not isna(x) else x) lambda x: '{:,.2f}%'.format(x) if not isna(x) else x)
trials['Total profit'] = trials['Total profit'].apply( trials['Total profit'] = trials['Total profit'].apply(
lambda x: '{: 11.8f} '.format(x) + config['stake_currency'] if not isna(x) else x) lambda x: '{:,.8f} '.format(x) + config['stake_currency'] if not isna(x) else x)
trials['Avg duration'] = trials['Avg duration'].apply( trials['Avg duration'] = trials['Avg duration'].apply(
lambda x: '{:,.1f}m'.format(x) if not isna(x) else x) lambda x: '{:,.1f}m'.format(x) if not isna(x) else x)
if print_colorized: if print_colorized:
@ -343,9 +349,11 @@ class Hyperopt:
str(trials.loc[i][z]), Style.RESET_ALL) str(trials.loc[i][z]), Style.RESET_ALL)
trials = trials.drop(columns=['is_initial_point', 'is_best', 'is_profit']) trials = trials.drop(columns=['is_initial_point', 'is_best', 'is_profit'])
table = tabulate(trials.to_dict(orient='list'), tablefmt='psql',
print(tabulate(trials.to_dict(orient='list'), headers='keys', tablefmt='psql', headers='keys', stralign="right")
stralign="right")) if remove_header > 0:
table = table.split("\n", remove_header)[remove_header]
print(table)
def has_space(self, space: str) -> bool: def has_space(self, space: str) -> bool:
""" """