Commit 8326eb9a51d90498a6593fe7a39423d5964ea965
1 parent
cc81e075
Exists in
theme-brasil-digital-from-staging
and in
9 other branches
adding statistics scripts
Showing
7 changed files
with
337 additions
and
0 deletions
Show diff stats
... | ... | @@ -0,0 +1,16 @@ |
1 | +#!/usr/bin/env ruby | |
2 | +require File.dirname(__FILE__) + '/../config/environment' | |
3 | + | |
4 | + | |
5 | +articles = Article.public(:order => :created_at) | |
6 | + | |
7 | +file = File.open('articles.csv', 'w+') | |
8 | + | |
9 | +file.write("'ID','Titulo','Tipo','Criado em','Votos','Comentarios','Hits','Criado Por','Criado Onde'\n") | |
10 | +articles.map do |a| | |
11 | + line = "'#{a.id}','#{a.title}','#{a.type}','#{a.created_at.strftime("%d/%m/%Y")}','#{a.votes.count}','#{a.comments.count}','#{a.hits}','#{a.author ? a.author.identifier : ''}','#{a.profile ? a.profile.identifier : ''}'\n" | |
12 | + puts line | |
13 | + file.write(line) | |
14 | + | |
15 | +end | |
16 | + | ... | ... |
... | ... | @@ -0,0 +1,20 @@ |
1 | +#!/usr/bin/env ruby | |
2 | +require File.dirname(__FILE__) + '/../config/environment' | |
3 | + | |
4 | + | |
5 | +comments = Comment.find(:all, :order => :created_at) | |
6 | + | |
7 | +file = File.open('comments.csv', 'w+') | |
8 | + | |
9 | +file.write("'ID do Artigo','ID do Comentario','Titulo','Criado em','Votos', 'Origem', 'Profile que escreveu','Id que o comentario se refere'\n") | |
10 | +comments.map do |c| | |
11 | +begin | |
12 | + line = "'#{c.source_id}','#{c.id}','#{c.title}','#{c.created_at.strftime("%d/%m/%Y")}','#{c.votes.count}','#{c.profile.identifier}','#{c.author ? c.author.identifier : ''}','#{c.reply_of_id}'\n" | |
13 | + puts line | |
14 | + file.write(line) | |
15 | +rescue | |
16 | + puts "SOMETHING WRONG HAPPENED WITH COMMENT #{c.id}" | |
17 | +end | |
18 | + | |
19 | +end | |
20 | + | ... | ... |
... | ... | @@ -0,0 +1,16 @@ |
1 | +#!/usr/bin/env ruby | |
2 | +require File.dirname(__FILE__) + '/../config/environment' | |
3 | + | |
4 | + | |
5 | +communities = Community.public(:order => :created_at) | |
6 | + | |
7 | +file = File.open('communities.csv', 'w+') | |
8 | + | |
9 | +file.write("'Identifier','Nome','Data de Criacao','Qtd Artigos','Qtd Membros','Qtd Comentatios', 'Membros'\n") | |
10 | +communities.map do |c| | |
11 | + line = "'#{c.identifier}','#{c.name}','#{c.created_at.strftime("%d/%m/%Y")}','#{c.articles.count}','#{c.members.count}','#{c.comments_received.count}', '#{c.members.map{|m|m.identifier}.join('#')}'\n" | |
12 | + puts line | |
13 | + file.write(line) | |
14 | + | |
15 | +end | |
16 | + | ... | ... |
... | ... | @@ -0,0 +1,186 @@ |
1 | +#!/usr/bin/env ruby | |
2 | +require File.dirname(__FILE__) + '/../config/environment' | |
3 | + | |
4 | + | |
5 | +communities = Community.public(:order => :created_at) | |
6 | + | |
7 | +file = File.open('communities.csv', 'w+') | |
8 | + | |
9 | +file.write("'Identifier','Qtd Artigos'\n") | |
10 | +communities.map do |c| | |
11 | + line = "'#{c.identifier}','#{c.articles.count}'\n" | |
12 | + puts line | |
13 | + file.write(line) | |
14 | +end | |
15 | + | |
16 | +file.write("\n") | |
17 | +file.write("'Identifier','Qtd Membros'\n") | |
18 | +communities.map do |c| | |
19 | + line = "'#{c.identifier}','#{c.members.count}'\n" | |
20 | + puts line | |
21 | + file.write(line) | |
22 | +end | |
23 | + | |
24 | +file.write("\n") | |
25 | +file.write("'Identifier','Qtd Atividades'\n") | |
26 | +communities.map do |c| | |
27 | + line = "'#{c.identifier}','#{c.activities.count}'\n" | |
28 | + puts line | |
29 | + file.write(line) | |
30 | +end | |
31 | + | |
32 | +file.close | |
33 | + | |
34 | +file = File.open('artigos.csv', 'w+') | |
35 | +articles = Article.public(:order => :created_at) | |
36 | + | |
37 | +file.write("\n") | |
38 | +file.write("'ID','Views'\n") | |
39 | +articles.map do |a| | |
40 | + line = "'#{a.id}','#{a.hits}'\n" | |
41 | + puts line | |
42 | + file.write(line) | |
43 | +end | |
44 | + | |
45 | +file.write("\n") | |
46 | +file.write("'ID','Comentarios'\n") | |
47 | +articles.map do |a| | |
48 | + line = "'#{a.id}','#{a.comments.count}'\n" | |
49 | + puts line | |
50 | + file.write(line) | |
51 | +end | |
52 | + | |
53 | +file.write("\n") | |
54 | +file.write("'ID','Votos'\n") | |
55 | +articles.map do |a| | |
56 | + line = "'#{a.id}','#{a.votes.count}'\n" | |
57 | + puts line | |
58 | + file.write(line) | |
59 | +end | |
60 | + | |
61 | +file.close | |
62 | +file = File.open('people.csv', 'w+') | |
63 | +people = Person.public(:order => :created_at) | |
64 | + | |
65 | + | |
66 | +file.write("'Identifier','Qtd Curtidas recebidas'\n") | |
67 | +people.map do |p| | |
68 | + amount = 0 | |
69 | + p.articles.text_articles.select(:id).map do |article| | |
70 | + amount += Vote.count(:conditions => {:voteable_id => article.id, :vote => 1}) | |
71 | + end | |
72 | + Comment.all(:conditions => {:source_id => p.articles.map{|a|a.id}}, :select => :id).map do |comment| | |
73 | + amount += Vote.count(:conditions => {:voteable_id => comment.id, :vote => 1}) | |
74 | + end | |
75 | + line = "'#{p.identifier}','#{amount}'\n" | |
76 | + puts line | |
77 | + file.write(line) | |
78 | +end | |
79 | + | |
80 | +file.write("\n") | |
81 | +file.write("'Identifier','Qtd Dislikes recebidos'\n") | |
82 | +people.map do |p| | |
83 | + amount = 0 | |
84 | + p.articles.text_articles.select(:id).map do |article| | |
85 | + amount += Vote.count(:conditions => {:voteable_id => article.id, :vote => -1}) | |
86 | + end | |
87 | + Comment.all(:conditions => {:source_id => p.articles.map{|a|a.id}}, :select => :id).map do |comment| | |
88 | + amount += Vote.count(:conditions => {:voteable_id => comment.id, :vote => -1}) | |
89 | + end | |
90 | + line = "'#{p.identifier}','#{amount * -1}'\n" | |
91 | + puts line | |
92 | + file.write(line) | |
93 | +end | |
94 | + | |
95 | +file.write("\n") | |
96 | +file.write("'Identifier','Qtd Curtidas realizadas'\n") | |
97 | +people.map do |p| | |
98 | + line = "'#{p.identifier}','#{Vote.count(:conditions => {:voter_id => p.id})}'\n" | |
99 | + puts line | |
100 | + file.write(line) | |
101 | +end | |
102 | + | |
103 | +file.write("\n") | |
104 | +file.write("'Identifier','Qtd Artigos'\n") | |
105 | +people.map do |p| | |
106 | + line = "'#{p.identifier}','#{p.articles.count}'\n" | |
107 | + puts line | |
108 | + file.write(line) | |
109 | +end | |
110 | + | |
111 | +file.write("\n") | |
112 | +file.write("'Identifier','Qtd Comentarios Criados'\n") | |
113 | +people.map do |p| | |
114 | + line = "'#{p.identifier}','#{Comment.count(:conditions => {:author_id => p.id})}'\n" | |
115 | + puts line | |
116 | + file.write(line) | |
117 | +end | |
118 | + | |
119 | +file.write("\n") | |
120 | +file.write("'Identifier','Qtd Comentarios Recebidos'\n") | |
121 | +people.map do |p| | |
122 | + line = "'#{p.identifier}','#{p.comments_received.count}'\n" | |
123 | + puts line | |
124 | + file.write(line) | |
125 | +end | |
126 | + | |
127 | +file.write("\n") | |
128 | +file.write("'Identifier','Qtd Amigos'\n") | |
129 | +people.map do |p| | |
130 | + line = "'#{p.identifier}','#{p.friends.count}'\n" | |
131 | + puts line | |
132 | + file.write(line) | |
133 | +end | |
134 | + | |
135 | +file.write("\n") | |
136 | +file.write("'Identifier','Qtd de Comunidades'\n") | |
137 | +people.map do |p| | |
138 | + line = "'#{p.identifier}','#{p.communities.count}'\n" | |
139 | + puts line | |
140 | + file.write(line) | |
141 | +end | |
142 | + | |
143 | +file.write("'Identifier','Qtd de Videos Publicados'\n") | |
144 | +people.map do |p| | |
145 | + line = "'#{p.identifier}','#{p.articles.where(:type => 'VideoPlugin::Video').count}'\n" | |
146 | + puts line | |
147 | + file.write(line) | |
148 | +end | |
149 | + | |
150 | +file.write("\n") | |
151 | +file.write("'Identifier','Dono de Comunidade com Pessoas'\n") | |
152 | +people.map do |p| | |
153 | + amount = 0 | |
154 | + communities.map do |community| | |
155 | + amount += 1 if community.admins.include?(p) | |
156 | + end | |
157 | + line = "'#{p.identifier}','#{amount}'\n" | |
158 | + puts line | |
159 | + file.write(line) | |
160 | +end | |
161 | + | |
162 | +file.write("'Identifier','Qtd Artigos com Conteudo Negativo'\n") | |
163 | +people.map do |p| | |
164 | + amount = 0 | |
165 | + p.articles.text_articles.select(:id).map do |article| | |
166 | + amount += Vote.count(:conditions => {:voteable_id => article.id, :vote => -1}) | |
167 | + end | |
168 | + line = "'#{p.identifier}','#{amount * -1}'\n" | |
169 | + puts line | |
170 | + file.write(line) | |
171 | +end | |
172 | + | |
173 | +file.write("\n") | |
174 | +file.write("'Identifier','Qtd Artigos que nao pode ser comentado'\n") | |
175 | +people.map do |p| | |
176 | + amount = 0 | |
177 | + p.articles.text_articles.map do |article| | |
178 | + amount += 1 if article.moderate_comments? | |
179 | + end | |
180 | + line = "'#{p.identifier}','#{amount}'\n" | |
181 | + puts line | |
182 | + file.write(line) | |
183 | +end | |
184 | + | |
185 | + | |
186 | + | ... | ... |
... | ... | @@ -0,0 +1,30 @@ |
1 | +#!/usr/bin/env ruby | |
2 | +require File.dirname(__FILE__) + '/../config/environment' | |
3 | + | |
4 | + | |
5 | +communities = Community.find(:all, :order => :created_at) | |
6 | + | |
7 | +file = File.open('/tmp/palavraaberta.csv', 'w+') | |
8 | +domain = Domain.find_by_name('palavraaberta.serpro') | |
9 | + | |
10 | +community = domain.owner | |
11 | + | |
12 | +articles = community.articles.find([798926, 378862,1062230,1062444,1063517,1065845,1032289,290145, 989503,963769,964368,974547]) | |
13 | +file.write("'ID','Caminho','Data de Criacao','Votos','Comentarios','Author','Profile'\n") | |
14 | +articles.map do |a| | |
15 | + line = "'#{a.id}','http://voce.serpro/#{a.profile.identifier}/#{a.path}','#{a.created_at.strftime("%d/%m/%Y")}','#{a.votes.count}','#{a.comments.count}','#{a.author ? a.author.identifier : ''}','#{a.profile ? a.profile.identifier : ''}'\n" | |
16 | + puts line | |
17 | + file.write(line) | |
18 | +end | |
19 | + | |
20 | +file.write("\n\n") | |
21 | + | |
22 | +file.write("'ID do Artigo','ID do Comentario','Titulo','Corpo','Criado em','Votos','Author', 'Resposta de'\n") | |
23 | +articles.map do |a| | |
24 | + a.comments.map do |c| | |
25 | + line = "'#{c.source_id}','#{c.id}','#{c.title}','#{c.body.chomp}','#{c.created_at.strftime("%d/%m/%Y")}','#{c.votes.count}','#{c.author ? c.author.identifier : ''}','#{c.reply_of_id}'\n" | |
26 | + puts line | |
27 | + file.write(line) | |
28 | + end | |
29 | +end | |
30 | + | ... | ... |
... | ... | @@ -0,0 +1,16 @@ |
1 | +#!/usr/bin/env ruby | |
2 | +require File.dirname(__FILE__) + '/../config/environment' | |
3 | + | |
4 | + | |
5 | +people = Person.public(:order => :created_at) | |
6 | + | |
7 | +file = File.open('people.csv', 'w+') | |
8 | + | |
9 | +file.write("'ID','Identifier','Nome','Data de Criacao','Qtd Artigos','Qtd Amigos','Qtd Comentatios'\n") | |
10 | +people.map do |p| | |
11 | + line = "'#{p.id}','#{p.identifier}','#{p.name}','#{p.created_at.strftime("%d/%m/%Y")}','#{p.articles.count}','#{p.friends.count}','#{p.comments_received.count}'\n" | |
12 | + puts line | |
13 | + file.write(line) | |
14 | + | |
15 | +end | |
16 | + | ... | ... |
... | ... | @@ -0,0 +1,53 @@ |
1 | +#!/usr/bin/env ruby | |
2 | +require File.dirname(__FILE__) + '/../config/environment' | |
3 | + | |
4 | + | |
5 | +date = Person.find(:first, :order => :created_at).created_at | |
6 | + | |
7 | +file = File.open('data.csv', 'w+') | |
8 | + | |
9 | +file.write("Numero de pessoas por mes\n") | |
10 | +puts "Numero de pessoas por mes" | |
11 | +while(date <= Date.today) do | |
12 | + date = date.beginning_of_month | |
13 | + | |
14 | + amount = Person.count(:conditions => {:created_at => date...date.end_of_month}) | |
15 | + | |
16 | + file.write("#{date.strftime('%m/%Y')},#{amount}\n") | |
17 | + puts "Amount in #{date.strftime('%m/%Y')} #{amount}" | |
18 | + | |
19 | + date = date.next_month | |
20 | + | |
21 | +end | |
22 | + | |
23 | +file.write("Numero de comunidades por mes\n") | |
24 | +puts "Numero de comunidades por mes" | |
25 | +date = Community.find(:first, :order => :created_at).created_at | |
26 | +while(date <= Date.today) do | |
27 | + date = date.beginning_of_month | |
28 | + | |
29 | + amount = Community.count(:conditions => {:created_at => date...date.end_of_month}) | |
30 | + | |
31 | + file.write("#{date.strftime('%m/%Y')},#{amount}\n") | |
32 | + puts "Amount in #{date.strftime('%m/%Y')} #{amount}" | |
33 | + | |
34 | + date = date.next_month | |
35 | + | |
36 | +end | |
37 | + | |
38 | +file.write("Numero de artigos por mes\n") | |
39 | +puts "Numero de artigos por mes" | |
40 | +date = Article.find(:first, :order => :created_at).created_at | |
41 | +while(date <= Date.today) do | |
42 | + date = date.beginning_of_month | |
43 | + | |
44 | + amount = Article.count(:conditions => {:created_at => date...date.end_of_month}) | |
45 | + | |
46 | + file.write("#{date.strftime('%m/%Y')},#{amount}\n") | |
47 | + puts "Amount in #{date.strftime('%m/%Y')} #{amount}" | |
48 | + | |
49 | + date = date.next_month | |
50 | + | |
51 | +end | |
52 | + | |
53 | +file.close | ... | ... |