Skip to content

Commit

Permalink
#412: average_backlog_size
Browse files Browse the repository at this point in the history
  • Loading branch information
yegor256 committed Dec 18, 2024
1 parent 66df7b7 commit b0db561
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 15 deletions.
48 changes: 48 additions & 0 deletions judges/quality-of-service/average_backlog_size.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# frozen_string_literal: true

# MIT License
#
# Copyright (c) 2024 Zerocracy
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

require 'fbe/octo'
require 'fbe/unmask_repos'

# Average issues
#
# This function is called from the "quality-of-service.rb".
#
# @param [Factbase::Fact] fact The fact just under processing
# @return [Hash] Map with keys as fact attributes and values as integers
def average_backlog_size(fact)
issues = []
Fbe.unmask_repos.each do |repo|
(fact.since.utc.to_date..Time.now.utc.to_date).each do |date|
count = 0
Fbe.octo.search_issues(
"repo:#{repo} type:issue created:#{fact.since.utc.to_date.iso8601[0..9]}..#{date.iso8601[0..9]}"
)[:items].each do |item|
count += 1 if item[:closed_at].nil? || item[:closed_at].utc.to_date >= date
end
issues << count
end
end
{ average_backlog_size: issues.empty? ? 0 : issues.inject(&:+).to_f / issues.size }
end
15 changes: 0 additions & 15 deletions judges/quality-of-service/quality-of-service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -119,19 +119,4 @@
ages.compact!
f.send("#{prop}=", ages.empty? ? 0 : ages.inject(&:+).to_f / ages.size)
end

# Average issues
issues = []
Fbe.unmask_repos.each do |repo|
(f.since.utc.to_date..Time.now.utc.to_date).each do |date|
count = 0
Fbe.octo.search_issues(
"repo:#{repo} type:issue created:#{f.since.utc.to_date.iso8601[0..9]}..#{date.iso8601[0..9]}"
)[:items].each do |item|
count += 1 if item[:closed_at].nil? || item[:closed_at].utc.to_date >= date
end
issues << count
end
end
f.average_backlog_size = issues.empty? ? 0 : issues.inject(&:+).to_f / issues.size
end

0 comments on commit b0db561

Please sign in to comment.