Created
October 25, 2013 13:47
-
-
Save danishsatkut/7154965 to your computer and use it in GitHub Desktop.
English, Hindi top 10 top rated, most rated movies by decades
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
english_group_id = LanguageCountry.joins(:language).where("language = 'English'").pluck(:group_id).uniq.first | |
hindi_group_id = LanguageCountry.joins(:language).where("language = 'Hindi'").pluck(:group_id).uniq.first | |
def write_csv(name, movies) | |
path = "#{Rails.root.to_s}/log/#{name}.csv" | |
CSV.open(path, "a+") do |csv| | |
csv << [] | |
movies.each do |movie| | |
csv << [movie[:release_year], movie[:engtitle], movie[:cached_avg_rating], movie[:cached_times_rated]] | |
end | |
end | |
end | |
decades = [[1950, 1959], [1960, 1969], [1970, 1979], [1980, 1989], [1990, 1999], [2001, 2013]] | |
decades.map do |pair| | |
start_year, end_year = pair | |
puts "\n\n---------------------------------------------" | |
puts "Decade: #{start_year} - #{end_year}" | |
movies = Movie.where("cached_times_rated >= 10").where("release_year BETWEEN ? AND ? ", start_year, end_year).limit(10); movies.count | |
most_rated = movies.order("cached_times_rated DESC"); nil | |
top_rated = movies.order("cached_avg_rating DESC"); nil | |
# English | |
english_most_rated = most_rated.joins(:movie_language_country_groups).where("group_id = ? ", english_group_id).to_a; english_most_rated.length == 10 | |
puts "## English Most rated: " + english_most_rated.collect(&:cached_times_rated).inspect | |
puts english_most_rated.collect(&:engtitle) | |
write_csv("english_most_rated", english_most_rated) | |
english_top_rated = top_rated.joins(:movie_language_country_groups).where("group_id = ? ", english_group_id).to_a; english_top_rated.length == 10 | |
puts "## English Top Rated: " + english_top_rated.collect(&:cached_avg_rating).inspect | |
puts english_top_rated.collect(&:engtitle) | |
write_csv("english_top_rated", english_top_rated) | |
# Hindi | |
hindi_most_rated = most_rated.joins(:movie_language_country_groups).where("group_id = ? ", hindi_group_id).to_a; hindi_most_rated.length == 10 | |
puts "## Hindi Most rated: " + hindi_most_rated.collect(&:cached_times_rated).inspect | |
puts hindi_most_rated.collect(&:engtitle) | |
write_csv("hindi_most_rated", hindi_most_rated) | |
hindi_top_rated = top_rated.joins(:movie_language_country_groups).where("group_id = ? ", hindi_group_id).to_a; hindi_top_rated.length == 10 | |
puts "## Hindi Top Rated: " + hindi_top_rated.collect(&:cached_avg_rating).inspect | |
puts hindi_top_rated.collect(&:engtitle) | |
write_csv("hindi_top_rated", hindi_top_rated) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment