heroku errors for api
This commit is contained in:
parent
81e294f489
commit
01b4b766df
9 changed files with 129 additions and 54 deletions
1
src/__init__.py
Normal file
1
src/__init__.py
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
from pyDataVizDay import *
|
||||||
16
src/etl.py
16
src/etl.py
|
|
@ -82,30 +82,46 @@ class Data(object):
|
||||||
end_year_mask = True
|
end_year_mask = True
|
||||||
|
|
||||||
if genre:
|
if genre:
|
||||||
|
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_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:
|
||||||
|
try:
|
||||||
|
country_mask = data.movie.country.isin(country)
|
||||||
|
except TypeError:
|
||||||
country_mask = data.movie.country == country
|
country_mask = data.movie.country == country
|
||||||
else:
|
else:
|
||||||
country_mask = True
|
country_mask = True
|
||||||
|
|
||||||
if language:
|
if language:
|
||||||
|
try:
|
||||||
|
language_mask = data.movie.language.isin(language)
|
||||||
|
except:
|
||||||
language_mask = data.movie.language == language
|
language_mask = data.movie.language == language
|
||||||
else:
|
else:
|
||||||
language_mask = True
|
language_mask = True
|
||||||
|
|
||||||
if title:
|
if title:
|
||||||
|
try:
|
||||||
|
title_mask = data.movie.movie_title.isin(title)
|
||||||
|
except TypeError:
|
||||||
title_mask = data.movie.movie_title == title
|
title_mask = data.movie.movie_title == title
|
||||||
else:
|
else:
|
||||||
title_mask = True
|
title_mask = True
|
||||||
|
|
||||||
if color:
|
if color:
|
||||||
|
try:
|
||||||
|
color_mask = data.movie.color.isin(color)
|
||||||
|
except TypeError:
|
||||||
color_mask = data.movie.color == color
|
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:
|
||||||
|
|
|
||||||
|
|
@ -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)]
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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{
|
||||||
|
|
|
||||||
49
src/static/js/enthusiast.js
Normal file
49
src/static/js/enthusiast.js
Normal 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
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -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>
|
|
||||||
|
|
@ -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 %}
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block body %}
|
||||||
|
{{ super ()}}
|
||||||
|
{{ form | safe }}
|
||||||
|
<div id='word_cloud'></div>
|
||||||
|
<script src='static/js/enthusiast.js'></script>
|
||||||
|
{% endblock %}
|
||||||
|
|
@ -13,3 +13,7 @@
|
||||||
<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 %}
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block body %}
|
||||||
|
{{ super ()}}
|
||||||
|
{% endblock %}
|
||||||
|
|
@ -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>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue