diff --git a/src/pyDataVizDay.py b/src/pyDataVizDay.py
index d6a80aa..c460835 100644
--- a/src/pyDataVizDay.py
+++ b/src/pyDataVizDay.py
@@ -26,8 +26,11 @@ app = Flask(__name__)
CORS(app)
api_blueprint = Blueprint('api', __name__, url_prefix='/api')
api = Api(api_blueprint, title='pyDataVizday api',
+ default='pyDataVizDay',
description='This api is used for the pyDataVizDay visualization',
- doc='/doc/')
+ doc='/doc/',
+ version='0.0.1'
+ )
app.register_blueprint(api_blueprint)
parser = reqparse.RequestParser()
@@ -50,6 +53,20 @@ dropdowns = {'genre': data.genre.genres.dropna().drop_duplicates().values.tolist
'language':data.movie.language.dropna().drop_duplicates().values.tolist()
}
+
+def return_csv(df, filename='data.csv'):
+ try:
+ s_buf = io.StringIO()
+ df.to_csv(s_buf)
+ response = make_response(s_buf.getvalue())
+ cd = 'attachment; filename={}.csv'.format(filename)
+ response.headers['Content-Disposition'] = cd
+ response.mimetype = 'text/csv'
+ except AttributeError:
+ response = 'AttributeError'
+ return response
+
+
@app.route('/')
def index():
return render_template('index.html', body='Hello')
@@ -121,6 +138,23 @@ class keywords(Resource):
return jsonify(words)
+@api.route('/top_movies')
+@api.expect(parser)
+class top_movies(Resource):
+ def get(self):
+ args = parser.parse_args()
+ data = filter_with_args(args)
+
+ df = (data.movie
+ .sort_values('imdb_score', ascending=False)
+ .drop_duplicates(subset=['movie_title'])
+ .set_index('movie_title')
+ [['title_year', 'imdb_score', 'gross']]
+ .head(6)
+ )
+
+ return jsonify(df.to_json())
+
@api.route('/score_timeseries')
@api.expect(parser)
class score_timeseries(Resource):
@@ -148,13 +182,22 @@ class score_timeseries(Resource):
['x'] + df.DATE.astype(str).values.tolist()],
# ['x'] + df.index.values.tolist()],
'colors':{
- 'IMDB Score': '#6998A6',
- 'gross': '#966001',
+ 'IMDB Score': '#B80000',
+ 'gross': '#fd8d3c',
'x': '#08414C'
}}
-
return jsonify(score_timeseries)
+@api.route('/download')
+@api.expect(parser)
+class download(Resource):
+ def get(self):
+ args = parser.parse_args()
+ data = filter_with_args(args)
+ df = data.movie
+ return return_csv(df, 'movie.csv')
+
+
if __name__ == '__main__':
app.jinja_env.auto_reload = True
app.config['TEMPLATES_AUTO_RELOAD'] = True
diff --git a/src/static/css/custom.css b/src/static/css/custom.css
index 79a8538..54df319 100644
--- a/src/static/css/custom.css
+++ b/src/static/css/custom.css
@@ -3,7 +3,7 @@ body{
/*font-size:16px;*/
}
.kpi {
- color: #B80000;
+ /* color: #B80000; */
font-weight:10;
}
@@ -43,4 +43,16 @@ body{
.centered{
float: none;
margin: 0 auto;
+}
+
+.title{
+ font-size:22px;
+ color:#B80000;
+ font: bold;
+}
+
+.sentiment-chart{
+text-align: center;
+vertical-align: middle;
+line-height: 200px;
}
\ No newline at end of file
diff --git a/src/static/js/enthusiast.js b/src/static/js/enthusiast.js
index 2dad2f8..376034f 100644
--- a/src/static/js/enthusiast.js
+++ b/src/static/js/enthusiast.js
@@ -1,5 +1,8 @@
var score_timeseries = document.getElementById('timeseries');
var mil = d3.format('$.3s')
+var update_freq = 200
+
+
var data = {
'size': {
'height': 300
@@ -23,8 +26,8 @@ var data = {
]
],
'colors': {
- 'IMDB Score': '#6998A6',
- 'gross': '#966001',
+ 'IMDB Score': '#B80000',
+ 'gross': '#fd8d3c',
'x': '#08414C'
}
},
@@ -74,8 +77,13 @@ var data = {
$('#year').html(year)
$('#score').html(score)
$('#gross').html(gross)
- update_words_year(year)
- t = data
+ if ((performance.now() - window.last_update)>update_freq)
+ {
+ window.last_update = performance.now()
+ var year = data[0]['x'].getYear()+1900
+ update_words_year(year)
+ update_top_movies(String(parseInt(year) - 1), String(parseInt(year) + 1))
+ }
}
}
};
@@ -110,6 +118,7 @@ $('#country').change(function(){update_all()})
$('#genre').change(function(){update_all()})
$('#start_year').change(function(){update_all()})
$('#end_year').change(function(){update_all()})
+$('#download').click(function(){download()})
jQuery(document).ready(function(){
jQuery(".chosen").chosen();
@@ -117,22 +126,34 @@ jQuery(document).ready(function(){
$('#word_cloud').jQCloud([{'text':'pyDataVizDay', 'weight':1}], word_coud_settings)
update_all()
+
});
+function download(){
+ url = url_params('/api/download?')
+ window.location = url
+}
function update_all(){
update_words()
update_ts()
+ update_top_movies()
+ last_update = performance.now()
}
-function url_params(base)
+function url_params(base, start_year_val, end_year_val)
{
+
+ // start_year = typeof start_year_val !== 'undefined' ? start_year.val()
+ var start_year_val = typeof start_year_val !== 'undefined' ? start_year_val: start_year.val()
+ var end_year_val = typeof end_year_val !== 'undefined' ? end_year_val: end_year.val()
+
var url = base
if (_top.val().length>0){url = url + 'top=' + _top.val() + '&'}
if (language.val().length>0){url = url + 'language=' + language.val() + '&'}
if (country.val().length>0){url = url + 'country=' + country.val() + '&'}
if (genre.val().length>0){url = url + 'genre=' + genre.val() + '&'}
- if (start_year.val().length>0){url = url + 'start_year=' + start_year.val() + '&'}
- if (end_year.val().length>0){url = url + 'end_year=' + end_year.val() + '&'}
+ if (start_year_val>0){url = url + 'start_year=' + String(start_year_val) + '&'}
+ if (end_year_val>0){url = url + 'end_year=' + String(end_year_val) + '&'}
return url
}
@@ -165,6 +186,51 @@ function update_words()
})
}
+poster_img = '';
+function poster(title){
+ console.log(title)
+ var info = $.get('http://www.omdbapi.com/?t=' + title + '&apikey=90424a9e')
+ return info.done( function(){
+ poster_img = ''
+ console.log(poster_img)
+ return poster_img
+ }
+ )
+ }
+
+function update_top_movies(start_year, end_year)
+{
+ var url = url_params('/api/top_movies?', start_year, end_year)
+
+ var top_movies = $.get(url)
+ var promises = []
+ top_movies.done(function()
+ {
+ tm = JSON.parse(top_movies.responseJSON)
+ h = ''
+ for (title in tm['gross']) {
+ // console.log(title)
+ var info = $.get('http://www.omdbapi.com/?t=' + title + '&apikey=90424a9e')
+ promises.push(info)
+ }
+ $.when.apply(null, promises).done(function(){
+ // console.log(promises)
+ window.promises = promises
+ for (i in promises){
+ console.log()
+ h = promises[i].responseJSON['Title'] + '
'
+ $('#poster-' + i).html('')
+ $('#title-' + i).html(promises[i].responseJSON['Title'])
+
+ }
+ // $('#top_movies').html(h)
+ // console.log(h)
+})
+ // console.log(poster(title))
+ }
+
+ )
+}
diff --git a/src/templates/data_form.html b/src/templates/data_form.html
index 6f8ffd2..b516300 100644
--- a/src/templates/data_form.html
+++ b/src/templates/data_form.html
@@ -25,7 +25,11 @@
{% endfor %}
+