Class: HtmlReportConfig

Inherits:
Object show all
Includes:
DiscardChangesBefore, SelfOrIssueDispatcher
Defined in:
lib/jirametrics/html_report_config.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from DiscardChangesBefore

#discard_changes_before

Methods included from SelfOrIssueDispatcher

#method_missing, #respond_to_missing?

Constructor Details

#initialize(file_config:, block:) ⇒ HtmlReportConfig

Returns a new instance of HtmlReportConfig.



12
13
14
15
16
17
# File 'lib/jirametrics/html_report_config.rb', line 12

def initialize file_config:, block:
  @file_config = file_config
  @block = block
  # @cycletimes = []
  @sections = []
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class SelfOrIssueDispatcher

Instance Attribute Details

#file_configObject (readonly)

Returns the value of attribute file_config.



10
11
12
# File 'lib/jirametrics/html_report_config.rb', line 10

def file_config
  @file_config
end

#sectionsObject (readonly)

Returns the value of attribute sections.



10
11
12
# File 'lib/jirametrics/html_report_config.rb', line 10

def sections
  @sections
end

Instance Method Details

#aging_work_bar_chart(&block) ⇒ Object



67
68
69
# File 'lib/jirametrics/html_report_config.rb', line 67

def aging_work_bar_chart &block
  execute_chart AgingWorkBarChart.new(block)
end

#aging_work_in_progress_chart(board_id: nil, &block) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/jirametrics/html_report_config.rb', line 53

def aging_work_in_progress_chart board_id: nil, &block
  if board_id.nil?
    ids = issues.collect { |i| i.board.id }.uniq.sort
  else
    ids = [board_id]
  end

  ids.each do |id|
    execute_chart(AgingWorkInProgressChart.new(block)) do |chart|
      chart.board_id = id
    end
  end
end

#aging_work_table(priority_name = nil, &block) ⇒ Object



71
72
73
74
75
76
77
78
# File 'lib/jirametrics/html_report_config.rb', line 71

def aging_work_table priority_name = nil, &block
  if priority_name
    deprecated message: 'priority name should no longer be passed into the chart. Specify it in the ' \
      'board declaration. See https://github.com/mikebowler/jira-export/wiki/Deprecated',
      date: '2022-12-26'
  end
  execute_chart AgingWorkTable.new(block)
end

#blocked_stalled_chartObject



109
110
111
112
# File 'lib/jirametrics/html_report_config.rb', line 109

def blocked_stalled_chart
  puts 'Deprecated(blocked_stalled_chart). Use daily_wip_by_blocked_stalled_chart instead.'
  execute_chart DailyWipByBlockedStalledChart.new
end

#board_id(id = nil) ⇒ Object



44
45
46
47
# File 'lib/jirametrics/html_report_config.rb', line 44

def board_id id = nil
  @board_id = id unless id.nil?
  @board_id
end

#boardsObject



210
211
212
# File 'lib/jirametrics/html_report_config.rb', line 210

def boards
  @file_config.project_config.board_configs.collect(&:id).collect { |id| find_board id }
end

#cycletime(label = nil, &block) ⇒ Object



19
20
21
22
23
24
25
26
27
# File 'lib/jirametrics/html_report_config.rb', line 19

def cycletime label = nil, &block
  # TODO: This is about to become deprecated

  @file_config.project_config.all_boards.each do |_id, board|
    raise 'Multiple cycletimes not supported yet' if board.cycletime

    board.cycletime = CycleTimeConfig.new(parent_config: self, label: label, block: block)
  end
end

#cycletime_histogram(&block) ⇒ Object



123
124
125
# File 'lib/jirametrics/html_report_config.rb', line 123

def cycletime_histogram &block
  execute_chart CycletimeHistogram.new block
end

#cycletime_scatterplot(&block) ⇒ Object



80
81
82
# File 'lib/jirametrics/html_report_config.rb', line 80

def cycletime_scatterplot &block
  execute_chart CycletimeScatterplot.new block
end

#daily_wip_by_age_chart(&block) ⇒ Object



93
94
95
# File 'lib/jirametrics/html_report_config.rb', line 93

def daily_wip_by_age_chart &block
  execute_chart DailyWipByAgeChart.new block
end

#daily_wip_by_blocked_stalled_chartObject



101
102
103
# File 'lib/jirametrics/html_report_config.rb', line 101

def daily_wip_by_blocked_stalled_chart
  execute_chart DailyWipByBlockedStalledChart.new
end

#daily_wip_by_type(&block) ⇒ Object



97
98
99
# File 'lib/jirametrics/html_report_config.rb', line 97

def daily_wip_by_type &block
  execute_chart DailyWipChart.new block
end

#daily_wip_chart(&block) ⇒ Object



89
90
91
# File 'lib/jirametrics/html_report_config.rb', line 89

def daily_wip_chart &block
  execute_chart DailyWipChart.new(block)
end

#dependency_chart(&block) ⇒ Object



169
170
171
# File 'lib/jirametrics/html_report_config.rb', line 169

def dependency_chart &block
  execute_chart DependencyChart.new block
end

#discard_changes_before_hook(issues_cutoff_times) ⇒ Object



151
152
153
154
155
156
157
158
159
160
161
162
# File 'lib/jirametrics/html_report_config.rb', line 151

