diff --git a/apier/v1/apier.go b/apier/v1/apier.go index 88bcbcf4d..6e44a7732 100644 --- a/apier/v1/apier.go +++ b/apier/v1/apier.go @@ -601,13 +601,13 @@ func (self *ApierV1) GetActions(actsId string, reply *[]*utils.TPAction) error { } type AttrSetActionPlan struct { - Id string // Profile id - ActionPlan []*ApiActionPlan // Set of actions this Actions profile will perform - Overwrite bool // If previously defined, will be overwritten - ReloadScheduler bool // Enables automatic reload of the scheduler (eg: useful when adding a single action timing) + Id string // Profile id + ActionPlan []*AttrActionPlan // Set of actions this Actions profile will perform + Overwrite bool // If previously defined, will be overwritten + ReloadScheduler bool // Enables automatic reload of the scheduler (eg: useful when adding a single action timing) } -type ApiActionPlan struct { +type AttrActionPlan struct { ActionsId string // Actions id Years string // semicolon separated list of years this timing is valid on, *any or empty supported Months string // semicolon separated list of months this timing is valid on, *any or empty supported diff --git a/apier/v1/apier_local_test.go b/apier/v1/apier_local_test.go index 3e5d3dbc9..a5fea9aff 100644 --- a/apier/v1/apier_local_test.go +++ b/apier/v1/apier_local_test.go @@ -988,8 +988,8 @@ func TestApierSetActionPlan(t *testing.T) { if !*testLocal { return } - atm1 := &ApiActionPlan{ActionsId: "ACTS_1", MonthDays: "1", Time: "00:00:00", Weight: 20.0} - atms1 := &AttrSetActionPlan{Id: "ATMS_1", ActionPlan: []*ApiActionPlan{atm1}} + atm1 := &AttrActionPlan{ActionsId: "ACTS_1", MonthDays: "1", Time: "00:00:00", Weight: 20.0} + atms1 := &AttrSetActionPlan{Id: "ATMS_1", ActionPlan: []*AttrActionPlan{atm1}} reply1 := "" if err := rater.Call("ApierV1.SetActionPlan", atms1, &reply1); err != nil { t.Error("Got error on ApierV1.SetActionPlan: ", err.Error()) diff --git a/engine/account.go b/engine/account.go index d70a974d3..1aca778d2 100644 --- a/engine/account.go +++ b/engine/account.go @@ -306,21 +306,22 @@ func (ub *Account) getBalancesForPrefix(prefix, category, direction, tor string, for _, p := range utils.SplitPrefix(prefix, MIN_PREFIX_MATCH) { if x, err := cache2go.Get(utils.DESTINATION_PREFIX + p); err == nil { destIds := x.(map[interface{}]struct{}) + foundResult := false + includeDest := true // wheter it is excluded or included for dId, _ := range destIds { - includeDest, found := b.DestinationIDs[dId.(string)] + inclDest, found := b.DestinationIDs[dId.(string)] if found { - if includeDest { - b.precision = len(p) - usefulBalances = append(usefulBalances, b) - break - } else { // the balance had !, so now equals false => exclude balance - b.precision = 1 // fake to exit the outer loop - break - } + foundResult = true + includeDest = includeDest && inclDest + } + } + if foundResult { + if includeDest { + b.precision = len(p) + usefulBalances = append(usefulBalances, b) + } else { + b.precision = 1 // fake to exit the outer loop } - /*if b.precision > 0 { - break - }*/ } } if b.precision > 0 { diff --git a/engine/callcost.go b/engine/callcost.go index 71e8609f2..c482f2b55 100644 --- a/engine/callcost.go +++ b/engine/callcost.go @@ -241,7 +241,7 @@ func (cc *CallCost) MatchCCFilter(bf *BalanceFilter) bool { for filterDestID := range *bf.DestinationIDs { if _, ok := destIds[filterDestID]; ok { foundMatchingDestID = true - break + break // only one found? } } } diff --git a/engine/rateinterval.go b/engine/rateinterval.go index 0b0b13ed2..71a1d75b8 100644 --- a/engine/rateinterval.go +++ b/engine/rateinterval.go @@ -360,6 +360,18 @@ func (ri *RateInterval) GetMaxCost() (float64, string) { // Structure to store intervals according to weight type RateIntervalList []*RateInterval +func (rl RateIntervalList) GetWeight() float64 { + // all reates should have the same weight + // just in case get the max + var maxWeight float64 + for _, r := range rl { + if r.Weight > maxWeight { + maxWeight = r.Weight + } + } + return maxWeight +} + // Structure to store intervals according to weight type RateIntervalTimeSorter struct { referenceTime time.Time diff --git a/engine/ratingprofile.go b/engine/ratingprofile.go index e72665a22..d0ec02be5 100644 --- a/engine/ratingprofile.go +++ b/engine/ratingprofile.go @@ -176,13 +176,18 @@ func (rpf *RatingProfile) GetRatingPlansForPrefix(cd *CallDescriptor) (err error for _, p := range utils.SplitPrefix(cd.Destination, MIN_PREFIX_MATCH) { if x, err := cache2go.Get(utils.DESTINATION_PREFIX + p); err == nil { destIds := x.(map[interface{}]struct{}) - for idId := range destIds { - dId := idId.(string) - if _, ok := rpl.DestinationRates[dId]; ok { - rps = rpl.RateIntervalList(dId) - prefix = p - destinationId = dId - break + var bestWeight float64 + for idID := range destIds { + dID := idID.(string) + if _, ok := rpl.DestinationRates[dID]; ok { + ril := rpl.RateIntervalList(dID) + currentWeight := ril.GetWeight() + if currentWeight > bestWeight { + bestWeight = currentWeight + rps = ril + prefix = p + destinationId = dID + } } } }