heroku errors for api

This commit is contained in:
walkews 2017-07-12 09:22:54 -05:00
parent 81e294f489
commit 01b4b766df
9 changed files with 129 additions and 54 deletions

1
src/__init__.py Normal file
View file

@ -0,0 +1 @@
from pyDataVizDay import *

View file

@ -82,30 +82,46 @@ class Data(object):
end_year_mask = True end_year_mask = True
if genre: if genre:
genre_indexes = data.genre[data.genre.genres == genre]['index'].values try: # assume genre is list like
genre_indexes = data.genre[data.genre.genres.isin(genre)]['index'].values
except TypeError: # it is a string
genre_indexes = data.genre[data.genre.genres == genre]['index'].values
genre_mask = data.movie.index.isin(genre_indexes) genre_mask = data.movie.index.isin(genre_indexes)
else: else:
genre_mask = True genre_mask = True
if country: if country:
country_mask = data.movie.country == country try:
country_mask = data.movie.country.isin(country)
except TypeError:
country_mask = data.movie.country == country
else: else:
country_mask = True country_mask = True
if language: if language:
language_mask = data.movie.language == language try:
language_mask = data.movie.language.isin(language)
except:
language_mask = data.movie.language == language
else: else:
language_mask = True language_mask = True
if title: if title:
title_mask = data.movie.movie_title == title try:
title_mask = data.movie.movie_title.isin(title)
except TypeError:
title_mask = data.movie.movie_title == title
else: else:
title_mask = True title_mask = True
if color: if color:
color_mask = data.movie.color == color try:
color_mask = data.movie.color.isin(color)
except TypeError:
color_mask = data.movie.color == color
else: else:
color_mask = True color_mask = True
masks = genre_mask & start_year_mask & end_year_mask & country_mask & language_mask & title_mask & color_mask masks = genre_mask & start_year_mask & end_year_mask & country_mask & language_mask & title_mask & color_mask
try: try:

View file

@ -75,7 +75,8 @@ def investor():
@app.route('/enthusiast') @app.route('/enthusiast')
def enthusiast(): def enthusiast():
return render_template('enthusiast.html', body='Hello Enthusiast') form = render_template('data_form.html', dropdowns=dropdowns, inputs=inputs)
return render_template('enthusiast.html', form=form)
@app.route('/slides') @app.route('/slides')
def slides(): def slides():
@ -88,15 +89,40 @@ def slides():
class keywords(Resource): class keywords(Resource):
def get(self): def get(self):
args = parser.parse_args() args = parser.parse_args()
try:
args['genre'] = args['genre'].split(',')
except:
pass
try:
args['country'] = args['country'].split(',')
except:
pass
try:
args['language'] = args['language'].split(',')
except:
pass
# try:
# args['start_year'] = int(args['start_year'].strip())
# except:
# args['start_year'] = 1900
# try:
# args['end_year'] = int(args['end_year'].strip())
# except:
# args['end_year'] = 3000
keyword_data = data.filter(start_year=args['start_year'], keyword_data = data.filter(start_year=args['start_year'],
end_year=args['end_year'], end_year=args['end_year'],
genre=args['genre'], genre=args['genre'],
country=args['country'], country=args['country'],
language=args['language'], language=args['language'],
top=args['top'], top=args['top']
title=args['title'],
color=args['color']
) )
print(len(keyword_data.movie))
c = Counter(keyword_data.keyword.plot_keywords.values.tolist()) c = Counter(keyword_data.keyword.plot_keywords.values.tolist())
words = [{'text': word[0], 'weight': word[1]} for word in c.most_common(50)] words = [{'text': word[0], 'weight': word[1]} for word in c.most_common(50)]

View file

