Class: Lazylead::Labels
- Inherits:
-
Object
- Object
- Lazylead::Labels
- Defined in:
- lib/lazylead/task/accuracy/onlyll.rb
Overview
The ticket with grid labels
Instance Attribute Summary collapse
-
#issue ⇒ Object
readonly
Returns the value of attribute issue.
Instance Method Summary collapse
-
#diff(record) ⇒ Object
Detect label diff in single history record from ticket’s history.
-
#exists? ⇒ Boolean
Ensure that issue has evaluation labels for accuracy rules.
-
#grid ⇒ Object
Detect the percentage grid for tickets, by default its 0%, 10%, 20%, etc.
-
#grid?(record) ⇒ Boolean
Ensure that history record has label change related to LL grid labels.
-
#hacked(record) ⇒ Object
Hacked score by violator in ticket’s history.
-
#initialize(issue, opts) ⇒ Labels
constructor
A new instance of Labels.
-
#remove ⇒ Object
Remove score labels from the ticket.
-
#score ⇒ Object
Find expected ticket score evaluated by LL.
-
#to_l(history) ⇒ Object
Find history record with labels changes.
-
#valid? ⇒ Boolean
Compare the score evaluated by LL and current ticket score.
-
#violators ⇒ Object
Detect the violators with their changes.
Constructor Details
#initialize(issue, opts) ⇒ Labels
Returns a new instance of Labels.
59 60 61 62 |
# File 'lib/lazylead/task/accuracy/onlyll.rb', line 59 def initialize(issue, opts) @issue = issue @opts = opts end |
Instance Attribute Details
#issue ⇒ Object (readonly)
Returns the value of attribute issue.
57 58 59 |
# File 'lib/lazylead/task/accuracy/onlyll.rb', line 57 def issue @issue end |
Instance Method Details
#diff(record) ⇒ Object
Detect label diff in single history record from ticket’s history.
130 131 132 133 134 135 136 137 138 |
# File 'lib/lazylead/task/accuracy/onlyll.rb', line 130 def diff(record) record["items"].select { |f| f["field"].eql? "labels" } .reject { |f| f["toString"].nil? || f["toString"].blank? } .map do |f| from = [] from = f["fromString"].split unless f["fromString"].nil? f["toString"].split - from end end |
#exists? ⇒ Boolean
Ensure that issue has evaluation labels for accuracy rules
65 66 67 68 69 |
# File 'lib/lazylead/task/accuracy/onlyll.rb', line 65 def exists? return false if @issue.labels.nil? || @issue.labels.empty? return false unless @issue.labels.is_a? Array grid.any? { |g| @issue.labels.any? { |l| g.eql? l } } end |
#grid ⇒ Object
Detect the percentage grid for tickets, by default its 0%, 10%, 20%, etc.
96 97 98 99 100 101 102 103 104 |
# File 'lib/lazylead/task/accuracy/onlyll.rb', line 96 def grid @grid ||= begin if @opts.key? "grid" @opts.slice("grid", ",") else %w[0% 10% 20% 30% 40% 50% 60% 70% 80% 90% 100%] end end end |
#grid?(record) ⇒ Boolean
Ensure that history record has label change related to LL grid labels.
125 126 127 |
# File 'lib/lazylead/task/accuracy/onlyll.rb', line 125 def grid?(record) diff(record).any? { |d| d.find { |l| grid.any? { |g| l.eql? g } } } end |
#hacked(record) ⇒ Object
Hacked score by violator in ticket’s history.
141 142 143 144 145 |
# File 'lib/lazylead/task/accuracy/onlyll.rb', line 141 def hacked(record) diff(record.first) .first .find { |l| grid.any? { |g| l.eql? g } } end |
#remove ⇒ Object
Remove score labels from the ticket.
107 108 109 |
# File 'lib/lazylead/task/accuracy/onlyll.rb', line 107 def remove @issue.labels!(@issue.labels - grid) end |
#score ⇒ Object
Find expected ticket score evaluated by LL. If LL evaluated the same ticket several times (no matter why),
then the last score would be returned.
80 81 82 83 84 85 86 87 |
# File 'lib/lazylead/task/accuracy/onlyll.rb', line 80 def score to_l( @issue.history .select { |h| h["author"]["key"].eql? @opts["author"] } .reverse .find { |h| to_l(h) } ).fetch("toString", "").split.find { |l| grid.any? { |g| l.eql? g } } end |
#to_l(history) ⇒ Object
Find history record with labels changes.
90 91 92 93 |
# File 'lib/lazylead/task/accuracy/onlyll.rb', line 90 def to_l(history) return {} if history.nil? || history.empty? history["items"].find { |f| f["field"].eql? "labels" } end |
#valid? ⇒ Boolean
Compare the score evaluated by LL and current ticket score.
73 74 75 |
# File 'lib/lazylead/task/accuracy/onlyll.rb', line 73 def valid? score.eql?(@issue.labels.sort.find { |l| grid.any? { |g| l.eql? g } }) end |
#violators ⇒ Object
Detect the violators with their changes.
.violators => ["Tom Hhhh set 40%", "Bob Mmmm set 50%"]
113 114 115 116 117 118 119 120 121 |
# File 'lib/lazylead/task/accuracy/onlyll.rb', line 113 def violators @issue.history .reject { |h| h["author"]["key"].eql? @opts["author"] } .select { |h| grid?(h) } .group_by { |h| h["author"]["key"] } .map do |a| "#{a.last.first['author']['displayName']} set #{hacked(a.last)}" end end |