diff --git a/src/__init__.py b/src/__init__.py new file mode 100644 index 0000000..31154a6 --- /dev/null +++ b/src/__init__.py @@ -0,0 +1 @@ +from pyDataVizDay import * \ No newline at end of file diff --git a/src/etl.py b/src/etl.py index 6fd8984..aa4188f 100644 --- a/src/etl.py +++ b/src/etl.py @@ -82,30 +82,46 @@ class Data(object): end_year_mask = True 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) else: genre_mask = True 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: country_mask = True if language: - language_mask = data.movie.language == language + try: + language_mask = data.movie.language.isin(language) + except: + language_mask = data.movie.language == language else: language_mask = True 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: title_mask = True 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: color_mask = True + masks = genre_mask & start_year_mask & end_year_mask & country_mask & language_mask & title_mask & color_mask try: diff --git a/src/pyDataVizDay.py b/src/pyDataVizDay.py index ff6e932..b92ff1c 100644 --- a/src/pyDataVizDay.py +++ b/src/pyDataVizDay.py @@ -75,7 +75,8 @@ def investor(): @app.route('/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') def slides(): @@ -88,15 +89,40 @@ def slides(): class keywords(Resource): def get(self): 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'], end_year=args['end_year'], genre=args['genre'], country=args['country'], language=args['language'], - top=args['top'], - title=args['title'], - color=args['color'] + top=args['top'] ) + + print(len(keyword_data.movie)) + c = Counter(keyword_data.keyword.plot_keywords.values.tolist()) words = [{'text': word[0], 'weight': word[1]} for word in c.most_common(50)] diff --git a/src/static/css/custom.css b/src/static/css/custom.css index c25ccdf..d543210 100644 --- a/src/static/css/custom.css +++ b/src/static/css/custom.css @@ -9,14 +9,16 @@ body{ .text_input{ height:75px; - width:75%; + width:70%; max-width: 300px; } .chosen{ + float:right; height:75px; - width:75%; + width:70%; max-width: 300px; + padding:5px; } .col-sm-3{ diff --git a/src/static/js/enthusiast.js b/src/static/js/enthusiast.js new file mode 100644 index 0000000..6e57e09 --- /dev/null +++ b/src/static/js/enthusiast.js @@ -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 + } +}); + + }) +} + + diff --git a/src/templates/data_form.html b/src/templates/data_form.html index 3265d82..51fe634 100644 --- a/src/templates/data_form.html +++ b/src/templates/data_form.html @@ -23,35 +23,3 @@ -
- - \ No newline at end of file diff --git a/src/templates/enthusiast.html b/src/templates/enthusiast.html index 25824d0..322d75b 100644 --- a/src/templates/enthusiast.html +++ b/src/templates/enthusiast.html @@ -3,14 +3,22 @@ {% block title %}enthusiast{% endblock %} {% block head %} {{ super() }} - - - - - - - - - + + + + + + + + + + +{% endblock %} + +{% block body %} + {{ super ()}} + {{ form | safe }} + + {% endblock %} \ No newline at end of file diff --git a/src/templates/investor.html b/src/templates/investor.html index d365432..5fc6584 100644 --- a/src/templates/investor.html +++ b/src/templates/investor.html @@ -12,4 +12,8 @@ +{% endblock %} + +{% block body %} + {{ super ()}} {% endblock %} \ No newline at end of file diff --git a/src/templates/layout.html b/src/templates/layout.html index ecda501..94fbdde 100644 --- a/src/templates/layout.html +++ b/src/templates/layout.html @@ -12,11 +12,12 @@ - + {% endblock %} +{% block body %} {% set navigation_bar = [ ('/investor', 'investor', 'Investor'), @@ -44,6 +45,6 @@ {{ body | safe }} - +{% endblock %}