destination rate selection fixes

This commit is contained in:
Radu Ioan Fericean
2016-05-16 21:16:25 +03:00
parent 4eeff7705c
commit 182da50555
6 changed files with 45 additions and 27 deletions

View File

@@ -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

View File

@@ -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())

View File

@@ -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 {

View File

@@ -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?
}
}
}

View File

@@ -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

View File

@@ -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
}
}
}
}