mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
renamed share to ratio
This commit is contained in:
@@ -37,10 +37,10 @@ Strategy indicates supplier selection algorithm and StrategyParams will be speci
|
||||
|
||||
\*load_distribution (sorting/filter)
|
||||
The system will sort the suppliers in order to achieve the specified load distribution.
|
||||
- if all have less than share return random order
|
||||
- if some have a cdr count not divisible by share return them first and all ordered by cdr times, oldest first
|
||||
- if all have a multiple of share return in the order of cdr times, oldest first
|
||||
StrategyParams: supplier1:share;supplier2:share;*default:share
|
||||
- if all have less than ratio return random order
|
||||
- if some have a cdr count not divisible by ratio return them first and all ordered by cdr times, oldest first
|
||||
- if all have a multiple of ratio return in the order of cdr times, oldest first
|
||||
StrategyParams: supplier1:ratio;supplier2:ratio;*default:ratio
|
||||
|
||||
ActivationTime is the date/time when the LCR entry starts to be active.
|
||||
|
||||
|
||||
@@ -337,25 +337,25 @@ func (lc *LCRCost) SortLoadDistribution() {
|
||||
/*for supplier, sq := range supplierQueues {
|
||||
log.Printf("Useful supplier qeues: %s %v", supplier, sq.conf.TimeWindow)
|
||||
}*/
|
||||
// if all have less than share return random order
|
||||
// if some have a cdr count not divisible by share return them first and all ordered by cdr times, oldest first
|
||||
// if all have a multiple of share return in the order of cdr times, oldest first
|
||||
// if all have less than ratio return random order
|
||||
// if some have a cdr count not divisible by ratio return them first and all ordered by cdr times, oldest first
|
||||
// if all have a multiple of ratio return in the order of cdr times, oldest first
|
||||
|
||||
// first put them in one of the above categories
|
||||
haveSharelessSuppliers := false
|
||||
haveRatiolessSuppliers := false
|
||||
for supCost, sq := range supplierQueues {
|
||||
share := lc.GetSupplierShare(supCost.Supplier)
|
||||
if share == -1 {
|
||||
ratio := lc.GetSupplierRatio(supCost.Supplier)
|
||||
if ratio == -1 {
|
||||
supCost.Cost = -1
|
||||
haveSharelessSuppliers = true
|
||||
haveRatiolessSuppliers = true
|
||||
continue
|
||||
}
|
||||
cdrCount := len(sq.Cdrs)
|
||||
if cdrCount < share {
|
||||
if cdrCount < ratio {
|
||||
supCost.Cost = float64(LOW_PRIORITY_LIMIT + rand.Intn(RAND_LIMIT))
|
||||
continue
|
||||
}
|
||||
if cdrCount%share == 0 {
|
||||
if cdrCount%ratio == 0 {
|
||||
supCost.Cost = float64(MED_PRIORITY_LIMIT+rand.Intn(RAND_LIMIT)) + (time.Now().Sub(sq.Cdrs[len(sq.Cdrs)-1].SetupTime).Seconds() / RAND_LIMIT)
|
||||
continue
|
||||
} else {
|
||||
@@ -363,7 +363,7 @@ func (lc *LCRCost) SortLoadDistribution() {
|
||||
continue
|
||||
}
|
||||
}
|
||||
if haveSharelessSuppliers {
|
||||
if haveRatiolessSuppliers {
|
||||
var filteredSupplierCost []*LCRSupplierCost
|
||||
for _, supCost := range lc.SupplierCosts {
|
||||
if supCost.Cost != -1 {
|
||||
@@ -375,35 +375,35 @@ func (lc *LCRCost) SortLoadDistribution() {
|
||||
}
|
||||
|
||||
// used in load distribution strategy only
|
||||
// receives a long supplier id and will return the share found in strategy params
|
||||
func (lc *LCRCost) GetSupplierShare(supplier string) int {
|
||||
// receives a long supplier id and will return the ratio found in strategy params
|
||||
func (lc *LCRCost) GetSupplierRatio(supplier string) int {
|
||||
// parse strategy params
|
||||
shares := make(map[string]int)
|
||||
ratios := make(map[string]int)
|
||||
params := strings.Split(lc.Entry.StrategyParams, utils.INFIELD_SEP)
|
||||
for _, param := range params {
|
||||
shareSlice := strings.Split(param, utils.CONCATENATED_KEY_SEP)
|
||||
if len(shareSlice) != 2 {
|
||||
ratioSlice := strings.Split(param, utils.CONCATENATED_KEY_SEP)
|
||||
if len(ratioSlice) != 2 {
|
||||
Logger.Warning(fmt.Sprintf("bad format in load distribution strategy param: %s", lc.Entry.StrategyParams))
|
||||
continue
|
||||
}
|
||||
p, err := strconv.Atoi(shareSlice[1])
|
||||
p, err := strconv.Atoi(ratioSlice[1])
|
||||
if err != nil {
|
||||
Logger.Warning(fmt.Sprintf("bad format in load distribution strategy param: %s", lc.Entry.StrategyParams))
|
||||
continue
|
||||
}
|
||||
shares[shareSlice[0]] = p
|
||||
ratios[ratioSlice[0]] = p
|
||||
}
|
||||
parts := strings.Split(supplier, utils.CONCATENATED_KEY_SEP)
|
||||
if len(parts) > 0 {
|
||||
supplierSubject := parts[len(parts)-1]
|
||||
if share, found := shares[supplierSubject]; found {
|
||||
return share
|
||||
if ratio, found := ratios[supplierSubject]; found {
|
||||
return ratio
|
||||
}
|
||||
if share, found := shares[utils.META_DEFAULT]; found {
|
||||
return share
|
||||
if ratio, found := ratios[utils.META_DEFAULT]; found {
|
||||
return ratio
|
||||
}
|
||||
}
|
||||
if len(shares) == 0 {
|
||||
if len(ratios) == 0 {
|
||||
return 1 // use random/last cdr date sorting
|
||||
}
|
||||
return -1 // exclude missing suppliers
|
||||
|
||||
Reference in New Issue
Block a user