extract_gamification_itens
4.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
#!/usr/bin/env ruby
require File.dirname(__FILE__) + '/../config/environment'
communities = Community.public(:order => :created_at)
file = File.open('communities.csv', 'w+')
file.write("'Identifier','Qtd Artigos'\n")
communities.map do |c|
line = "'#{c.identifier}','#{c.articles.count}'\n"
puts line
file.write(line)
end
file.write("\n")
file.write("'Identifier','Qtd Membros'\n")
communities.map do |c|
line = "'#{c.identifier}','#{c.members.count}'\n"
puts line
file.write(line)
end
file.write("\n")
file.write("'Identifier','Qtd Atividades'\n")
communities.map do |c|
line = "'#{c.identifier}','#{c.activities.count}'\n"
puts line
file.write(line)
end
file.close
file = File.open('artigos.csv', 'w+')
articles = Article.public(:order => :created_at)
file.write("\n")
file.write("'ID','Views'\n")
articles.map do |a|
line = "'#{a.id}','#{a.hits}'\n"
puts line
file.write(line)
end
file.write("\n")
file.write("'ID','Comentarios'\n")
articles.map do |a|
line = "'#{a.id}','#{a.comments.count}'\n"
puts line
file.write(line)
end
file.write("\n")
file.write("'ID','Votos'\n")
articles.map do |a|
line = "'#{a.id}','#{a.votes.count}'\n"
puts line
file.write(line)
end
file.close
file = File.open('people.csv', 'w+')
people = Person.public(:order => :created_at)
file.write("'Identifier','Qtd Curtidas recebidas'\n")
people.map do |p|
amount = 0
p.articles.text_articles.select(:id).map do |article|
amount += Vote.count(:conditions => {:voteable_id => article.id, :vote => 1})
end
Comment.all(:conditions => {:source_id => p.articles.map{|a|a.id}}, :select => :id).map do |comment|
amount += Vote.count(:conditions => {:voteable_id => comment.id, :vote => 1})
end
line = "'#{p.identifier}','#{amount}'\n"
puts line
file.write(line)
end
file.write("\n")
file.write("'Identifier','Qtd Dislikes recebidos'\n")
people.map do |p|
amount = 0
p.articles.text_articles.select(:id).map do |article|
amount += Vote.count(:conditions => {:voteable_id => article.id, :vote => -1})
end
Comment.all(:conditions => {:source_id => p.articles.map{|a|a.id}}, :select => :id).map do |comment|
amount += Vote.count(:conditions => {:voteable_id => comment.id, :vote => -1})
end
line = "'#{p.identifier}','#{amount * -1}'\n"
puts line
file.write(line)
end
file.write("\n")
file.write("'Identifier','Qtd Curtidas realizadas'\n")
people.map do |p|
line = "'#{p.identifier}','#{Vote.count(:conditions => {:voter_id => p.id})}'\n"
puts line
file.write(line)
end
file.write("\n")
file.write("'Identifier','Qtd Artigos'\n")
people.map do |p|
line = "'#{p.identifier}','#{p.articles.count}'\n"
puts line
file.write(line)
end
file.write("\n")
file.write("'Identifier','Qtd Comentarios Criados'\n")
people.map do |p|
line = "'#{p.identifier}','#{Comment.count(:conditions => {:author_id => p.id})}'\n"
puts line
file.write(line)
end
file.write("\n")
file.write("'Identifier','Qtd Comentarios Recebidos'\n")
people.map do |p|
line = "'#{p.identifier}','#{p.comments_received.count}'\n"
puts line
file.write(line)
end
file.write("\n")
file.write("'Identifier','Qtd Amigos'\n")
people.map do |p|
line = "'#{p.identifier}','#{p.friends.count}'\n"
puts line
file.write(line)
end
file.write("\n")
file.write("'Identifier','Qtd de Comunidades'\n")
people.map do |p|
line = "'#{p.identifier}','#{p.communities.count}'\n"
puts line
file.write(line)
end
file.write("'Identifier','Qtd de Videos Publicados'\n")
people.map do |p|
line = "'#{p.identifier}','#{p.articles.where(:type => 'VideoPlugin::Video').count}'\n"
puts line
file.write(line)
end
file.write("\n")
file.write("'Identifier','Dono de Comunidade com Pessoas'\n")
people.map do |p|
amount = 0
communities.map do |community|
amount += 1 if community.admins.include?(p)
end
line = "'#{p.identifier}','#{amount}'\n"
puts line
file.write(line)
end
file.write("'Identifier','Qtd Artigos com Conteudo Negativo'\n")
people.map do |p|
amount = 0
p.articles.text_articles.select(:id).map do |article|
amount += Vote.count(:conditions => {:voteable_id => article.id, :vote => -1})
end
line = "'#{p.identifier}','#{amount * -1}'\n"
puts line
file.write(line)
end
file.write("\n")
file.write("'Identifier','Qtd Artigos que nao pode ser comentado'\n")
people.map do |p|
amount = 0
p.articles.text_articles.map do |article|
amount += 1 if article.moderate_comments?
end
line = "'#{p.identifier}','#{amount}'\n"
puts line
file.write(line)
end