diff --git a/judges/dimensions-of-terrain/dimensions-of-terrain.rb b/judges/dimensions-of-terrain/dimensions-of-terrain.rb index b2f8c909..bcd28540 100644 --- a/judges/dimensions-of-terrain/dimensions-of-terrain.rb +++ b/judges/dimensions-of-terrain/dimensions-of-terrain.rb @@ -22,9 +22,9 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. +require 'time' require 'fbe/fb' -require 'fbe/octo' -require 'fbe/overwrite' +require_relative '../../lib/incremate' f = Fbe.fb.query( "(and @@ -37,18 +37,4 @@ f.when = Time.now end -start = Time.now -Dir[File.join(__dir__, 'total_*.rb')].each do |rb| - n = File.basename(rb).gsub(/\.rb$/, '') - next unless f[n].nil? - if Fbe.octo.off_quota - $loog.info('No GitHub quota left, it is time to stop') - break - end - if Time.now - start > 5 * 60 - $loog.info('We are doing this for too long, time to stop') - break - end - require_relative rb - send(n, f).each { |k, v| f = Fbe.overwrite(f, k.to_s, v) } -end +Jp.incremate(f, __dir__, 'total') diff --git a/judges/quality-of-service/quality-of-service.rb b/judges/quality-of-service/quality-of-service.rb index d2712788..926c781d 100644 --- a/judges/quality-of-service/quality-of-service.rb +++ b/judges/quality-of-service/quality-of-service.rb @@ -22,24 +22,9 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. -require 'fbe/octo' -require 'fbe/overwrite' require 'fbe/regularly' +require_relative '../../lib/incremate' -start = Time.now Fbe.regularly('quality', 'qos_interval', 'qos_days') do |f| - Dir[File.join(__dir__, 'average_*.rb')].each do |rb| - n = File.basename(rb).gsub(/\.rb$/, '') - next unless f[n].nil? - if Fbe.octo.off_quota - $loog.info('No GitHub quota left, it is time to stop') - break - end - if Time.now - start > 5 * 60 - $loog.info('We are doing this for too long, time to stop') - break - end - require_relative rb - send(n, f).each { |k, v| f = Fbe.overwrite(f, k.to_s, v) } - end + Jp.incremate(f, __dir__, 'average') end diff --git a/judges/quantity-of-deliverables/quantity-of-deliverables.rb b/judges/quantity-of-deliverables/quantity-of-deliverables.rb index 780c6ef3..6ddbdc26 100644 --- a/judges/quantity-of-deliverables/quantity-of-deliverables.rb +++ b/judges/quantity-of-deliverables/quantity-of-deliverables.rb @@ -22,24 +22,9 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. -require 'fbe/overwrite' -require 'fbe/octo' require 'fbe/regularly' +require_relative '../../lib/incremate' -start = Time.now Fbe.regularly('scope', 'qod_interval', 'qod_days') do |f| - Dir[File.join(__dir__, 'total_*.rb')].each do |rb| - n = File.basename(rb).gsub(/\.rb$/, '') - next unless f[n].nil? - if Fbe.octo.off_quota - $loog.info('No GitHub quota left, it is time to stop') - break - end - if Time.now - start > 5 * 60 - $loog.info('We are doing this for too long, time to stop') - break - end - require_relative rb - send(n, f).each { |k, v| f = Fbe.overwrite(f, k.to_s, v) } - end + Jp.incremate(f, __dir__, 'total') end diff --git a/lib/incremate.rb b/lib/incremate.rb new file mode 100644 index 00000000..edf02189 --- /dev/null +++ b/lib/incremate.rb @@ -0,0 +1,47 @@ +# 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/overwrite' +require_relative 'jp' + +# Incrementaly accumulates data into a fact, using Ruby scripts +# found in the directory provided, by the prefix. +def Jp.incremate(fact, dir, prefix) + start = Time.now + Dir[File.join(dir, "#{prefix}_*.rb")].each do |rb| + n = File.basename(rb).gsub(/\.rb$/, '') + next unless fact[n].nil? + if Fbe.octo.off_quota + $loog.info('No GitHub quota left, it is time to stop') + break + end + if Time.now - start > 5 * 60 + $loog.info('We are doing this for too long, time to stop') + break + end + require_relative rb + send(n, fact).each { |k, v| fact = Fbe.overwrite(fact, k.to_s, v) } + end +end diff --git a/lib/jp.rb b/lib/jp.rb new file mode 100644 index 00000000..e738880c --- /dev/null +++ b/lib/jp.rb @@ -0,0 +1,26 @@ +# 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. + +# The module with supplementary features. +module Jp; end