From cfa657e4da34ac7d5fba1a8e9576a4e09c587ebe Mon Sep 17 00:00:00 2001 From: Leandro Nunes dos Santos Date: Thu, 22 Oct 2015 16:15:52 -0300 Subject: [PATCH] updating script --- script/export_ranking.rb | 14 ++++++++++---- script/process_merit_rules.rb | 16 ++++++++++++++-- 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/script/export_ranking.rb b/script/export_ranking.rb index b3b22cb..1e7a2d3 100644 --- a/script/export_ranking.rb +++ b/script/export_ranking.rb @@ -2,7 +2,11 @@ require 'csv' +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')) + + profile_ids = GamificationPlugin::PointsCategorization.select(:profile_id).group(:profile_id).map(&:profile_id) +profile_ids.keep_if { |item| group_control.keys.include?(item) } unless group_control.nil? profile_ids.each do |profile_id| profile = Profile.where(id: profile_id).first if profile.nil? @@ -19,16 +23,18 @@ profile_ids.each do |profile_id| 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'] csv << ['identifier', 'name', 'score'] + categories_labels + quantities_labels - amount = Person.count + conditions = group_control.nil? ? {} : {:identifier => group_control[profile_id]['profiles']} + amount = Person.find(:all, :conditions => conditions).count count = 0 - Person.find_each do |person| + + Person.find_each(:conditions => conditions) do |person| count += 1 gamification_categories = categories.map{ |c| GamificationPlugin::PointsCategorization.for_type(c).where(profile_id: profile_id).first} categories_values = gamification_categories.map{|c| person.score_points(:category => c.id.to_s).sum(:num_points)} if (profile.nil?) - person_articles = Article.where(:author_id => person.id) + person_articles = Article.where(:author_id => person.id, :type => Article.text_article_types + ['ProposalsDiscussionPlugin::Proposal']) else - person_articles = profile.articles.where(:author_id => person.id) + person_articles = profile.articles.where(:author_id => person.id, :type => Article.text_article_types + ['ProposalsDiscussionPlugin::Proposal']) end puts "Exporting '#{person.identifier}' #{count}/#{amount}" diff --git a/script/process_merit_rules.rb b/script/process_merit_rules.rb index d8ed49a..9519419 100755 --- a/script/process_merit_rules.rb +++ b/script/process_merit_rules.rb @@ -33,26 +33,38 @@ end Merit.observers << 'ProcessObserver' +class Article < ActiveRecord::Base + def self.text_article_types + ['TextArticle', 'TextileArticle', 'TinyMceArticle', 'ProposalsDiscussionPlugin::Proposal'] + end +end + Environment.all.each do |environment| + puts "Process environment #{environment.name}" Merit::AppPointRules.clear Merit::AppBadgeRules.clear Merit::AppPointRules.merge!(Merit::PointRules.new(environment).defined_rules) Merit::AppBadgeRules.merge!(Merit::BadgeRules.new(environment).defined_rules) - article_count = environment.articles.text_articles.count + article_count = environment.articles.where(:type => Article.text_article_types + ['ProposalsDiscussionPlugin::Proposal']).count article_index = 0 - environment.articles.text_articles.find_each do |article| + + puts "Amount of articles '#{article_count}'" + environment.articles.where(:type => Article.text_article_types + ['ProposalsDiscussionPlugin::Proposal']).find_each do |article| article_index += 1 + puts "Analising article #{article_index} of #{article_count}" create_action(article, article_index, article_count) comment_count = article.comments.count article.comments.each.with_index(1) do |comment, i| + puts "Analising comments of article '#{article.id}': comment #{i} of #{comment_count}" create_action(comment, i, comment_count) end followed_articles_count = article.article_followers.count article.article_followers.each_with_index do |af, i| + puts "Analising follow of article '#{article.id}': follow #{i} of #{followed_articles_count}" create_action(af, i, followed_articles_count) end end -- libgit2 0.21.2