Continued updates for /enthusiast draft

This commit is contained in:
walkews 2017-07-14 16:08:27 -05:00
parent 04e8135cf0
commit e82149c072
7 changed files with 184 additions and 18 deletions

View file

@ -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 = '<img src=' + info.responseJSON['Poster'] + '>'
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'] + '<br> <img src=' + promises[i].responseJSON['Poster'] + '><br><br>'
$('#poster-' + i).html('<img src=' + promises[i].responseJSON['Poster'] + '>')
$('#title-' + i).html(promises[i].responseJSON['Title'])
}
// $('#top_movies').html(h)
// console.log(h)
})
// console.log(poster(title))
}
)
}