interactive charts!

Signed-off-by: Kenneth Reitz <me@kennethreitz.org>
This commit is contained in:
2017-08-31 02:50:08 -04:00
parent 28d114fbf5
commit c9f19de176
6 changed files with 70 additions and 23 deletions
+1
View File
@@ -27,3 +27,4 @@ fbprophet = "*"
cython = "*"
flask-graphql = "*"
graphene = "*"
mpld3 = "*"
Generated
+47 -5
View File
@@ -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"
+4 -5
View File
@@ -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'])
+4 -7
View File
@@ -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
+2 -2
View File
@@ -64,8 +64,8 @@ def get_forecast(coin):
@app.route('/<coin>/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('/<coin>/<float:n>')
+12 -4
View File
@@ -6,6 +6,14 @@
<link rel="stylesheet" href="{{ url_for('static', filename='tufte.css') }}"/>
<link rel="stylesheet" href="{{ url_for('static', filename='latex.css') }}"/>
<meta name="viewport" content="width=device-width, initial-scale=1">
<script>
function resizeIframe(obj) {
obj.style.height = obj.contentWindow.document.body.scrollHeight + 'px';
obj.style.width = obj.contentWindow.document.body.scrollWidth + 'px';
}
</script>
</head>
<body>
@@ -76,12 +84,12 @@
<h2>Experimental (e.g. <em>fun</em>) Endpoints</h2>
<h3>Prediction of BTC Price (using <em>machine learning</em>)</h3>
<h3><a href="https://coinbin.org/btc/forecast/graph">Prediction of BTC Price</a> (using <em>machine learning</em>)</h3>
<p>&nbsp;</p>
<a href="https://coinbin.org/btc/forecast/graph">
<img src="/btc/forecast/graph" alt="Graph of BTC prediction.">
</a>
<iframe src="/btc/forecast/graph" frameborder="0" scrolling="no" onload="resizeIframe(this)" width="80%"></iframe>
<p></p>
<code><strong>$ curl <a href="https://coinbin.org/btc/forecast">https://coinbin.org/btc/forecast</a></strong></code>