diff --git a/tests/test_trendet.py b/tests/test_trendet.py index 6fa3d60..80cdb1f 100644 --- a/tests/test_trendet.py +++ b/tests/test_trendet.py @@ -1,5 +1,6 @@ # Copyright 2019-2020 Alvaro Bartolome # See LICENSE for details. +import time import pytest @@ -94,6 +95,8 @@ def test_trendet(): trend_limit=param['trend_limit'], labels=param['labels'], identify=param['identify']) + # sleep for 5 seconds to avoid http code 429 error + time.sleep(5) trendet.identify_all_trends(stock=param['stock'], country=param['country'], @@ -130,6 +133,8 @@ def test_trendet(): column=param['column'], window_size=param['window_size'], identify=param['identify']) + # sleep for 5 seconds to avoid http code 429 error + time.sleep(5) if __name__ == '__main__': diff --git a/trendet/identification.py b/trendet/identification.py index f139d5a..090be9c 100644 --- a/trendet/identification.py +++ b/trendet/identification.py @@ -361,11 +361,10 @@ def identify_all_trends(stock, country, from_date, to_date, window_size=5, ident trends = list() + df_length = len(obj['element']) + for index, value in enumerate(obj['element'], 0): - if limit and limit > value: - values.append(value) - limit = mean(values) - elif limit and limit < value: + if limit and limit < value or index == df_length - 1: if len(values) > window_size: min_value = min(values) @@ -384,6 +383,9 @@ def identify_all_trends(stock, country, from_date, to_date, window_size=5, ident limit = None values = list() + elif limit and limit > value: + values.append(value) + limit = mean(values) else: from_trend = index @@ -547,11 +549,10 @@ def identify_df_trends(df, column, window_size=5, identify='both'): trends = list() + df_length = len(obj['element']) + for index, value in enumerate(obj['element'], 0): - if limit and limit > value: - values.append(value) - limit = mean(values) - elif limit and limit < value: + if limit and limit < value or index == df_length -1: if len(values) > window_size: min_value = min(values) @@ -570,6 +571,9 @@ def identify_df_trends(df, column, window_size=5, identify='both'): limit = None values = list() + elif limit and limit > value: + values.append(value) + limit = mean(values) else: from_trend = index