Commit 65e1860f8967517f1d011041c65f26b0f4fc88d0
1 parent
e42f5f69
Exists in
master
and in
1 other branch
Improve ranking export
Showing
1 changed file
with
25 additions
and
0 deletions
Show diff stats
... | ... | @@ -0,0 +1,25 @@ |
1 | +# encoding: UTF-8 | |
2 | + | |
3 | +require 'csv' | |
4 | +CSV.open( "ranking_gamification.csv", 'w' ) do |csv| | |
5 | + categories = [:article_author, :comment_author, :comment_article_author, :vote_voteable_author, :vote_voter] | |
6 | + categories_labels = ['autor do artigo', 'autor do comentário', 'comentário recebido no meu artigo', 'voto em meu conteúdo', 'voto realizado'] | |
7 | + 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'] | |
8 | + | |
9 | + csv << ['identifier', 'name', 'score'] + categories_labels + quantities_labels | |
10 | + Person.find_each do |person| | |
11 | + categories_values = categories.map {|c| person.score_points(category: c).sum(:num_points)} | |
12 | + person_articles = Article.where(:author_id => person.id) | |
13 | + | |
14 | + quantities_values = [ | |
15 | + Vote.for_voter(person).count, | |
16 | + person.friends.count, | |
17 | + person.comments.joins(:votes).where('vote > 0').count + person_articles.joins(:votes).where('vote > 0').count, | |
18 | + person.comments.joins(:votes).where('vote < 0').count + person_articles.joins(:votes).where('vote < 0').count, | |
19 | + person_articles.text_articles.count, | |
20 | + person.comments.count, | |
21 | + Comment.where(:source_id => person_articles).count | |
22 | + ] | |
23 | + csv << [person.identifier, person.name, person.points] + categories_values + quantities_values | |
24 | + end | |
25 | +end | ... | ... |