Return true/false for validation function

This commit is contained in:
Matthias 2018-10-18 19:48:54 +02:00
parent 518dcf5209
commit bc356c4d65
2 changed files with 8 additions and 5 deletions

View File

@ -78,7 +78,7 @@ def get_timeframe(data: Dict[str, DataFrame]) -> Tuple[arrow.Arrow, arrow.Arrow]
def validate_backtest_data(data: Dict[str, DataFrame], min_date: datetime, def validate_backtest_data(data: Dict[str, DataFrame], min_date: datetime,
max_date: datetime, ticker_interval_mins: int) -> None: max_date: datetime, ticker_interval_mins: int) -> bool:
""" """
Validates preprocessed backtesting data for missing values and shows warnings about it that. Validates preprocessed backtesting data for missing values and shows warnings about it that.
@ -89,10 +89,13 @@ def validate_backtest_data(data: Dict[str, DataFrame], min_date: datetime,
""" """
# total difference in minutes / interval-minutes # total difference in minutes / interval-minutes
expected_frames = int((max_date - min_date).total_seconds() // 60 // ticker_interval_mins) expected_frames = int((max_date - min_date).total_seconds() // 60 // ticker_interval_mins)
found_missing = False
for pair, df in data.items(): for pair, df in data.items():
if len(df) < expected_frames: if len(df) < expected_frames:
found_missing = True
logger.warning('%s has missing frames: expected %s, got %s', logger.warning('%s has missing frames: expected %s, got %s',
pair, expected_frames, len(df)) pair, expected_frames, len(df))
return found_missing
def load_tickerdata_file( def load_tickerdata_file(

View File

@ -465,7 +465,7 @@ def test_validate_backtest_data_warn(default_conf, mocker, caplog) -> None:
) )
min_date, max_date = optimize.get_timeframe(data) min_date, max_date = optimize.get_timeframe(data)
caplog.clear() caplog.clear()
optimize.validate_backtest_data(data, min_date, max_date, assert optimize.validate_backtest_data(data, min_date, max_date,
constants.TICKER_INTERVAL_MINUTES["1m"]) constants.TICKER_INTERVAL_MINUTES["1m"])
assert len(caplog.record_tuples) == 1 assert len(caplog.record_tuples) == 1
assert log_has('UNITTEST/BTC has missing frames: expected 14396, got 13680', assert log_has('UNITTEST/BTC has missing frames: expected 14396, got 13680',
@ -488,7 +488,7 @@ def test_validate_backtest_data(default_conf, mocker, caplog) -> None:
min_date, max_date = optimize.get_timeframe(data) min_date, max_date = optimize.get_timeframe(data)
caplog.clear() caplog.clear()
optimize.validate_backtest_data(data, min_date, max_date, assert not optimize.validate_backtest_data(data, min_date, max_date,
constants.TICKER_INTERVAL_MINUTES["5m"]) constants.TICKER_INTERVAL_MINUTES["5m"])
assert len(caplog.record_tuples) == 0 assert len(caplog.record_tuples) == 0