From 20d325e3071e5d8609f50196ded676619012197c Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Thu, 26 Oct 2023 14:03:50 +0300 Subject: [PATCH] [#167] netmap: Fix reverse min agregator The higher the price, the lower reverse min weight should be. Previously nodes with 0 price had 0 weight which is a bit misleading. Introduced in d71a0e0755f8. Signed-off-by: Evgenii Stratonikov --- netmap/aggregator.go | 6 +----- netmap/json_tests/hrw_sort.json | 8 ++++---- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/netmap/aggregator.go b/netmap/aggregator.go index b2a9366..0f577a0 100644 --- a/netmap/aggregator.go +++ b/netmap/aggregator.go @@ -156,11 +156,7 @@ func (a *meanIQRAgg) Compute() float64 { } func (r *reverseMinNorm) Normalize(w float64) float64 { - if w == 0 { - return 0 - } - - return r.min / w + return (r.min + 1) / (w + 1) } func (r *sigmoidNorm) Normalize(w float64) float64 { diff --git a/netmap/json_tests/hrw_sort.json b/netmap/json_tests/hrw_sort.json index 8110ac7..49bdf2d 100644 --- a/netmap/json_tests/hrw_sort.json +++ b/netmap/json_tests/hrw_sort.json @@ -146,19 +146,19 @@ "select 3 nodes in 3 distinct countries, same placement": { "policy": {"replicas":[{"count":1,"selector":"Main"}],"containerBackupFactor":1,"selectors":[{"name":"Main","count":3,"clause":"DISTINCT","attribute":"Country","filter":"*"}],"filters":[]}, "pivot": "Y29udGFpbmVySUQ=", - "result": [[0, 2, 3]], + "result": [ [ 5, 0, 7 ] ], "placement": { "pivot": "b2JqZWN0SUQ=", - "result": [[0, 2, 3]] + "result": [ [ 5, 0, 7 ] ] } }, "select 6 nodes in 3 distinct countries, different placement": { "policy": {"replicas":[{"count":1,"selector":"Main"}],"containerBackupFactor":2,"selectors":[{"name":"Main","count":3,"clause":"DISTINCT","attribute":"Country","filter":"*"}],"filters":[]}, "pivot": "Y29udGFpbmVySUQ=", - "result": [[0, 1, 2, 6, 3, 4]], + "result": [ [ 5, 4, 0, 1, 7, 2 ] ], "placement": { "pivot": "b2JqZWN0SUQ=", - "result": [[0, 1, 2, 6, 3, 4]] + "result": [ [ 5, 4, 0, 7, 2, 1 ] ] } } }