Commit cfa657e4da34ac7d5fba1a8e9576a4e09c587ebe
1 parent
76ebea63
Exists in
master
and in
1 other branch
updating script
Showing
2 changed files
with
24 additions
and
6 deletions
Show diff stats
script/export_ranking.rb
... | ... | @@ -2,7 +2,11 @@ |
2 | 2 | |
3 | 3 | require 'csv' |
4 | 4 | |
5 | +group_control = YAML.load(File.read(File.join(Rails.root,'tmp','control_group.yml'))) if File.exist?(File.join(Rails.root,'tmp','control_group.yml')) | |
6 | + | |
7 | + | |
5 | 8 | profile_ids = GamificationPlugin::PointsCategorization.select(:profile_id).group(:profile_id).map(&:profile_id) |
9 | +profile_ids.keep_if { |item| group_control.keys.include?(item) } unless group_control.nil? | |
6 | 10 | profile_ids.each do |profile_id| |
7 | 11 | profile = Profile.where(id: profile_id).first |
8 | 12 | if profile.nil? |
... | ... | @@ -19,16 +23,18 @@ profile_ids.each do |profile_id| |
19 | 23 | quantities_labels = ['quantidade de votos realizados', 'quantidade de amigos', 'votos positivos recebidos', 'votos negativos recebidos', 'quantidade de artigos', 'quantidade de comentários realizados', 'quantidade de comentários recebidos', 'quatidade de vezes que eu segui', 'quantidade de vezes que meus artigos foram seguidos'] |
20 | 24 | |
21 | 25 | csv << ['identifier', 'name', 'score'] + categories_labels + quantities_labels |
22 | - amount = Person.count | |
26 | + conditions = group_control.nil? ? {} : {:identifier => group_control[profile_id]['profiles']} | |
27 | + amount = Person.find(:all, :conditions => conditions).count | |
23 | 28 | count = 0 |
24 | - Person.find_each do |person| | |
29 | + | |
30 | + Person.find_each(:conditions => conditions) do |person| | |
25 | 31 | count += 1 |
26 | 32 | gamification_categories = categories.map{ |c| GamificationPlugin::PointsCategorization.for_type(c).where(profile_id: profile_id).first} |
27 | 33 | categories_values = gamification_categories.map{|c| person.score_points(:category => c.id.to_s).sum(:num_points)} |
28 | 34 | if (profile.nil?) |
29 | - person_articles = Article.where(:author_id => person.id) | |
35 | + person_articles = Article.where(:author_id => person.id, :type => Article.text_article_types + ['ProposalsDiscussionPlugin::Proposal']) | |
30 | 36 | else |
31 | - person_articles = profile.articles.where(:author_id => person.id) | |
37 | + person_articles = profile.articles.where(:author_id => person.id, :type => Article.text_article_types + ['ProposalsDiscussionPlugin::Proposal']) | |
32 | 38 | end |
33 | 39 | puts "Exporting '#{person.identifier}' #{count}/#{amount}" |
34 | 40 | ... | ... |
script/process_merit_rules.rb
... | ... | @@ -33,26 +33,38 @@ end |
33 | 33 | |
34 | 34 | Merit.observers << 'ProcessObserver' |
35 | 35 | |
36 | +class Article < ActiveRecord::Base | |
37 | + def self.text_article_types | |
38 | + ['TextArticle', 'TextileArticle', 'TinyMceArticle', 'ProposalsDiscussionPlugin::Proposal'] | |
39 | + end | |
40 | +end | |
41 | + | |
36 | 42 | Environment.all.each do |environment| |
43 | + puts "Process environment #{environment.name}" | |
37 | 44 | |
38 | 45 | Merit::AppPointRules.clear |
39 | 46 | Merit::AppBadgeRules.clear |
40 | 47 | Merit::AppPointRules.merge!(Merit::PointRules.new(environment).defined_rules) |
41 | 48 | Merit::AppBadgeRules.merge!(Merit::BadgeRules.new(environment).defined_rules) |
42 | 49 | |
43 | - article_count = environment.articles.text_articles.count | |
50 | + article_count = environment.articles.where(:type => Article.text_article_types + ['ProposalsDiscussionPlugin::Proposal']).count | |
44 | 51 | article_index = 0 |
45 | - environment.articles.text_articles.find_each do |article| | |
52 | + | |
53 | + puts "Amount of articles '#{article_count}'" | |
54 | + environment.articles.where(:type => Article.text_article_types + ['ProposalsDiscussionPlugin::Proposal']).find_each do |article| | |
46 | 55 | article_index += 1 |
56 | + puts "Analising article #{article_index} of #{article_count}" | |
47 | 57 | create_action(article, article_index, article_count) |
48 | 58 | |
49 | 59 | comment_count = article.comments.count |
50 | 60 | article.comments.each.with_index(1) do |comment, i| |
61 | + puts "Analising comments of article '#{article.id}': comment #{i} of #{comment_count}" | |
51 | 62 | create_action(comment, i, comment_count) |
52 | 63 | end |
53 | 64 | |
54 | 65 | followed_articles_count = article.article_followers.count |
55 | 66 | article.article_followers.each_with_index do |af, i| |
67 | + puts "Analising follow of article '#{article.id}': follow #{i} of #{followed_articles_count}" | |
56 | 68 | create_action(af, i, followed_articles_count) |
57 | 69 | end |
58 | 70 | end | ... | ... |