-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcharts.rake
275 lines (234 loc) · 9.8 KB
/
charts.rake
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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
require 'active_record'
require 'iconv'
require 'pp'
require 'gchart'
namespace :redmine do
task :send_charts=>:environment do
module Charts
class ChartMailer < Mailer
def send_charts(users,title,content)
recipients users
subject title + ' Bug informations'
body content
content_type "text/html"
end
end
def self.gen
@projects = Project.find(:all)
due = 7
@projects.each do |project|
chart_dev = create_issue_day_resolved_status_chart(due, project.id)
issueinfo = issue_day_create_status(due, project.id)
issue_day_create_status_chart =
Gchart.line(:title => "Last 7 day issue by reportor",
:theme => :greyscale,
:size => '700x200',
:data => issueinfo[0],
:legend => issueinfo[1],
:axis_labels => issueinfo[2],
:axis_with_labels => 'x'
)
issueinfo = issue_by_creator(project.id)
issue_by_creator_chart =
Gchart.pie_3d(
:theme => :thirty7signals,
:size => '400x200',
:data => issueinfo[0],
:labels=> issueinfo[1],
:title => 'All bugs by reporter'
)
issueinfo = issue_by_assigner(project.id)
issue_by_assigner_chart=
Gchart.pie_3d(
:theme => :thirty7signals,
:size => '400x200',
:data => issueinfo[0],
:labels=> issueinfo[1],
:title => 'Unresolved bugs'
)
issueinfo = issue_create_today(due, project.id)
issue_create_today_chart=
Gchart.pie_3d(
:theme => :thirty7signals,
:size => '400x200',
:data => issueinfo[0],
:labels=> issueinfo[1],
:title => 'Today reported'
)
content =
"<img src=#{issue_by_creator_chart}></img>" +
"<img src=#{issue_create_today_chart}></img>" +
"<img src=#{issue_by_assigner_chart}></img>" +
"<img src=#{issue_day_create_status_chart}></img>"
chart_dev.each do |c|
content += "<img src=#{c}><img>"
end
users = ''
project.users.each do |u|
if u.admin
if users.length > 0
users += ','
end
users += u.mail
end
end
ChartMailer.deliver_send_charts(users,project.name,content)
end
end
def self.create_issue_day_resolved_status_chart(due, project_id)
issues = Issue.find_by_sql [
"select i.assigned_to_id,count(1) as c, concat(u.firstname,u.lastname) as name from issues i,users u where i.assigned_to_id = u.id and i.status_id in (1,2,4,7) and i.project_id = ? group by i.assigned_to_id,name", project_id
]
charts = []
issues.each do |i|
if i.c.to_i > 0
issuesinfos = issue_day_resolved_status(i.assigned_to_id.to_i, due, project_id)
charts <<
Gchart.line(:title => "Last 7 day issue by resolved by " + i.name,
:theme => :greyscale,
:size => '550x200',
:data => issuesinfos[0],
:axis_labels => issuesinfos[1],
:axis_with_labels => 'x'
)
end
end
charts
end
def self.issue_day_resolved_status(user_id, due, project_id)
if due == 0
due = 7
end
axis_labels = []
x_labels = []
t = Time.now()
axis_labels << t.strftime('%Y-%m-%d')
x_labels << t.strftime('%m-%d')
step = 24 * 60 * 60
(1..due).each do |d|
t1 = t - d * step
axis_labels << t1.strftime('%Y-%m-%d')
x_labels << t1.strftime('%m-%d')
end
issues = Issue.find_by_sql [
"select count(1) c,CONCAT(u.firstname,u.lastname) name,DATE_FORMAT(j.created_on,'%Y-%m-%d') create_date from " +
" journals j, " +
" journal_details jd, " +
" issues i , " +
" users u " +
"where " +
" i.assigned_to_id = u.id " +
"and " +
" i.assigned_to_id = ? " +
"and " +
" i.id = j.journalized_id " +
"and " +
" j.journalized_type = 'issue' " +
"and " +
" j.id = jd.journal_id " +
"and " +
" jd.old_value = 3 " +
"and " +
" jd.value = 5 " +
"and " +
" i.project_id = ? " +
"and " +
" to_days(now()) - to_days(j.created_on) <= ? " +
"group by name,create_date ",
user_id, project_id, due
]
data = Hash.new
axis_labels.each do |al|
data.store(al, 0)
end
issues.each do |i|
data[i.create_date] =i.c
end
tmp = []
data.sort.each do |d|
tmp << d[1].to_i
end
x_labels_arr = []
x_labels_arr << x_labels.reverse * '|'
[tmp, x_labels_arr]
end
def self.issue_day_create_status(due, project_id)
if due == 0
due = 7
end
axis_labels = []
x_labels = []
legend = []
t = Time.now()
axis_labels << t.strftime('%Y-%m-%d')
x_labels << t.strftime('%m-%d')
step = 24 * 60 * 60
(1..due).each do |d|
t1 = t - d * step
axis_labels << t1.strftime('%Y-%m-%d')
x_labels << t1.strftime('%m-%d')
end
axis_labels = axis_labels.reverse
authors = Issue.find_by_sql ['select distinct i.author_id author_id,CONCAT(u.firstname,u.lastname) name from issues i,users u where i.author_id = u.id and to_days(now())-to_days(i.created_on)<= ? and i.project_id = ? and i.status_id in (1,2,4,7) group by author_id', due, project_id]
author_ids = []
authors.each do |a|
legend << a.name
author_ids << a.author_id
end
ret_val = []
author_ids.each do |a|
issues = Issue.find_by_sql ['select count(1) c ,DATE_FORMAT(i.created_on,"%Y-%m-%d") as create_date from issues i,users u where i.author_id = u.id and to_days(now())-to_days(i.created_on)<= ? and i.project_id = ? and i.status_id in (1,2,4,7) and author_id = ? group by create_date', due, project_id, a]
data = Hash.new
axis_labels.each do |al|
data.store(al, 0)
end
issues.each do |i|
data[i.create_date] =i.c
end
tmp = []
data.sort.each do |d|
tmp << d[1].to_i
end
ret_val << tmp
end
x_labels_arr = []
x_labels_arr << x_labels.reverse * '|'
[ret_val, legend, x_labels_arr]
end
def self.issue_create_today(due, project_id)
if due == 0
due = 0
end
issues = Issue.find_by_sql ['select count(1) c ,CONCAT(u.firstname,u.lastname) name from issues i,users u where i.author_id = u.id and to_days(now())-to_days(i.created_on) <= ? and i.project_id = ? and i.status_id in (1,2,4,7) group by author_id', due, project_id]
v = []
d = []
issues.each do |issue|
v << issue.c.to_i
d << issue.name+"("+issue.c+")"
end
[v, d]
end
def self.issue_by_creator(project_id)
issues = Issue.find_by_sql ['select count(1) c ,CONCAT(u.firstname,u.lastname) name from issues i,users u where i.author_id = u.id and i.project_id = ? and i.status_id in (1,2,4,7) group by author_id', project_id]
v = []
d = []
issues.each do |issue|
v << issue.c.to_i
d << issue.name + "(" + issue.c + ")"
end
[v, d]
end
def self.issue_by_assigner(project_id)
issues = Issue.find_by_sql ['select count(1) c ,CONCAT(u.firstname,u.lastname) name from issues i,users u where i.assigned_to_id = u.id and i.project_id = ? and i.status_id in (1,2,4,7) group by assigned_to_id', project_id]
v = []
d = []
issues.each do |issue|
v << issue.c.to_i
d << issue.name+"("+issue.c+")"
end
[v, d]
end
end
Charts.gen
end
end