def get_data_and_rate(self, line): import re from exception import InvalidReportFormat formatted_str = re.sub('(\(|\))', '', line) values = formatted_str.split(r' ') if len(values) != 2: raise InvalidReportFormat( self.report_file, 'value of Maximal drawdown contains more than 2 values') for value in values: if re.match('.*\%$', value): rate = re.sub(r'%', '', value) rate = float(rate) else: data = float(value) return data, rate
def __init__(self, backtest, alias=DEFAULT_MT4_NAME): from exception import InvalidReportFormat report_file = get_report_abs_path(backtest.ea_name, alias=alias) with open(report_file, 'r') as fp: raw_html = fp.read() if self._is_valid_format(raw_html): try: self.results = self._get_results(backtest, raw_html) except KeyError: err_msg = 'optimization report seems invlid format' logging.error(err_msg) raise else: raise InvalidReportFormat( report_file, r'"Optimization Report" not found in html')
def split_to_tokens(self, line): ''' Notes: split consecutive xxx into two tokens. e.g. 1 (123.45) => (1, 123.45) 123.45 (1) => (123.45, 1) ''' import re from exception import InvalidReportFormat formatted_str = re.sub('(\(|\))', '', line) values = formatted_str.split(r' ') if len(values) != 2: raise InvalidReportFormat( 'value of Maximal drawdown contains more than 2 values') return values