mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-14 20:59:53 +05:00
higher weights are better
This commit is contained in:
@@ -502,7 +502,8 @@ func (apl Actions) Swap(i, j int) {
|
||||
apl[i], apl[j] = apl[j], apl[i]
|
||||
}
|
||||
|
||||
func (apl Actions) Less(i, j int) bool {
|
||||
// we need higher weights earlyer in the list
|
||||
func (apl Actions) Less(j, i int) bool {
|
||||
return apl[i].Weight < apl[j].Weight
|
||||
}
|
||||
|
||||
|
||||
@@ -297,7 +297,8 @@ func (atpl ActionTimingPriotityList) Swap(i, j int) {
|
||||
|
||||
func (atpl ActionTimingPriotityList) Less(i, j int) bool {
|
||||
if atpl[i].GetNextStartTime(time.Now()).Equal(atpl[j].GetNextStartTime(time.Now())) {
|
||||
return atpl[i].Weight < atpl[j].Weight
|
||||
// higher weights earlyer in the list
|
||||
return atpl[i].Weight > atpl[j].Weight
|
||||
}
|
||||
return atpl[i].GetNextStartTime(time.Now()).Before(atpl[j].GetNextStartTime(time.Now()))
|
||||
}
|
||||
|
||||
@@ -151,7 +151,8 @@ func (atpl ActionTriggerPriotityList) Swap(i, j int) {
|
||||
atpl[i], atpl[j] = atpl[j], atpl[i]
|
||||
}
|
||||
|
||||
func (atpl ActionTriggerPriotityList) Less(i, j int) bool {
|
||||
//we need higher weights earlyer in the list
|
||||
func (atpl ActionTriggerPriotityList) Less(j, i int) bool {
|
||||
return atpl[i].Weight < atpl[j].Weight
|
||||
}
|
||||
|
||||
|
||||
@@ -19,12 +19,13 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
package engine
|
||||
|
||||
import (
|
||||
"github.com/cgrates/cgrates/config"
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
"net/rpc"
|
||||
"net/rpc/jsonrpc"
|
||||
"path"
|
||||
"testing"
|
||||
|
||||
"github.com/cgrates/cgrates/config"
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
)
|
||||
|
||||
var actsLclCfg *config.CGRConfig
|
||||
|
||||
@@ -463,7 +463,7 @@ func TestActionTimingPriotityListWeight(t *testing.T) {
|
||||
StartTime: "00:00:00",
|
||||
},
|
||||
},
|
||||
Weight: 10.0,
|
||||
Weight: 20,
|
||||
}
|
||||
at2 := &ActionTiming{
|
||||
Timing: &RateInterval{
|
||||
@@ -473,7 +473,7 @@ func TestActionTimingPriotityListWeight(t *testing.T) {
|
||||
StartTime: "00:00:00",
|
||||
},
|
||||
},
|
||||
Weight: 20.0,
|
||||
Weight: 10,
|
||||
}
|
||||
var atpl ActionTimingPriotityList
|
||||
atpl = append(atpl, at2, at1)
|
||||
@@ -634,9 +634,9 @@ func TestActionTriggerMatchAll(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestActionTriggerPriotityList(t *testing.T) {
|
||||
at1 := &ActionTrigger{Weight: 10}
|
||||
at1 := &ActionTrigger{Weight: 30}
|
||||
at2 := &ActionTrigger{Weight: 20}
|
||||
at3 := &ActionTrigger{Weight: 30}
|
||||
at3 := &ActionTrigger{Weight: 10}
|
||||
var atpl ActionTriggerPriotityList
|
||||
atpl = append(atpl, at2, at1, at3)
|
||||
atpl.Sort()
|
||||
|
||||
@@ -521,6 +521,7 @@ func (bc BalanceChain) Swap(i, j int) {
|
||||
bc[i], bc[j] = bc[j], bc[i]
|
||||
}
|
||||
|
||||
// we need the better ones at the beginning
|
||||
func (bc BalanceChain) Less(j, i int) bool {
|
||||
return bc[i].precision < bc[j].precision ||
|
||||
(bc[i].precision == bc[j].precision && bc[i].Weight < bc[j].Weight)
|
||||
|
||||
@@ -42,10 +42,12 @@ func populateDB() {
|
||||
&Action{ActionType: "*topup", BalanceType: utils.MONETARY, Direction: OUTBOUND, Balance: &Balance{Value: 10}},
|
||||
&Action{ActionType: "*topup", BalanceType: utils.VOICE, Direction: OUTBOUND, Balance: &Balance{Weight: 20, Value: 10, DestinationIds: "NAT"}},
|
||||
}
|
||||
|
||||
ats1 := []*Action{
|
||||
&Action{ActionType: "*topup", BalanceType: utils.MONETARY, Direction: OUTBOUND, Balance: &Balance{Value: 10}, Weight: 20},
|
||||
&Action{ActionType: "*reset_account", Weight: 10},
|
||||
&Action{ActionType: "*topup", BalanceType: utils.MONETARY, Direction: OUTBOUND, Balance: &Balance{Value: 10}, Weight: 10},
|
||||
&Action{ActionType: "*reset_account", Weight: 20},
|
||||
}
|
||||
|
||||
minu := &Account{
|
||||
Id: "*out:vdf:minu",
|
||||
BalanceMap: map[string]BalanceChain{
|
||||
@@ -235,7 +237,7 @@ func TestCalldescHolliday(t *testing.T) {
|
||||
},
|
||||
&RateInterval{
|
||||
Timing: &RITiming{Months: utils.Months{time.May}, MonthDays: utils.MonthDays{1}, StartTime: "00:00:00"},
|
||||
Weight: 5,
|
||||
Weight: 20,
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
@@ -158,6 +158,7 @@ func (es LCREntriesSorter) Swap(i, j int) {
|
||||
es[i], es[j] = es[j], es[i]
|
||||
}
|
||||
|
||||
// we need the best earlyer in the list
|
||||
func (es LCREntriesSorter) Less(j, i int) bool {
|
||||
return es[i].Weight < es[j].Weight ||
|
||||
(es[i].Weight == es[j].Weight && es[i].precision < es[j].precision)
|
||||
|
||||
@@ -364,7 +364,8 @@ func (il RateIntervalList) Swap(i, j int) {
|
||||
il[i], il[j] = il[j], il[i]
|
||||
}
|
||||
|
||||
func (il RateIntervalList) Less(i, j int) bool {
|
||||
// we need higher weights earlyer in the list
|
||||
func (il RateIntervalList) Less(j, i int) bool {
|
||||
return il[i].Weight < il[j].Weight
|
||||
}
|
||||
|
||||
|
||||
@@ -248,6 +248,7 @@ or if the Weights are equal and new price is lower then spans's interval price
|
||||
*/
|
||||
func (ts *TimeSpan) SetRateInterval(i *RateInterval) {
|
||||
//log.Printf("SETRATEINTERVAL: %+v", i.Timing)
|
||||
// higher weights are better
|
||||
if ts.RateInterval == nil || ts.RateInterval.Weight < i.Weight {
|
||||
ts.RateInterval = i
|
||||
//log.Printf("RET TS: %+v", ts.RateInterval.Timing)
|
||||
@@ -548,9 +549,9 @@ func (ts *TimeSpan) hasBetterRateIntervalThan(interval *RateInterval) bool {
|
||||
//log.Print("StartTime: ", ts.TimeStart)
|
||||
//log.Printf("OWN: %+v", ts.RateInterval)
|
||||
//log.Printf("OTHER: %+v", interval)
|
||||
// the lower the weight the better
|
||||
// the higher the weight the better
|
||||
if ts.RateInterval != nil &&
|
||||
ts.RateInterval.Weight < interval.Weight {
|
||||
ts.RateInterval.Weight > interval.Weight {
|
||||
return true
|
||||
}
|
||||
// check interval is closer than the new one
|
||||
|
||||
Reference in New Issue
Block a user