Alignment and cleanups
This commit is contained in:
parent
7652a2bb95
commit
090d1e8a70
@ -154,7 +154,7 @@ class Hyperopt:
|
|||||||
"""
|
"""
|
||||||
num_trials = len(self.trials)
|
num_trials = len(self.trials)
|
||||||
if num_trials > self.num_trials_saved:
|
if num_trials > self.num_trials_saved:
|
||||||
logger.info(f"Saving {num_trials} {plural(num_trials, 'epoch')}.")
|
logger.debug(f"Saving {num_trials} {plural(num_trials, 'epoch')}.")
|
||||||
dump(self.trials, self.trials_file)
|
dump(self.trials, self.trials_file)
|
||||||
self.num_trials_saved = num_trials
|
self.num_trials_saved = num_trials
|
||||||
if final:
|
if final:
|
||||||
@ -322,7 +322,6 @@ class Hyperopt:
|
|||||||
trials['is_profit'] = False
|
trials['is_profit'] = False
|
||||||
trials.loc[trials['is_initial_point'], 'Best'] = '*'
|
trials.loc[trials['is_initial_point'], 'Best'] = '*'
|
||||||
trials.loc[trials['is_best'], 'Best'] = 'Best'
|
trials.loc[trials['is_best'], 'Best'] = 'Best'
|
||||||
trials['Objective'] = trials['Objective'].astype(str)
|
|
||||||
trials.loc[trials['Total profit'] > 0, 'is_profit'] = True
|
trials.loc[trials['Total profit'] > 0, 'is_profit'] = True
|
||||||
trials['Trades'] = trials['Trades'].astype(str)
|
trials['Trades'] = trials['Trades'].astype(str)
|
||||||
|
|
||||||
@ -336,14 +335,15 @@ class Hyperopt:
|
|||||||
lambda x: ('{:,.1f} m'.format(x)).rjust(7, ' ') if not isna(x) else "--".rjust(7, ' ')
|
lambda x: ('{:,.1f} m'.format(x)).rjust(7, ' ') if not isna(x) else "--".rjust(7, ' ')
|
||||||
)
|
)
|
||||||
trials['Objective'] = trials['Objective'].apply(
|
trials['Objective'] = trials['Objective'].apply(
|
||||||
lambda x: str(x).rjust(10, ' ') if str(x) != str(100000) else "N/A".rjust(10, ' ')
|
lambda x: '{:,.5f}'.format(x).rjust(8, ' ') if x != 100000 else "N/A".rjust(8, ' ')
|
||||||
)
|
)
|
||||||
|
|
||||||
trials['Profit'] = trials.apply(
|
trials['Profit'] = trials.apply(
|
||||||
lambda x: '{:,.8f} {} ({:,.2f}%)'.format(
|
lambda x: '{:,.8f} {} {}'.format(
|
||||||
x['Total profit'], config['stake_currency'],
|
x['Total profit'], config['stake_currency'],
|
||||||
x['Profit']).rjust(24+len(config['stake_currency']))
|
'({:,.2f}%)'.format(x['Profit']).rjust(10, ' ')
|
||||||
if x['Total profit'] != 0.0 else '--'.rjust(24+len(config['stake_currency'])),
|
).rjust(25+len(config['stake_currency']))
|
||||||
|
if x['Total profit'] != 0.0 else '--'.rjust(25+len(config['stake_currency'])),
|
||||||
axis=1
|
axis=1
|
||||||
)
|
)
|
||||||
trials = trials.drop(columns=['Total profit'])
|
trials = trials.drop(columns=['Total profit'])
|
||||||
@ -351,27 +351,33 @@ class Hyperopt:
|
|||||||
if print_colorized:
|
if print_colorized:
|
||||||
for i in range(len(trials)):
|
for i in range(len(trials)):
|
||||||
if trials.loc[i]['is_profit']:
|
if trials.loc[i]['is_profit']:
|
||||||
for z in range(len(trials.loc[i])-3):
|
for j in range(len(trials.loc[i])-3):
|
||||||
trials.iat[i, z] = "{}{}{}".format(
|
trials.iat[i, j] = "{}{}{}".format(Fore.GREEN,
|
||||||
Fore.GREEN, str(trials.loc[i][z]), Fore.RESET)
|
str(trials.loc[i][j]), Fore.RESET)
|
||||||
if trials.loc[i]['is_best'] and highlight_best:
|
if trials.loc[i]['is_best'] and highlight_best:
|
||||||
for z in range(len(trials.loc[i])-3):
|
for j in range(len(trials.loc[i])-3):
|
||||||
trials.iat[i, z] = "{}{}{}".format(
|
trials.iat[i, j] = "{}{}{}".format(Style.BRIGHT,
|
||||||
Style.BRIGHT, str(trials.loc[i][z]), Style.RESET_ALL)
|
str(trials.loc[i][j]), 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'])
|
||||||
if remove_header > 0:
|
if remove_header > 0:
|
||||||
table = tabulate.tabulate(
|
table = tabulate.tabulate(
|
||||||
trials.to_dict(orient='list'), tablefmt='orgtbl', headers='keys', stralign="right")
|
trials.to_dict(orient='list'), tablefmt='orgtbl',
|
||||||
# print(table)
|
headers='keys', stralign="right"
|
||||||
|
)
|
||||||
|
|
||||||
table = table.split("\n", remove_header)[remove_header]
|
table = table.split("\n", remove_header)[remove_header]
|
||||||
elif remove_header < 0:
|
elif remove_header < 0:
|
||||||
table = tabulate.tabulate(
|
table = tabulate.tabulate(
|
||||||
trials.to_dict(orient='list'), tablefmt='psql', headers='keys', stralign="right")
|
trials.to_dict(orient='list'), tablefmt='psql',
|
||||||
|
headers='keys', stralign="right"
|
||||||
|
)
|
||||||
table = "\n".join(table.split("\n")[0:remove_header])
|
table = "\n".join(table.split("\n")[0:remove_header])
|
||||||
else:
|
else:
|
||||||
table = tabulate.tabulate(
|
table = tabulate.tabulate(
|
||||||
trials.to_dict(orient='list'), tablefmt='psql', headers='keys', stralign="right")
|
trials.to_dict(orient='list'), tablefmt='psql',
|
||||||
|
headers='keys', stralign="right"
|
||||||
|
)
|
||||||
print(table)
|
print(table)
|
||||||
|
|
||||||
def has_space(self, space: str) -> bool:
|
def has_space(self, space: str) -> bool:
|
||||||
|
@ -432,13 +432,11 @@ def test_save_trials_saves_trials(mocker, hyperopt, testdatadir, caplog) -> None
|
|||||||
|
|
||||||
hyperopt.trials = trials
|
hyperopt.trials = trials
|
||||||
hyperopt.save_trials(final=True)
|
hyperopt.save_trials(final=True)
|
||||||
assert log_has("Saving 1 epoch.", caplog)
|
|
||||||
assert log_has(f"1 epoch saved to '{trials_file}'.", caplog)
|
assert log_has(f"1 epoch saved to '{trials_file}'.", caplog)
|
||||||
mock_dump.assert_called_once()
|
mock_dump.assert_called_once()
|
||||||
|
|
||||||
hyperopt.trials = trials + trials
|
hyperopt.trials = trials + trials
|
||||||
hyperopt.save_trials(final=True)
|
hyperopt.save_trials(final=True)
|
||||||
assert log_has("Saving 2 epochs.", caplog)
|
|
||||||
assert log_has(f"2 epochs saved to '{trials_file}'.", caplog)
|
assert log_has(f"2 epochs saved to '{trials_file}'.", caplog)
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user