fixes for LCR test and code

This commit is contained in:
Radu Ioan Fericean
2015-04-15 20:02:24 +03:00
parent 8941a74cd9
commit b5ebf2c4ef
2 changed files with 64 additions and 59 deletions

View File

@@ -21,6 +21,7 @@ package engine
import (
"errors"
"fmt"
"log"
"log/syslog"
"sort"
"strings"
@@ -153,6 +154,7 @@ func (cd *CallDescriptor) LoadRatingPlans() (err error) {
}
//load the rating plans
if err != nil || !cd.continousRatingInfos() {
//log.Print("ERR: ", cd.GetKey(cd.Subject), err)
err = errors.New("Could not determine rating plans for call")
return
}
@@ -699,11 +701,12 @@ func (cd *CallDescriptor) GetLCR(stats StatsInterface) (*LCRCost, error) {
if lcrCost.Entry == nil {
return lcrCost, nil
}
//log.Printf("Entry: %+v", ts.Entry)
//log.Printf("Entry: %+v", lcrCost.Entry)
if lcrCost.Entry.Strategy == LCR_STRATEGY_STATIC {
for _, supplier := range lcrCost.Entry.GetParams() {
lcrCD := cd.Clone()
lcrCD.Subject = supplier
lcrCD.Category = lcrCost.Entry.RPCategory
var cc *CallCost
var err error
if cd.account, err = accountingStorage.GetAccount(cd.GetAccountKey()); err == nil {
@@ -712,7 +715,8 @@ func (cd *CallDescriptor) GetLCR(stats StatsInterface) (*LCRCost, error) {
cc, err = lcrCD.GetCost()
}
supplier = utils.ConcatenatedKey(cd.Direction, cd.Tenant, cd.Category, supplier)
supplier = utils.ConcatenatedKey(lcrCD.Direction, lcrCD.Tenant, lcrCD.Category, lcrCD.Subject)
//log.Printf("CC: %+v", cc.Timespans[0].ratingInfo.RateIntervals[0].Rating.Rates[0])
if err != nil || cc == nil {
lcrCost.SupplierCosts = append(lcrCost.SupplierCosts, &LCRSupplierCost{
Supplier: supplier,
@@ -733,11 +737,14 @@ func (cd *CallDescriptor) GetLCR(stats StatsInterface) (*LCRCost, error) {
category = lcr.Category
}
ratingProfileSearchKey := utils.ConcatenatedKey(lcr.Direction, lcr.Tenant, lcrCost.Entry.RPCategory)
log.Print("KEY: ", ratingProfileSearchKey)
suppliers := cache2go.GetEntriesKeys(RATING_PROFILE_PREFIX + ratingProfileSearchKey)
for _, supplier := range suppliers {
log.Print("Supplier: ", supplier)
split := strings.Split(supplier, ":")
supplier = split[len(split)-1]
lcrCD := cd.Clone()
lcrCD.Category = category
lcrCD.Subject = supplier
var asr, acd float64
var qosSortParams []string
@@ -802,7 +809,7 @@ func (cd *CallDescriptor) GetLCR(stats StatsInterface) (*LCRCost, error) {
} else {
cc, err = lcrCD.GetCost()
}
supplier = utils.ConcatenatedKey(cd.Direction, cd.Tenant, cd.Category, supplier)
supplier = utils.ConcatenatedKey(lcrCD.Direction, lcrCD.Tenant, lcrCD.Category, lcrCD.Subject)
if err != nil || cc == nil {
lcrCost.SupplierCosts = append(lcrCost.SupplierCosts, &LCRSupplierCost{
Supplier: supplier,

View File

@@ -239,7 +239,7 @@ func TestGetLCR(t *testing.T) {
},
}
rp3 := &RatingPlan{
Id: "RP2",
Id: "RP3",
Timings: map[string]*RITiming{
"30eab300": &RITiming{
Years: utils.Years{},
@@ -338,60 +338,58 @@ func TestGetLCR(t *testing.T) {
[]string{LCR_PREFIX + lcrStatic.GetId(), LCR_PREFIX + lcrLowestCost.GetId()}); err != nil {
t.Error(err)
}
/*
cdStatic := &CallDescriptor{
TimeStart: time.Date(2015, 04, 06, 17, 40, 0, 0, time.UTC),
TimeEnd: time.Date(2015, 04, 06, 17, 41, 0, 0, time.UTC),
Tenant: "cgrates.org",
Direction: utils.OUT,
Category: "call_static",
Destination: "+4986517174963",
Account: "dan",
Subject: "dan",
}
eStLcr := &LCRCost{
Entry: &LCREntry{DestinationId: utils.ANY, RPCategory: "call", Strategy: LCR_STRATEGY_STATIC, StrategyParams: "ivo12;dan12;rif12", Weight: 10.0},
SupplierCosts: []*LCRSupplierCost{
&LCRSupplierCost{Supplier: "*out:cgrates.org:call:ivo12", Cost: 1.8, Duration: 60 * time.Second},
&LCRSupplierCost{Supplier: "*out:cgrates.org:call:dan12", Cost: 0.6, Duration: 60 * time.Second},
&LCRSupplierCost{Supplier: "*out:cgrates.org:call:rif12", Cost: 1.2, Duration: 60 * time.Second},
},
}
var lcr LCRCost
if err := rsponder.GetLCR(cdStatic, &lcr); err != nil {
t.Error(err)
} else if !reflect.DeepEqual(eStLcr.Entry, lcr.Entry) {
t.Errorf("Expecting: %+v, received: %+v", eStLcr.Entry, lcr.Entry)
} else if !reflect.DeepEqual(eStLcr.SupplierCosts, lcr.SupplierCosts) {
t.Errorf("Expecting: %+v, received: %+v", eStLcr.SupplierCosts[2], lcr.SupplierCosts[2])
}
// Test *least_cost strategy here
cdLowestCost := &CallDescriptor{
TimeStart: time.Date(2015, 04, 06, 17, 40, 0, 0, time.UTC),
TimeEnd: time.Date(2015, 04, 06, 17, 41, 0, 0, time.UTC),
Tenant: "cgrates.org",
Direction: utils.OUT,
Category: "call_least_cost",
Destination: "+4986517174963",
Account: "dan",
Subject: "dan",
}
eLcLcr := &LCRCost{
Entry: &LCREntry{DestinationId: utils.ANY, RPCategory: "call", Strategy: LCR_STRATEGY_LOWEST, Weight: 10.0},
SupplierCosts: []*LCRSupplierCost{
&LCRSupplierCost{Supplier: "*out:cgrates.org:call:dan12", Cost: 0.6, Duration: 60 * time.Second},
&LCRSupplierCost{Supplier: "*out:cgrates.org:call:rif12", Cost: 1.2, Duration: 60 * time.Second},
&LCRSupplierCost{Supplier: "*out:cgrates.org:call:ivo12", Cost: 1.8, Duration: 60 * time.Second},
},
}
var lcrLc LCRCost
if err := rsponder.GetLCR(cdLowestCost, &lcrLc); err != nil {
t.Error(err)
} else if !reflect.DeepEqual(eLcLcr.Entry, lcrLc.Entry) {
t.Errorf("Expecting: %+v, received: %+v", eLcLcr.Entry, lcrLc.Entry)
cdStatic := &CallDescriptor{
TimeStart: time.Date(2015, 04, 06, 17, 40, 0, 0, time.UTC),
TimeEnd: time.Date(2015, 04, 06, 17, 41, 0, 0, time.UTC),
Tenant: "cgrates.org",
Direction: utils.OUT,
Category: "call_static",
Destination: "+4986517174963",
Account: "dan",
Subject: "dan",
}
eStLcr := &LCRCost{
Entry: &LCREntry{DestinationId: utils.ANY, RPCategory: "call", Strategy: LCR_STRATEGY_STATIC, StrategyParams: "ivo12;dan12;rif12", Weight: 10.0},
SupplierCosts: []*LCRSupplierCost{
&LCRSupplierCost{Supplier: "*out:cgrates.org:call:ivo12", Cost: 1.8, Duration: 60 * time.Second},
&LCRSupplierCost{Supplier: "*out:cgrates.org:call:dan12", Cost: 0.6, Duration: 60 * time.Second},
&LCRSupplierCost{Supplier: "*out:cgrates.org:call:rif12", Cost: 1.2, Duration: 60 * time.Second},
},
}
var lcr LCRCost
if err := rsponder.GetLCR(cdStatic, &lcr); err != nil {
t.Error(err)
} else if !reflect.DeepEqual(eStLcr.Entry, lcr.Entry) {
t.Errorf("Expecting: %+v, received: %+v", eStLcr.Entry, lcr.Entry)
} else if !reflect.DeepEqual(eStLcr.SupplierCosts, lcr.SupplierCosts) {
t.Errorf("Expecting: %+v, received: %+v", eStLcr.SupplierCosts[2], lcr.SupplierCosts[2])
}
// Test *least_cost strategy here
/*cdLowestCost := &CallDescriptor{
TimeStart: time.Date(2015, 04, 06, 17, 40, 0, 0, time.UTC),
TimeEnd: time.Date(2015, 04, 06, 17, 41, 0, 0, time.UTC),
Tenant: "cgrates.org",
Direction: utils.OUT,
Category: "call_least_cost",
Destination: "+4986517174963",
Account: "dan",
Subject: "dan",
}
eLcLcr := &LCRCost{
Entry: &LCREntry{DestinationId: utils.ANY, RPCategory: "call", Strategy: LCR_STRATEGY_LOWEST, Weight: 10.0},
SupplierCosts: []*LCRSupplierCost{
&LCRSupplierCost{Supplier: "*out:cgrates.org:call:dan12", Cost: 0.6, Duration: 60 * time.Second},
&LCRSupplierCost{Supplier: "*out:cgrates.org:call:rif12", Cost: 1.2, Duration: 60 * time.Second},
&LCRSupplierCost{Supplier: "*out:cgrates.org:call:ivo12", Cost: 1.8, Duration: 60 * time.Second},
},
}
var lcrLc LCRCost
if err := rsponder.GetLCR(cdLowestCost, &lcrLc); err != nil {
t.Error(err)
} else if !reflect.DeepEqual(eLcLcr.Entry, lcrLc.Entry) {
t.Errorf("Expecting: %+v, received: %+v", eLcLcr.Entry, lcrLc.Entry)
} else if !reflect.DeepEqual(eLcLcr.SupplierCosts, lcrLc.SupplierCosts) {
t.Errorf("Expecting: %+v, received: %+v", eLcLcr.SupplierCosts[2], lcrLc.SupplierCosts[2])
}
*/
} else if !reflect.DeepEqual(eLcLcr.SupplierCosts, lcrLc.SupplierCosts) {
t.Errorf("Expecting: %+v, received: %+v", eLcLcr.SupplierCosts[2], lcrLc.SupplierCosts[2])
}*/
}