Class: ReportsController
Instance Attribute Summary collapse
Instance Method Summary
collapse
#after_sign_in_path_for, #api_authenticate!, #current_project, #expire_revision!, #followed_projects, #no_cache, #read_revision, #require_login, #return_or_cache_revision!, #revision, #save_current_project, #set_current_project, #unfurling?
Methods included from UrlHelper
#edit_release_path, #edit_release_url, #feature_path, #github_commit_range_url, #github_commit_url, #github_project_url, #github_url?, #goldmine_case_number_url, #link_to_project_feature, #new_release_url, #release_path, #release_url, #releases_path
Instance Attribute Details
#end_date ⇒ Object
Returns the value of attribute end_date.
6
7
8
|
# File 'app/controllers/reports_controller.rb', line 6
def end_date
@end_date
end
|
#start_date ⇒ Object
Returns the value of attribute start_date.
6
7
8
|
# File 'app/controllers/reports_controller.rb', line 6
def start_date
@start_date
end
|
#tickets ⇒ Object
Returns the value of attribute tickets.
6
7
8
|
# File 'app/controllers/reports_controller.rb', line 6
def tickets
@tickets
end
|
Instance Method Details
#cycle_time ⇒ Object
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
# File 'app/controllers/reports_controller.rb', line 43
def cycle_time
results = benchmark("pluck") do
tickets.joins(<<-SQL)
LEFT OUTER JOIN generate_series('#{start_date}'::timestamp, '#{end_date}'::timestamp, '1 month') AS months(month)
ON tickets.created_at <= months.month
AND (tickets.closed_at IS NULL OR tickets.closed_at > months.month)
SQL
.where("months.month IS NOT NULL")
.group("months.month")
.reorder("months.month ASC")
.pluck("months.month::date", "AVG(extract('epoch' from month - tickets.created_at)) / 86400")
end
benchmark("present") do
render json: results
end
end
|
#index ⇒ Object
8
9
10
|
# File 'app/controllers/reports_controller.rb', line 8
def index
@title = "Reports"
end
|
#queue_age ⇒ Object
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
|
# File 'app/controllers/reports_controller.rb', line 12
def queue_age
results = benchmark("pluck") do
tickets.joins(<<-SQL)
LEFT OUTER JOIN generate_series('#{start_date}'::timestamp, '#{end_date}'::timestamp, '1 month') AS months(month)
ON tickets.created_at <= months.month
AND (tickets.closed_at IS NULL OR tickets.closed_at > months.month)
SQL
.where("months.month IS NOT NULL")
.reorder("months.month ASC")
.pluck("months.month::date", "extract('epoch' from month - tickets.created_at)")
end
results = benchmark("process") do
results \
.each_with_object(Hash.new { |h, k| h[k] = [] }) { |(date, age), map| map[date].push(age) }
.map { |date, ages| [date] + to_age_bins(ages) }
end
line = benchmark("line") do
tickets.closed
.group("date_trunc('month', closed_at)::date")
.reorder("date_trunc('month', closed_at)::date")
.pluck("date_trunc('month', closed_at)::date", "COUNT(id)")
.map { |(month, count)| {date: month, y: count} }
end
benchmark("present") do
render json: {data: results, line: line}
end
end
|
#sprint ⇒ Object
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
|
# File 'app/controllers/reports_controller.rb', line 158
def sprint
@title = "Sprint Reports"
@start_date = Date.parse(params.fetch(:since, "2014-05-18")) @start_date = Date.parse(params.fetch(:since, "2014-08-07"))
@end_date = Date.today
@users = []
([nil] + User.developers).each do |user|
data = SprintReport.new(user, start_date, end_date).to_a
next if data.all? { |(_, completed, missed)| (completed + missed).zero? }
average = data
.select { |_, completed, missed| (completed + missed) > 0 }
.avg { |(_, completed, _)| completed }
@users.push [(user ? user.name : "Team"), average, data] end
@users.sort_by! { |(_, average, _)| -average }
end
|
#tasks_excel ⇒ Object
179
180
181
182
183
184
185
186
|
# File 'app/controllers/reports_controller.rb', line 179
def tasks_excel
authorize! :read, "Report"
tasks = Task.completed
send_data TasksExcelPresenter.new(tasks),
type: :xlsx,
filename: "Tasks.xlsx",
disposition: "attachment"
end
|
#time_to_first_test ⇒ Object
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
|
# File 'app/controllers/reports_controller.rb', line 108
def time_to_first_test
results = benchmark("pluck") do
Ticket.connection.select_rows(<<-SQL)
SELECT
months.month::date,
AVG(extract('epoch' from q.testing_started_at - q.to_staging_at)) / 3600
FROM generate_series('#{start_date}'::timestamp, '#{end_date}'::timestamp, '1 month') AS months(month)
LEFT OUTER JOIN (
SELECT
to_staging.created_at "to_staging_at",
first_test.created_at "testing_started_at"
FROM tickets
INNER JOIN (
SELECT rt1.ticket_id, MIN(r1.created_at) "created_at"
FROM releases r1
INNER JOIN releases_tickets rt1 ON rt1.release_id=r1.id
WHERE r1.environment_name = 'Staging'
GROUP BY rt1.ticket_id
) AS to_staging ON to_staging.ticket_id=tickets.id
INNER JOIN (
SELECT tn.ticket_id, MIN(tn.created_at) "created_at"
FROM testing_notes tn
GROUP BY tn.ticket_id
) AS first_test ON first_test.ticket_id=tickets.id
) AS q
ON q.to_staging_at >= months.month
AND q.to_staging_at < (months.month + interval '1 month')
WHERE q.testing_started_at > q.to_staging_at
GROUP BY months.month
ORDER BY months.month ASC
SQL
.map { |(date, v1, v2, v3)| [date.to_date, v1.to_i, v2.to_i, v3.to_i] }
end
benchmark("present") do
render json: results
end
end
|
#time_to_release ⇒ Object
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
|
# File 'app/controllers/reports_controller.rb', line 61
def time_to_release
results = benchmark("pluck") do
Ticket.connection.select_rows(<<-SQL)
SELECT
months.month::date,
AVG(extract('epoch' from q.closed_at - q.to_staging_at)) / 86400,
AVG(extract('epoch' from q.released_at - q.closed_at)) / 86400
FROM generate_series('#{start_date}'::timestamp, '#{end_date}'::timestamp, '1 month') AS months(month)
LEFT OUTER JOIN (
SELECT
to_staging.created_at "to_staging_at",
tickets.closed_at,
to_production.created_at "released_at"
FROM tickets
INNER JOIN (
SELECT rt1.ticket_id, MIN(r1.created_at) "created_at"
FROM releases r1
INNER JOIN releases_tickets rt1 ON rt1.release_id=r1.id
WHERE r1.environment_name = 'Staging'
GROUP BY rt1.ticket_id
) AS to_staging ON to_staging.ticket_id=tickets.id
INNER JOIN (
SELECT rt2.ticket_id, MIN(r2.created_at) "created_at"
FROM releases r2
INNER JOIN releases_tickets rt2 ON rt2.release_id=r2.id
WHERE r2.environment_name = 'Production'
GROUP BY rt2.ticket_id
) AS to_production ON to_production.ticket_id=tickets.id
) AS q
ON q.released_at >= months.month
AND q.released_at < (months.month + interval '1 month')
WHERE q.closed_at > q.to_staging_at
AND q.released_at > q.closed_at
GROUP BY months.month
ORDER BY months.month ASC
SQL
.map { |(date, v1, v2, v3)| [date.to_date, v1.to_i, v2.to_i, v3.to_i] }
end
benchmark("present") do
render json: results
end
end
|
#velocity ⇒ Object
152
153
154
155
156
|
# File 'app/controllers/reports_controller.rb', line 152
def velocity
@title = "Reports"
@tickets = ::Ticket.includes(:project, :tasks).estimated.closed
.select { |ticket| ticket.commit_time > 0 } end
|