def discard_changes_before_hook issues_cutoff_times
  # raise 'Cycletime must be defined before using discard_changes_before' unless @cycletime

  @original_issue_times = {}
  issues_cutoff_times.each do |issue, cutoff_time|
    started = issue.board.cycletime.started_time(issue)
    if started && started <= cutoff_time
      # We only need to log this if data was discarded
      @original_issue_times[issue] = { cutoff_time: cutoff_time, started_time: started }
    end
  end
end

#discarded_changes_reportObject



164
165
166
167
# File 'lib/jirametrics/html_report_config.rb', line 164

def discarded_changes_report
  puts 'Deprecated(discarded_changes_report) No need to specify this anymore as this information is ' \
   'now included in the data quality checks.'
end

#execute_chart(chart, &after_init_block) ⇒ Object



173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
# File 'lib/jirametrics/html_report_config.rb', line 173

def execute_chart chart, &after_init_block
  project_config = @file_config.project_config

  chart.issues = issues
  chart.time_range = project_config.time_range
  chart.timezone_offset = timezone_offset
  chart.settings = project_config.settings

  chart.all_boards = project_config.all_boards
  chart.board_id = find_board_id if chart.respond_to? :board_id=
  chart.holiday_dates = project_config.exporter.holiday_dates

  time_range = @file_config.project_config.time_range
  chart.date_range = time_range.begin.to_date..time_range.end.to_date
  chart.aggregated_project = project_config.aggregated_project?

  after_init_block&.call chart

  html chart.run
end

#expedited_chart(priority_name = nil) ⇒ Object



114
115
116
117
118
119
120
121
# File 'lib/jirametrics/html_report_config.rb', line 114

def expedited_chart priority_name = nil
  if priority_name
    deprecated message: 'priority name should no longer be passed into the chart. Specify it in the ' \
      'board declaration. See https://github.com/mikebowler/jira-export/wiki/Deprecated',
      date: '2022-12-26'
  end
  execute_chart ExpeditedChart.new
end

#find_board(id) ⇒ Object



202
203
204
# File 'lib/jirametrics/html_report_config.rb', line 202

def find_board id
  @file_config.project_config.all_boards[id]
end

#find_board_idObject



194
195
196
# File 'lib/jirametrics/html_report_config.rb', line 194

def find_board_id
  @board_id || @file_config.project_config.guess_board_id
end

#find_project_by_name(name) ⇒ Object



214
215
216
# File 'lib/jirametrics/html_report_config.rb', line 214

def find_project_by_name name
  @file_config.project_config.exporter.project_configs.find { |p| p.name == name }
end

#hierarchy_table(&block) ⇒ Object



147
148
149
# File 'lib/jirametrics/html_report_config.rb', line 147

def hierarchy_table &block
  execute_chart HierarchyTable.new block
end

#html(string, type: :body) ⇒ Object



131
132
133
134
135
# File 'lib/jirametrics/html_report_config.rb', line 131

def html string, type: :body
  raise "Unexpected type: #{type}" unless [:body, :header].include? type

  @sections << [string, type]
end

#issuesObject



198
199
200
# File 'lib/jirametrics/html_report_config.rb', line 198

def issues
  @file_config.issues
end

#project_nameObject



206
207
208
# File 'lib/jirametrics/html_report_config.rb', line 206

def project_name
  @file_config.project_config.name
end

#random_colorObject



127
128
129
# File 'lib/jirametrics/html_report_config.rb', line 127

def random_color
  "\##{Random.bytes(3).unpack1('H*')}"
end

#runObject



29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/jirametrics/html_report_config.rb', line 29

def run
  instance_eval(&@block)

  # The quality report has to be generated last because otherwise cycletime won't have been
  # set. Then we have to rotate it to the first position so it's at the top of the report.
  execute_chart DataQualityReport.new(@original_issue_times || {})
  @sections.rotate!(-1)

  File.open @file_config.output_filename, 'w' do |file|
    html_directory = "#{Pathname.new(File.realpath(__FILE__)).dirname}/html"
    erb = ERB.new File.read("#{html_directory}/index.erb")
    file.puts erb.result(binding)
  end
end

#sprint_burndown(options = :points_and_counts) ⇒ Object



137
138
139
140
141
# File 'lib/jirametrics/html_report_config.rb', line 137

def sprint_burndown options = :points_and_counts
  execute_chart SprintBurndown.new do |chart|
    chart.options = options
  end
end

#story_point_accuracy_chart(&block) ⇒ Object



143
144
145
# File 'lib/jirametrics/html_report_config.rb', line 143

def story_point_accuracy_chart &block
  execute_chart StoryPointAccuracyChart.new block
end

#throughput_chart(&block) ⇒ Object



105
106
107
# File 'lib/jirametrics/html_report_config.rb', line 105

def throughput_chart &block
  execute_chart ThroughputChart.new(block)
end

#timezone_offsetObject



49
50
51
# File 'lib/jirametrics/html_report_config.rb', line 49

def timezone_offset
  @file_config.project_config.exporter.timezone_offset
end

#total_wip_over_time_chart(&block) ⇒ Object



84
85
86
87
# File 'lib/jirametrics/html_report_config.rb', line 84

def total_wip_over_time_chart &block
  puts 'Deprecated(total_wip_over_time_chart). Use daily_wip_by_age_chart instead.'
  execute_chart DailyWipByAgeChart.new block
end