diff --git a/Pipfile b/Pipfile index 7fb0599..58bb044 100644 --- a/Pipfile +++ b/Pipfile @@ -27,3 +27,4 @@ fbprophet = "*" cython = "*" flask-graphql = "*" graphene = "*" +mpld3 = "*" diff --git a/Pipfile.lock b/Pipfile.lock index 28913c7..58a4afb 100644 --- a/Pipfile.lock +++ b/Pipfile.lock @@ -1,7 +1,7 @@ { "_meta": { "hash": { - "sha256": "e33bd23b4cafa0e8680e1adc911ed07c0d9aadd076631460d2bcdf69c27f3280" + "sha256": "e2a9e1803c3d4ba7768760415b5bbf93ce4fa8a78c4cf97e69dbe1a6580f8ec3" }, "requires": {}, "sources": [ @@ -42,6 +42,9 @@ "cssselect": { "version": "==1.0.1" }, + "cython": { + "version": "==0.26.1" + }, "dateparser": { "version": "==0.6.0" }, @@ -51,6 +54,9 @@ "et-xmlfile": { "version": "==1.0.1" }, + "fbprophet": { + "version": "==0.1.1" + }, "flask": { "version": "==0.12.2" }, @@ -60,9 +66,21 @@ "flask-common": { "version": "==0.2.0" }, + "flask-graphql": { + "version": "==1.4.1" + }, "flask-sslify": { "version": "==0.1.5" }, + "graphene": { + "version": "==1.4.1" + }, + "graphql-core": { + "version": "==1.1" + }, + "graphql-relay": { + "version": "==0.4.5" + }, "greenlet": { "version": "==0.4.12" }, @@ -99,6 +117,9 @@ "meinheld": { "version": "==0.6.1" }, + "mpld3": { + "version": "==0.3" + }, "multidict": { "version": "==3.1.3" }, @@ -114,9 +135,15 @@ "pandas": { "version": "==0.20.3" }, + "pandas-datareader": { + "version": "==0.5.0" + }, "pendulum": { "version": "==1.2.4" }, + "promise": { + "version": "==2.0.2" + }, "psycopg2": { "version": "==2.7.3.1" }, @@ -130,7 +157,7 @@ "version": "==2017.2" }, "pytzdata": { - "version": "==2017.2" + "version": "==2017.2.1" }, "pyyaml": { "version": "==3.12" @@ -144,11 +171,23 @@ "requests": { "version": "==2.18.4" }, + "requests-file": { + "version": "==1.4.2" + }, + "requests-ftp": { + "version": "==0.3.1" + }, "ruamel.yaml": { - "version": "==0.15.32" + "version": "==0.15.33" + }, + "scikit-learn": { + "version": "==0.19.0" + }, + "scipy": { + "version": "==0.19.1" }, "setuptools": { - "version": "==36.2.7" + "version": "==36.3.0" }, "simplejson": { "version": "==3.11.1" @@ -160,7 +199,10 @@ "version": "==1.1.13" }, "tablib": { - "version": "==0.11.5" + "version": "==0.12.0" + }, + "typing": { + "version": "==3.6.2" }, "tzlocal": { "version": "==1.4" diff --git a/predictions.py b/predictions.py index 5580bf6..9b0c5c8 100644 --- a/predictions.py +++ b/predictions.py @@ -9,9 +9,11 @@ import numpy as np import pandas as pd # Matplotlib hack. + import matplotlib matplotlib.use('agg') +import mpld3 from fbprophet import Prophet from scraper import Coin, MWT, convert_to_decimal @@ -51,12 +53,9 @@ def get_predictions(coin, render=False): forecast_data = model.predict(future_data) if render: - f_name = str(uuid.uuid4()) - matplotlib.pyplot.gcf() - model.plot(forecast_data).savefig(f_name, transparent=True) - - return f'{f_name}.png' + fig = model.plot(forecast_data, ylabel='log($)') + return mpld3.fig_to_html(fig) forecast_data_orig = forecast_data # make sure we save the original forecast data forecast_data_orig['yhat'] = np.exp(forecast_data_orig['yhat']) diff --git a/requirements.txt b/requirements.txt index f77f946..2c6cf5f 100644 --- a/requirements.txt +++ b/requirements.txt @@ -5,12 +5,11 @@ bs4==0.0.1 certifi==2017.7.27.1 chardet==3.0.4 click==6.7 -coinmarketcap==3.0.1 colorama==0.3.9 crayons==0.1.2 cssselect==1.0.1 cycler==0.10.0 -Cython==0.26 +Cython==0.26.1 dateparser==0.6.0 docopt==0.6.2 et-xmlfile==1.0.1 @@ -36,14 +35,13 @@ MarkupSafe==1.0 matplotlib==2.0.2 maya==0.3.2 meinheld==0.6.1 +mpld3==0.3 multidict==3.1.3 numpy==1.13.1 odfpy==1.3.5 openpyxl==2.4.8 pandas==0.20.3 pandas-datareader==0.5.0 -patsy==0.4.1 -pbr==3.1.1 pendulum==1.2.4 promise==2.0.2 psycopg2==2.7.3.1 @@ -52,20 +50,19 @@ pyquery==1.2.17 pystan==2.16.0.0 python-dateutil==2.6.1 pytz==2017.2 -pytzdata==2017.2 +pytzdata==2017.2.1 PyYAML==3.12 records==0.5.0 regex==2017.7.28 requests==2.18.4 requests-file==1.4.2 requests-ftp==0.3.1 -ruamel.yaml==0.15.32 +ruamel.yaml==0.15.33 scikit-learn==0.19.0 scipy==0.19.1 simplejson==3.11.1 six==1.10.0 SQLAlchemy==1.1.13 -statsmodels==0.8.0 tablib==0.12.0 typing==3.6.2 tzlocal==1.4 diff --git a/server.py b/server.py index fd7aa0a..9af7991 100644 --- a/server.py +++ b/server.py @@ -64,8 +64,8 @@ def get_forecast(coin): @app.route('//forecast/graph') def get_forecast_graph(coin): - f_name = get_predictions(coin.lower(), render=True) - return send_file(f_name, mimetype='image/png') + return get_predictions(coin.lower(), render=True) + # return send_file(f_name, mimetype='image/png') @app.route('//') diff --git a/templates/index.html b/templates/index.html index 8cfb82b..fa2f5b9 100644 --- a/templates/index.html +++ b/templates/index.html @@ -6,6 +6,14 @@ + + + @@ -76,12 +84,12 @@

Experimental (e.g. fun) Endpoints

-

Prediction of BTC Price (using machine learning)

+

Prediction of BTC Price (using machine learning)

 

- - Graph of BTC prediction. - + + +

$ curl https://coinbin.org/btc/forecast