colorization by means of termcolor and colorama

This commit is contained in:
hroff-1902 2019-08-04 22:54:19 +03:00
parent 3dd6fe2703
commit 9cbab35de0
3 changed files with 12 additions and 16 deletions

View File

@ -113,15 +113,3 @@ def deep_merge_dicts(source, destination):
destination[key] = value destination[key] = value
return destination return destination
def green(s):
return '\033[92m' + s + '\033[0m'
def red(s):
return '\033[91m' + s + '\033[0m'
def bold(s):
return '\033[1m' + s + '\033[0m'

View File

@ -13,14 +13,15 @@ from pathlib import Path
from pprint import pprint from pprint import pprint
from typing import Any, Dict, List, Optional from typing import Any, Dict, List, Optional
from colorama import init as colorama_init
from joblib import Parallel, delayed, dump, load, wrap_non_picklable_objects, cpu_count from joblib import Parallel, delayed, dump, load, wrap_non_picklable_objects, cpu_count
from pandas import DataFrame from pandas import DataFrame
from skopt import Optimizer from skopt import Optimizer
from skopt.space import Dimension from skopt.space import Dimension
from termcolor import colored
from freqtrade.configuration import Arguments from freqtrade.configuration import Arguments
from freqtrade.data.history import load_data, get_timeframe from freqtrade.data.history import load_data, get_timeframe
from freqtrade.misc import green, red, bold
from freqtrade.optimize.backtesting import Backtesting from freqtrade.optimize.backtesting import Backtesting
# Import IHyperOptLoss to allow users import from this file # Import IHyperOptLoss to allow users import from this file
from freqtrade.optimize.hyperopt_loss_interface import IHyperOptLoss # noqa: F4 from freqtrade.optimize.hyperopt_loss_interface import IHyperOptLoss # noqa: F4
@ -162,11 +163,11 @@ class Hyperopt(Backtesting):
# Colorize output # Colorize output
if self.config.get('print_colorized', False): if self.config.get('print_colorized', False):
if results['total_profit'] > 0: if results['total_profit'] > 0:
log_str = bold(log_str) log_str = colored(log_str, attrs=['bold'])
if results['loss'] >= MAX_LOSS: if results['loss'] >= MAX_LOSS:
log_str = red(log_str) log_str = colored(log_str, 'red')
elif is_best_loss: elif is_best_loss:
log_str = green(log_str) log_str = colored(log_str, 'green')
if print_all: if print_all:
print(log_str) print(log_str)
else: else:
@ -353,6 +354,9 @@ class Hyperopt(Backtesting):
logger.info(f'Number of parallel jobs set as: {config_jobs}') logger.info(f'Number of parallel jobs set as: {config_jobs}')
opt = self.get_optimizer(config_jobs) opt = self.get_optimizer(config_jobs)
colorama_init()
try: try:
with Parallel(n_jobs=config_jobs) as parallel: with Parallel(n_jobs=config_jobs) as parallel:
jobs = parallel._effective_n_jobs() jobs = parallel._effective_n_jobs()

View File

@ -30,3 +30,7 @@ sdnotify==0.3.2
# Api server # Api server
flask==1.1.1 flask==1.1.1
# Support for colorized terminal output
termcolor==1.1.0
colorama==0.4.1