@ -9,14 +9,16 @@ body{
.text_input{ .text_input{
height:75px; height:75px;
width:75%; width:70%;
max-width: 300px; max-width: 300px;
} }
.chosen{ .chosen{
float:right;
height:75px; height:75px;
width:75%; width:70%;
max-width: 300px; max-width: 300px;
padding:5px;
} }
.col-sm-3{ .col-sm-3{

View file

@ -0,0 +1,49 @@
$('#top').change(function(){update_words()})
$('#language').change(function(){update_words()})
$('#country').change(function(){update_words()})
$('#genre').change(function(){update_words()})
$('#start_year').change(function(){update_words()})
$('#end_year').change(function(){update_words()})
jQuery(document).ready(function(){
jQuery(".chosen").chosen();
update_words()
});
function update_words(){
var _top = $('#top').val()
var language = $('#language').val()
var country = $('#country').val()
var genre = $('#genre').val()
var start_year = $('#start_year').val()
var end_year = $('#end_year').val()
url = 'http://localhost:5000/api/keywords?'
if (_top.length>0){url = url + 'top=' + _top + '&'}
if (language.length>0){url = url + 'language=' + language + '&'}
if (country.length>0){url = url + 'country=' + country + '&'}
if (genre.length>0){url = url + 'genre=' + genre + '&'}
if (start_year.length>0){url = url + 'start_year=' + start_year + '&'}
if (end_year.length>0){url = url + 'end_year=' + end_year + '&'}
var words = $.get(url)
words.done(function(data){
$('#word_cloud').html('')
$('#word_cloud').jQCloud(words.responseJSON, {
width: 500,
height: 350,
classPattern: null,
colors: ['#800026', '#bd0026', '#e31a1c', '#fc4e2a', '#fd8d3c', '#feb24c', '#fed976', '#ffeda0', '#ffffcc'],
fontSize: {
from: 0.1,
to: 0.02
}
});
})
}

View file

@ -23,35 +23,3 @@
</div> </div>
</div> </div>
<div id='word_cloud'></div>
<script type="text/javascript">
jQuery(document).ready(function(){
jQuery(".chosen").chosen();
update_words()
});
$('#top').change(function(){update_words()})
function update_words(){
var top = $('#top').val()
//+ '&language=' + language + '&country=' + country + '&genre=' + genre + '&end_year=' + end_year + ' &start_year=' + start_year
var words = $.get('http://localhost:5000/api/keywords?top=' + top)
words.done(function(data){
$('#word_cloud').html('')
$('#word_cloud').jQCloud(words.responseJSON, {
width: 500,
height: 350,
classPattern: null,
colors: ['#800026', '#bd0026', '#e31a1c', '#fc4e2a', '#fd8d3c', '#feb24c', '#fed976', '#ffeda0', '#ffffcc'],
fontSize: {
from: 0.1,
to: 0.02
}
});
})
}
</script>

View file

@ -3,14 +3,22 @@
{% block title %}enthusiast{% endblock %} {% block title %}enthusiast{% endblock %}
{% block head %} {% block head %}
{{ super() }} {{ super() }}
<!-- Load d3.js and c3.js --> <!-- Load d3.js and c3.js -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jqcloud/1.0.4/jqcloud.css"> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jqcloud/1.0.4/jqcloud.css">
<script src='http://d3js.org/d3.v3.min.js' charset='utf-8'></script> <script src='http://d3js.org/d3.v3.min.js' charset='utf-8'></script>
<script src='http://cdnjs.cloudflare.com/ajax/libs/c3/0.4.10/c3.min.js'></script> <script src='http://cdnjs.cloudflare.com/ajax/libs/c3/0.4.10/c3.min.js'></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<link rel="stylesheet" href="static/node_modules/chosen-js/chosen.css"> <link rel="stylesheet" href="static/node_modules/chosen-js/chosen.css">
<script src="static/node_modules/chosen-js/chosen.jquery.js"></script> <script src="static/node_modules/chosen-js/chosen.jquery.js"></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/jqcloud/1.0.4/jqcloud-1.0.4.min.js'></script> <script src='https://cdnjs.cloudflare.com/ajax/libs/jqcloud/1.0.4/jqcloud-1.0.4.min.js'></script>
<link rel='stylesheet' type='text/css' href='static/css/custom.css'> <link rel='stylesheet' type='text/css' href='static/css/custom.css'>
{% endblock %}
{% block body %}
{{ super ()}}
{{ form | safe }}
<div id='word_cloud'></div>
<script src='static/js/enthusiast.js'></script>
{% endblock %} {% endblock %}

View file

@ -12,4 +12,8 @@
<script src="static/node_modules/chosen-js/chosen.jquery.js"></script> <script src="static/node_modules/chosen-js/chosen.jquery.js"></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/jqcloud/1.0.4/jqcloud-1.0.4.min.js'></script> <script src='https://cdnjs.cloudflare.com/ajax/libs/jqcloud/1.0.4/jqcloud-1.0.4.min.js'></script>
<link rel='stylesheet' type='text/css' href='static/css/custom.css/'> <link rel='stylesheet' type='text/css' href='static/css/custom.css/'>
{% endblock %}
{% block body %}
{{ super ()}}
{% endblock %} {% endblock %}

View file

@ -12,11 +12,12 @@
<link href='https://cdnjs.cloudflare.com/ajax/libs/c3/0.4.10/c3.min.css' rel='stylesheet' type='text/css'/> <link href='https://cdnjs.cloudflare.com/ajax/libs/c3/0.4.10/c3.min.css' rel='stylesheet' type='text/css'/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link rel='stylesheet' type='text/css' href='static/css/custom.css'>
{% endblock %} {% endblock %}
</head> </head>
<body> <body>
{% block body %}
{% set navigation_bar = [ {% set navigation_bar = [
('/investor', 'investor', 'Investor'), ('/investor', 'investor', 'Investor'),
@ -44,6 +45,6 @@
</nav> </nav>
{{ body | safe }} {{ body | safe }}
{% endblock %}
</body> </body>
</html> </html>