1
0
mirror of https://github.com/Rikj000/MoniGoMani.git synced 2022-03-06 00:08:05 +03:00

Renaming some methods for better distinction

This commit is contained in:
topscoder
2021-08-16 16:05:31 +02:00
parent 5f31b578dd
commit 8b746ddbcd
4 changed files with 43 additions and 34 deletions

View File

@@ -429,7 +429,7 @@ class MGMHurry:
}
}
self.monigomani_config.write(new_config)
self.monigomani_config.write_hurry_dotfile(new_config)
if answers.get('proceed_exchange') is True:
cred = {

View File

@@ -23,12 +23,12 @@ def test_reload_with_valid_config_file():
# --- ↑
# --- ↓
# --- ↓ Unit Testing .valid_config_file_present(self) -> bool
# --- ↓ Unit Testing .valid_hurry_dotfile_present(self) -> bool
# --- ↓
def test_valid_config_file_present_should_return_true():
def test_valid_hurry_dotfile_present_should_return_true():
obj = __get_instance()
assert obj.valid_config_file_present() is True
assert obj.valid_hurry_dotfile_present() is True
# --- ↑

View File

@@ -51,10 +51,10 @@ class MoniGoManiConfig(object):
self.__full_path_config = '{0}/.hurry'.format(self.__basedir)
# if .hurry file does not exist
if self.valid_config_file_present() is False:
if self.valid_hurry_dotfile_present() is False:
self.__create_default_config()
self.__config = self.__read_config()
self.__config = self.read_hurry_config()
@property
def config(self) -> dict:
@@ -83,15 +83,15 @@ class MoniGoManiConfig(object):
:return bool: True if config is read, False if config could not be read.
"""
if self.valid_config_file_present() is not True:
self.logger.error('Failed to reload config. No valid config file present.')
if self.valid_hurry_dotfile_present() is not True:
self.logger.error('Failed to reload config. No valid hurry dotfile present.')
return False
self.config = self.__read_config()
self.config = self.read_hurry_config()
return True
def valid_config_file_present(self) -> bool:
def valid_hurry_dotfile_present(self) -> bool:
"""Check if the .hurry config file exists on disk."""
if os.path.isfile(self.__full_path_config) is not True:
self.logger.warning(
@@ -154,7 +154,11 @@ class MoniGoManiConfig(object):
- mgm-config-hyperopt
:return dict: Dictionary containing all the MoniGoMani Configuration files in format
{ mgm-config: dict, mgm-config-private: dict, mgm-config-hyperopt: dict }
{
mgm-config: dict,
mgm-config-private: dict,
mgm-config-hyperopt: dict
}
"""
hurry_config = self.read_hurry_config()
@@ -222,7 +226,7 @@ class MoniGoManiConfig(object):
json_data = json.load(file_object)
return json_data
def write(self, config: dict = None):
def write_hurry_dotfile(self, config: dict = None):
""" Write config-array to ".hurry" config file and load its contents into config-property.
Writes the passed config dictionary or if nothing passed, it will write default values.
@@ -271,10 +275,10 @@ class MoniGoManiConfig(object):
- mgm-config-hyperopt.json (applied results file)
- MoniGoManiHyperStrategy.json (intermediate results file)
:return bool: True if one of these files is cleaned up with success.
:return bool: True if one of these files is cleaned up with success.
False if no file was cleaned up.
"""
file_abspath = self._get_full_path_for_config_name('mgm-config-hyperopt')
file_abspath = self._get_full_path_for_config_name(self.read_hurry_config(), 'mgm-config-hyperopt')
cleaned_up_cfg = self._remove_file(file_abspath)
# Remove the intermediate ho file if exists
@@ -283,9 +287,9 @@ class MoniGoManiConfig(object):
cleaned_up_intmd = self._remove_file(strategy_ho_intmd_path)
# return true if one of these is true
return xor(
bool(cleaned_up_cfg),
bool(cleaned_up_intmd)
return xor(
bool(cleaned_up_cfg),
bool(cleaned_up_intmd)
)
def _remove_file(self, fil: str) -> bool:
@@ -314,7 +318,7 @@ class MoniGoManiConfig(object):
def __create_default_config(self):
""" Creates default .hurry config file with default values. """
self.write()
self.write_hurry_dotfile()
def _save_exchange_credentials(self, cred: dict):
"""
@@ -395,4 +399,4 @@ class MoniGoManiConfig(object):
self.logger.debug(f'☀️ Timerange string parsed from "{tr_input}" to "{tr_output}"')
return timerange
return timerange

View File

@@ -20,32 +20,39 @@ import os
import logging
from logging import Formatter
from Logging.handlers import RotatingFileHandler
from logging.handlers import RotatingFileHandler
from datetime import datetime
# ---- ↑ Do not remove these libs ↑ ------------------------------------------------------------------------------------
class mgmConsoleFormatter(Formatter):
def __init__(self):
log_file_format = "[%(levelname)s] - : %(message)s"
log_file_format = '[%(levelname)s] - : %(message)s'
datefmt = '%F %A %T' # in fact this is not used if no %(asctime)s exists in log_file_format
super(mgmConsoleFormatter, self).__init__(log_file_format, datefmt)
class mgmFileFormatter(Formatter):
def __init__(self):
log_file_format = "[%(levelname)s] - %(asctime)s - %(name)s - : %(message)s in %(pathname)s:%(lineno)d"
log_file_format = '[%(levelname)s] - %(asctime)s - %(name)s - : %(message)s in %(pathname)s:%(lineno)d'
datefmt = '%F %A %T'
super(mgmFileFormatter, self).__init__(log_file_format, datefmt)
class MGMLogger(logging.Logger):
def makeRecord(self, *args, **kwargs):
rv = super(MGMLogger, self).makeRecord(*args, **kwargs)
# TODO Filter as we like it
def makeRecord(self, name, level, fn, lno, msg, args, exc_info,
func=None, extra=None, sinfo=None):
"""
A factory method which can be overridden in subclasses to create
specialized LogRecords.
"""
rv = super(MGMLogger, self).makeRecord(name, level, fn, lno, msg, args, exc_info,
func=None, extra=None, sinfo=None)
# The magic filtering happens right here!
rv.__dict__['message'] = self.clean_line(rv.__dict__['message'])
return rv
def clean_line(self, line: str) -> str:
@@ -62,7 +69,7 @@ class MGMLogger(logging.Logger):
final_line = self.modify_line(final_line)
return final_line
@staticmethod
def filter_line(line: str) -> bool:
"""
@@ -146,7 +153,7 @@ class MGMLogger(logging.Logger):
line = line.replace(prefix_newline, f'\n {prefix_newline}')
if 'trades. ' in line:
line = line.replace('trades. ', f'trades. \n ')
line = line.replace('trades. ', 'trades. \n ')
prefix_other_newlines = {'Elapsed Time:', 'Best result:', '# Buy hyperspace params:',
'# Sell hyperspace params:', '# ROI table:', '# Stoploss:', '# Trailing stop:'}
@@ -190,14 +197,14 @@ class MoniGoManiLogger():
self.basedir = basedir
self.output_path = '{0}/Some Test Results/'.format(self.basedir)
self.output_file_name = 'MGM-Hurry-Command-Results-{0}.log'.format(datetime.now().strftime('%d-%m-%Y-%H-%M-%S'))
# TODO is this switch still needed?
# if print_output is True:
self._setup_logging()
def _setup_logging(self):
# Use our own Logging setup to log what we want.
# Use our own Logging setup to log what we want.
# And probably more important: how we want it!
logging_file_debug = os.path.join(self.output_path, 'MGM-Hurry-Command-Debug-{0}.log'.format(datetime.now().strftime('%d-%m-%Y-%H-%M-%S')))
@@ -257,5 +264,3 @@ class MoniGoManiLogger():
response['results_updated'] = True
return response