Skip to content

chelaxe/SwingingDoor

Repository files navigation

License Release Supported versions Docs Code Coverage Build status Appveyor Build Status Travis CI Contact Blog

Swinging Door

Implementation of the SwingingDoor algorithm in Python.

Example of usage

>>> from datetime import datetime
>>> from pandas import read_csv, DataFrame

>>> df = DataFrame(
...     [
...         {
...             "Date": datetime.strptime(date, "%Y-%m-%d"),
...             "Price": value
...         }
...         for date, value in read_csv(
...             "https://datahub.io/core/oil-prices/r/wti-daily.csv"
...         ).values.tolist()
...     ]
... )

>>> print(len(df))
9286

>>> df.plot(x="Date", y="Price")
>>> from swinging_door import swinging_door

>>> compress = DataFrame(
...      list(
...         {
...             "Date": datetime.fromtimestamp(date),
...             "Price": value
...         }
...         for date, value in swinging_door(
...             [
...                 (date.timestamp(), value)
...                 for date, value in df.values.tolist()
...             ], deviation=.5
...         )
...     )
... )

>>> print(len(compress))
2719

>>> compress.plot(x="Date", y="Price")