Class: Lazylead::Score
- Inherits:
-
Object
- Object
- Lazylead::Score
- Defined in:
- lib/lazylead/task/accuracy/accuracy.rb
Overview
The ticket score based on fields content.
Instance Attribute Summary collapse
-
#accuracy ⇒ Object
readonly
Returns the value of attribute accuracy.
-
#issue ⇒ Object
readonly
Returns the value of attribute issue.
-
#score ⇒ Object
readonly
Returns the value of attribute score.
-
#total ⇒ Object
readonly
Returns the value of attribute total.
Instance Method Summary collapse
- #color ⇒ Object
- #colors ⇒ Object
-
#comment ⇒ Object
The jira comment in markdown format.
-
#docs_link ⇒ Object
Link to ticket formatting rules.
-
#evaluate(digits = 2) ⇒ Object
Estimate the ticket score and accuracy.
-
#grade(value) ⇒ Object
Calculate grade for accuracy For example, grade(7.5) => 0 grade(12) => 10 grade(25.5) => 20.
-
#initialize(issue, opts) ⇒ Score
constructor
A new instance of Score.
-
#post ⇒ Object
Post the comment with score and accuracy to the ticket.
Constructor Details
#initialize(issue, opts) ⇒ Score
Returns a new instance of Score.
63 64 65 66 |
# File 'lib/lazylead/task/accuracy/accuracy.rb', line 63 def initialize(issue, opts) @issue = issue @opts = opts end |
Instance Attribute Details
#accuracy ⇒ Object (readonly)
Returns the value of attribute accuracy.
61 62 63 |
# File 'lib/lazylead/task/accuracy/accuracy.rb', line 61 def accuracy @accuracy end |
#issue ⇒ Object (readonly)
Returns the value of attribute issue.
61 62 63 |
# File 'lib/lazylead/task/accuracy/accuracy.rb', line 61 def issue @issue end |
#score ⇒ Object (readonly)
Returns the value of attribute score.
61 62 63 |
# File 'lib/lazylead/task/accuracy/accuracy.rb', line 61 def score @score end |
#total ⇒ Object (readonly)
Returns the value of attribute total.
61 62 63 |
# File 'lib/lazylead/task/accuracy/accuracy.rb', line 61 def total @total end |
Instance Method Details
#color ⇒ Object
111 112 113 114 115 116 117 |
# File 'lib/lazylead/task/accuracy/accuracy.rb', line 111 def color return "#061306" if colors.nil? || !defined?(@score) || !@score.is_a?(Numeric) colors.reverse_each do |color| return color.last if @accuracy >= color.first end "#061306" end |
#colors ⇒ Object
119 120 121 122 123 124 125 126 127 |
# File 'lib/lazylead/task/accuracy/accuracy.rb', line 119 def colors @colors ||= begin JSON.parse(@opts["colors"]) .to_h .to_a .each { |e| e[0] = e[0].to_i } .sort_by { |e| e[0] } end end |
#comment ⇒ Object
The jira comment in markdown format
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/lazylead/task/accuracy/accuracy.rb', line 83 def comment comment = [ "Hi [~#{@issue.reporter.id}],", "", "The triage accuracy is '{color:#{color}}#{@score}{color}'" \ " (~{color:#{color}}#{@accuracy}%{color}), here are the reasons why:", "|| Ticket requirement || Status || Field ||" ] @rules.each do |r| comment << "|#{r.desc}|#{r.passed(@issue) ? '(/)' : '(-)'}|#{r.field}|" end comment << docs_link comment << "" comment << "Posted by [lazylead v#{Lazylead::VERSION}|" \ "https://bit.ly/2NjdndS]." comment.join("\r\n") end |
#docs_link ⇒ Object
Link to ticket formatting rules
102 103 104 105 106 107 108 109 |
# File 'lib/lazylead/task/accuracy/accuracy.rb', line 102 def docs_link if @opts["docs"].nil? || @opts["docs"].blank? "" else "The requirements/examples of ticket formatting rules you may find " \ "[here|#{@opts['docs']}]." end end |
#evaluate(digits = 2) ⇒ Object
Estimate the ticket score and accuracy. Accuracy is a percentage between current score and maximum possible value.
70 71 72 73 |
# File 'lib/lazylead/task/accuracy/accuracy.rb', line 70 def evaluate(digits = 2) @score = @opts[:rules].select { |r| r.passed(@issue) }.sum(&:score) @accuracy = (score / @opts[:total] * 100).round(digits) end |
#grade(value) ⇒ Object
Calculate grade for accuracy For example,
grade(7.5) => 0
grade(12) => 10
grade(25.5) => 20
134 135 136 |
# File 'lib/lazylead/task/accuracy/accuracy.rb', line 134 def grade(value) (value / 10).floor * 10 end |
#post ⇒ Object
Post the comment with score and accuracy to the ticket.
76 77 78 79 80 |
# File 'lib/lazylead/task/accuracy/accuracy.rb', line 76 def post return if @opts.key? "silent" @issue.post comment @issue.add_label "LL.accuracy", "#{grade(@accuracy)}%", "#{@accuracy}%" end |