Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed last trend detection #18

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions tests/test_trendet.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Copyright 2019-2020 Alvaro Bartolome
# See LICENSE for details.
import time

import pytest

Expand Down Expand Up @@ -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'],
Expand Down Expand Up @@ -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__':
Expand Down
20 changes: 12 additions & 8 deletions trendet/identification.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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

Expand Down Expand Up @@ -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)

Expand All @@ -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

Expand Down