/
version_synthesis.rb
84 lines (76 loc) · 2.81 KB
/
version_synthesis.rb
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
# My Roadmaps - Redmine plugin to expose global roadmaps
# Copyright (C) 2012 Stéphane Rondinaud
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
class VersionSynthesis
def initialize(project, version, issues)
@version = version
@project = project
@issues = Array.new
@trackers = Array.new
@max_depth=0
self.add_issues(issues)
end
def add_issues(issues)
issues.each{ |issue|
if @trackers.select{|wrapper| wrapper.wrapped_tracker == issue.tracker }.length!=1
current_tracker = TrackerWrapper.new(version,issue.tracker)
@trackers.push(current_tracker)
else
current_tracker = @trackers.select{|wrapper| wrapper.wrapped_tracker == issue.tracker }[0]
end
current_tracker.addIssue(issue)
depth=issues.select{|iss| (iss.lft<issue.lft) && (iss.rgt>issue.rgt) && (iss.id!=issue.id) && (iss.root_id==issue.root_id) }.length
@issues.push(IssueWrapper.new(issue,depth))
if @max_depth<depth
@max_depth = depth
end
}
@trackers.sort{|a,b| a.wrapped_tracker.position<=>b.wrapped_tracker.position}
@done_pct = 0
@done_nb = 0
@total_nb = 0
@closed_nb = 0
@opened_nb = 0
@closed_pct = 0
@opened_pct = 0
@trackers.each{|wrapper|
@total_nb += wrapper.total_nb
@closed_nb += wrapper.closed_nb
@opened_nb += wrapper.opened_nb
@done_nb += wrapper.done_nb
@done_pct += wrapper.done_pct
}
if @done_nb > 0
@done_pct /= @done_nb
end
if @total_nb > 0
@closed_pct = @closed_nb*100/@total_nb
@opened_pct = @opened_nb*100/@total_nb
end
# issues progress % set
if !@issues.nil? && @issues.length > 0
@pct_done = @issues.map{|issue_wrapper| (issue_wrapper.wrapped_issue.closed?)?100:issue_wrapper.wrapped_issue.done_ratio}
@pct_done.push(0,100)
@pct_done.uniq!
@pct_done.sort!
# when all issues are either not started or closed
@pct_done = [0,90,100] if pct_done.length==2
else
@pct_done = nil
end
end
attr_reader :version, :project, :max_depth, :issues, :trackers, :pct_done, :done_nb, :done_pct, :closed_nb, :closed_pct, :opened_nb, :opened_pct
end