From ba8bdab81bab7d321a7a667430033dbf33dae1f2 Mon Sep 17 00:00:00 2001 From: Yegor Bugayenko Date: Thu, 22 Aug 2024 19:52:32 +0300 Subject: [PATCH] #81 paranoia --- assets/bylaws/bad-branch-name-was-punished.liquid | 2 +- assets/bylaws/code-contribution-was-rewarded.liquid | 8 ++++---- assets/bylaws/code-review-was-rewarded.liquid | 4 ++-- assets/bylaws/push-to-master-was-punished.liquid | 2 +- assets/bylaws/resolved-bug-was-rewarded.liquid | 2 +- lib/fbe/bylaws.rb | 4 ++-- test/fbe/test_bylaws.rb | 4 ++-- 7 files changed, 13 insertions(+), 13 deletions(-) diff --git a/assets/bylaws/bad-branch-name-was-punished.liquid b/assets/bylaws/bad-branch-name-was-punished.liquid index 9b35f08..198ac83 100644 --- a/assets/bylaws/bad-branch-name-was-punished.liquid +++ b/assets/bylaws/bad-branch-name-was-punished.liquid @@ -1,7 +1,7 @@ (award (explain "If a branch has a name that doesn\\\'t obey the convention, a penalty is given to the author") (aka - (let fee -12) + (let fee {{ -6 | times: anger }}) (give fee "as a basis") "deduct ${fee} points") ) diff --git a/assets/bylaws/code-contribution-was-rewarded.liquid b/assets/bylaws/code-contribution-was-rewarded.liquid index f248714..1dab429 100644 --- a/assets/bylaws/code-contribution-was-rewarded.liquid +++ b/assets/bylaws/code-contribution-was-rewarded.liquid @@ -11,7 +11,7 @@ (aka (let hoc_k {{ 0.05 | times: love }}) - (let hoc_threshold 200) + (let hoc_threshold {{ 400 | divided_by: paranoia }}) (let hoc_max 16) (let hoc_min 5) (set bonus_for_hoc (if (lt hoc hoc_threshold) (times hoc hoc_k) 0)) @@ -30,7 +30,7 @@ (aka (let many_hoc_fee2 {{ 8 | times: anger }}) - (let hoc_threshold2 800) + (let hoc_threshold2 {{ 1600 | divided_by: paranoia }}) (set penalty_for_hoc2 (if (gte hoc hoc_threshold2) (times -1 many_hoc_fee2) 0)) (give penalty_for_hoc2 "for way too many hits-of-code (${hoc} >= ${hoc_threshold2})") "deduct ${many_hoc_fee2} points if more than ${hoc_threshold2} @@ -53,7 +53,7 @@ (aka (let few_comments_fee {{ 2 | times: anger }}) - (let comments_needed 5) + (let comments_needed {{ 3 | times: paranoia }}) (set penalty_for_few_comments (if (and (lt comments comments_needed) (not (eq comments 0))) (times -1 few_comments_fee) 0)) (give penalty_for_few_comments "for very few (${comments}) comments") "deduct ${few_comments_fee} points if there were less than ${comments_needed} comments made during review") @@ -66,7 +66,7 @@ (aka (let few_hoc_fee {{ 4 | times: anger }}) - (let hoc_needed 20) + (let hoc_needed {{ 10 | times: paranoia }}) (set penalty_for_few_hoc (if (lt hoc hoc_needed) (times -1 few_hoc_fee) 0)) (give penalty_for_few_hoc "for too few (${hoc}) hits-of-code") "deduct ${few_hoc_fee} points if you contribute less than ${hoc_needed} hits-of-code") diff --git a/assets/bylaws/code-review-was-rewarded.liquid b/assets/bylaws/code-review-was-rewarded.liquid index 910fb21..07afea9 100644 --- a/assets/bylaws/code-review-was-rewarded.liquid +++ b/assets/bylaws/code-review-was-rewarded.liquid @@ -29,7 +29,7 @@ (aka (let few_comments_fee {{ 5 | times: anger }}) - (let comments_needed 6) + (let comments_needed {{ 3 | times: paranoia }}) (set penalty_for_few_comments (if (and (lt comments comments_needed) (not (eq comments 0))) (times -1 few_comments_fee) 0)) (give penalty_for_few_comments "for very few (${comments}) comments") "deduct ${few_comments_fee} points if there were less than ${comments_needed} comments made during review") @@ -52,7 +52,7 @@ (aka (let hoc_fee {{ 4 | times: anger }}) - (let hoc_needed 15) + (let hoc_needed {{ 8 | times: paranoia }}) (set penalty_for_hoc (if (lt hoc hoc_needed) (times -1 hoc_fee) 0)) (give penalty_for_hoc "for too few (${hoc}) hits-of-code") "deduct ${hoc_fee} points if there were less than ${hoc_needed} hits-of-code") diff --git a/assets/bylaws/push-to-master-was-punished.liquid b/assets/bylaws/push-to-master-was-punished.liquid index b8ecb8c..b8eef5a 100644 --- a/assets/bylaws/push-to-master-was-punished.liquid +++ b/assets/bylaws/push-to-master-was-punished.liquid @@ -1,7 +1,7 @@ (award (explain "When someone pushes directly to the default branch, they get a penalty") (aka - (let fee -16) + (let fee {{ -8 | times: anger }}) (give fee "as a basis") "${fee} points") ) diff --git a/assets/bylaws/resolved-bug-was-rewarded.liquid b/assets/bylaws/resolved-bug-was-rewarded.liquid index 2e3ebe4..4547674 100644 --- a/assets/bylaws/resolved-bug-was-rewarded.liquid +++ b/assets/bylaws/resolved-bug-was-rewarded.liquid @@ -10,7 +10,7 @@ (aka (let b1 {{ 4 | times: love }}) - (let hours_threshold 24) + (let hours_threshold {{ 48 | divided_by: paranoia }}) (set b1 (if (lt hours hours_threshold) b1 0)) (give b1 "for resolving it in less than ${hours_threshold} hours") "add ${b1} points if it was resolved in less than ${hours_threshold} hours") diff --git a/lib/fbe/bylaws.rb b/lib/fbe/bylaws.rb index ded292f..7ade19a 100644 --- a/lib/fbe/bylaws.rb +++ b/lib/fbe/bylaws.rb @@ -30,12 +30,12 @@ # Author:: Yegor Bugayenko (yegor256@gmail.com) # Copyright:: Copyright (c) 2024 Yegor Bugayenko # License:: MIT -def Fbe.bylaws(anger: 2, love: 2) +def Fbe.bylaws(anger: 2, love: 2, paranoia: 2) home = File.join(__dir__, '../../assets/bylaws') raise "The directory with templates is absent '#{home}'" unless File.exist?(home) Dir[File.join(home, '*.liquid')].to_h do |f| formula = Liquid::Template.parse(File.read(f)).render( - 'anger' => anger, 'love' => love + 'anger' => anger, 'love' => love, 'paranoia' => paranoia ) [File.basename(f).gsub(/\.liquid$/, ''), formula] end diff --git a/test/fbe/test_bylaws.rb b/test/fbe/test_bylaws.rb index 5fbdd77..3c63a57 100644 --- a/test/fbe/test_bylaws.rb +++ b/test/fbe/test_bylaws.rb @@ -80,7 +80,7 @@ def test_check_all_bills { hoc: 50, comments: 15, reviews: 0 } => 5, { hoc: 50, comments: 25, reviews: 0 } => 4, { hoc: 180, comments: 7, reviews: 2 } => 32, - { hoc: 150, comments: 5, reviews: 1 } => 31, + { hoc: 150, comments: 5, reviews: 1 } => 27, { hoc: 500, comments: 25, reviews: 2 } => 4, { hoc: 99, comments: 6, reviews: 1 } => 26, { hoc: 1_500, comments: 3, reviews: 0 } => 4, @@ -104,7 +104,7 @@ def test_check_all_bills assert(!formula.nil?, title) a = Fbe::Award.new(formula) help = [ - " #{title}: {\n ", + " '#{title.gsub('-', '_')}' => {\n ", pairs.map do |args, _| [ '{',