mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-20 06:38:45 +05:00
destination rate selection fixes
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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?
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user