Commit d8043c6f290e29d6033d442f8dad9b36f04e687e
Exists in
master
and in
1 other branch
Merge branch 'master' of gitlab.com:noosfero-plugins/gamification
Showing
1 changed file
with
18 additions
and
10 deletions
Show diff stats
script/export_ranking.rb
... | ... | @@ -26,29 +26,37 @@ profile_ids.each do |profile_id| |
26 | 26 | conditions = group_control.nil? ? {} : {:identifier => group_control[profile_id]['profiles']} |
27 | 27 | amount = Person.find(:all, :conditions => conditions).count |
28 | 28 | count = 0 |
29 | - | |
29 | + | |
30 | 30 | Person.find_each(:conditions => conditions) do |person| |
31 | 31 | count += 1 |
32 | 32 | gamification_categories = categories.map{ |c| GamificationPlugin::PointsCategorization.for_type(c).where(profile_id: profile_id).first} |
33 | 33 | categories_values = gamification_categories.map{|c| person.score_points(:category => c.id.to_s).sum(:num_points)} |
34 | - if (profile.nil?) | |
35 | - person_articles = Article.where(:author_id => person.id, :type => Article.text_article_types + ['ProposalsDiscussionPlugin::Proposal']) | |
34 | + if profile.nil? | |
35 | + person_articles = Article.where(:author_id => person.id) | |
36 | + person_up_votes = person.comments.joins(:votes).where('vote > 0').count + person_articles.joins(:votes).where('vote > 0').count | |
37 | + person_down_votes = person.comments.joins(:votes).where('vote < 0').count + person_articles.joins(:votes).where('vote < 0').count | |
38 | + person_comments = person.comments.count | |
39 | + person_followers = (person.following_articles & person.article_followers.where(article_id: person_articles)).count | |
36 | 40 | else |
37 | - person_articles = profile.articles.where(:author_id => person.id, :type => Article.text_article_types + ['ProposalsDiscussionPlugin::Proposal']) | |
41 | + person_articles = profile.articles.where(:author_id => person.id) | |
42 | + person_up_votes = person.comments.where(:source_id => profile.articles).joins(:votes).where('vote > 0').count + person_articles.joins(:votes).where('vote > 0').count | |
43 | + person_down_votes = person.comments.where(:source_id => profile.articles).joins(:votes).where('vote < 0').count + person_articles.joins(:votes).where('vote < 0').count | |
44 | + person_comments = person.comments.where(:source_id => profile.articles).count | |
45 | + person_followers = (person.following_articles & person.article_followers.where(article_id: profile.articles)).count | |
38 | 46 | end |
39 | - puts "Exporting '#{person.identifier}' #{count}/#{amount}" | |
40 | - | |
41 | 47 | quantities_values = [ |
42 | 48 | Vote.for_voter(person).count, |
43 | 49 | person.friends.count, |
44 | - person.comments.where(:source_id => person_articles).joins(:votes).where('vote > 0').count + person_articles.joins(:votes).where('vote > 0').count, | |
45 | - person.comments.where(:source_id => person_articles).joins(:votes).where('vote < 0').count + person_articles.joins(:votes).where('vote < 0').count, | |
50 | + person_up_votes, | |
51 | + person_down_votes, | |
46 | 52 | person_articles.count, |
47 | - person.comments.where(source_id: person_articles).count, | |
48 | 53 | Comment.where(:source_id => person_articles).count, |
49 | - (person.following_articles & person.article_followers.where(article_id: person_articles)).count, | |
54 | + person_followers, | |
50 | 55 | ArticleFollower.where(:article_id => person_articles).count |
51 | 56 | ] |
57 | + | |
58 | + puts "Exporting '#{person.identifier}' #{count}/#{amount}" | |
59 | + | |
52 | 60 | csv << [person.identifier, person.name, person.points] + categories_values + quantities_values |
53 | 61 | end |
54 | 62 | end | ... | ... |