Update supplier_it_test with different statistics and add logs for session

This commit is contained in:
TeoV
2018-08-02 03:25:15 -04:00
committed by Dan Christian Bogos
parent efe71c09d4
commit cad0d1b4f7
4 changed files with 63 additions and 25 deletions

View File

@@ -503,6 +503,24 @@ func testV1SplSPolulateStatsForQOS(t *testing.T) {
t.Errorf("Expecting: %+v, received: %+v", expected, reply)
}
expected = []string{"Stat_1_1"}
ev1 = utils.CGREvent{
Tenant: "cgrates.org",
ID: "event3",
Event: map[string]interface{}{
"Stat": "Stat1_1",
utils.AnswerTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
utils.Usage: time.Duration(15 * time.Second),
utils.COST: 15.5,
utils.PDD: time.Duration(15 * time.Second),
},
}
if err := splSv1Rpc.Call(utils.StatSv1ProcessEvent, &ev1, &reply); err != nil {
t.Error(err)
} else if !reflect.DeepEqual(reply, expected) {
t.Errorf("Expecting: %+v, received: %+v", expected, reply)
}
}
func testV1SplSGetQOSSuppliers(t *testing.T) {
@@ -519,6 +537,18 @@ func testV1SplSGetQOSSuppliers(t *testing.T) {
ProfileID: "SPL_QOS_1",
Sorting: utils.MetaQOS,
SortedSuppliers: []*engine.SortedSupplier{
&engine.SortedSupplier{
SupplierID: "supplier1",
SortingData: map[string]interface{}{
"*acd:Stat_1": 11.0,
"*acd:Stat_1_1": 13.0,
"*asr:Stat_1": 100.0,
"*pdd:Stat_1_1": 13.5,
"*tcd:Stat_1": 22.0,
"*tcd:Stat_1_1": 26.0,
utils.Weight: 10.0,
},
},
&engine.SortedSupplier{
SupplierID: "supplier3",
SortingData: map[string]interface{}{
@@ -528,18 +558,6 @@ func testV1SplSGetQOSSuppliers(t *testing.T) {
utils.Weight: 35.0,
},
},
&engine.SortedSupplier{
SupplierID: "supplier1",
SortingData: map[string]interface{}{
"*acd:Stat_1": 11.0,
"*acd:Stat_1_1": 11.0,
"*asr:Stat_1": 100.0,
"*pdd:Stat_1_1": 12.0,
"*tcd:Stat_1": 22.0,
"*tcd:Stat_1_1": 11.0,
utils.Weight: 10.0,
},
},
&engine.SortedSupplier{
SupplierID: "supplier2",
@@ -598,11 +616,11 @@ func testV1SplSGetQOSSuppliers2(t *testing.T) {
SupplierID: "supplier1",
SortingData: map[string]interface{}{
"*acd:Stat_1": 11.0,
"*acd:Stat_1_1": 11.0,
"*acd:Stat_1_1": 13.0,
"*asr:Stat_1": 100.0,
"*pdd:Stat_1_1": 12.0,
"*pdd:Stat_1_1": 13.5,
"*tcd:Stat_1": 22.0,
"*tcd:Stat_1_1": 11.0,
"*tcd:Stat_1_1": 26.0,
utils.Weight: 10.0,
},
},
@@ -636,11 +654,11 @@ func testV1SplSGetQOSSuppliers3(t *testing.T) {
SupplierID: "supplier1",
SortingData: map[string]interface{}{
"*acd:Stat_1": 11.0,
"*acd:Stat_1_1": 11.0,
"*acd:Stat_1_1": 13.0,
"*asr:Stat_1": 100.0,
"*pdd:Stat_1_1": 12.0,
"*pdd:Stat_1_1": 13.5,
"*tcd:Stat_1": 22.0,
"*tcd:Stat_1_1": 11.0,
"*tcd:Stat_1_1": 26.0,
utils.Weight: 10.0,
},
},
@@ -692,11 +710,11 @@ func testV1SplSGetQOSSuppliersFiltred(t *testing.T) {
SupplierID: "supplier1",
SortingData: map[string]interface{}{
"*acd:Stat_1": 11.0,
"*acd:Stat_1_1": 11.0,
"*acd:Stat_1_1": 13.0,
"*asr:Stat_1": 100.0,
"*pdd:Stat_1_1": 12.0,
"*pdd:Stat_1_1": 13.5,
"*tcd:Stat_1": 22.0,
"*tcd:Stat_1_1": 11.0,
"*tcd:Stat_1_1": 26.0,
utils.Weight: 10.0,
},
},

View File

@@ -20,6 +20,7 @@ package engine
import (
"errors"
"fmt"
"time"
"github.com/cgrates/cgrates/utils"
@@ -354,16 +355,33 @@ func (ec *EventCost) appendCIlFromEC(oEC *EventCost, cIlIdx int) {
// AppendChargingInterval appends or compresses a &ChargingInterval to existing ec.Chargers
func (ec *EventCost) AppendChargingIntervalFromEventCost(oEC *EventCost, cIlIdx int) {
lenChargers := len(ec.Charges)
if lenChargers != 0 && ec.Charges[lenChargers-1].PartiallyEquals(oEC.Charges[cIlIdx]) {
ec.Charges[lenChargers-1].CompressFactor += 1
} else {
fmt.Printf("\n#####Enter on AppendChargingIntervalFromEventCost#####\n")
fmt.Printf("\nlenChargers : %+v\n", lenChargers)
fmt.Printf("\n len(oEC.Charges) : %+v\n", len(oEC.Charges))
fmt.Printf("\n oEC.Charges[cIlIdx] : %+v\n", utils.ToJSON(oEC.Charges))
wasAdded := false
if lenChargers != 0 {
for i, charger := range ec.Charges {
fmt.Printf("\ni : %+v and charger : %+v\n", i, utils.ToJSON(charger))
if ec.Charges[i].PartiallyEquals(oEC.Charges[cIlIdx]) {
ec.Charges[i].CompressFactor += 1
wasAdded = true
}
}
}
if !wasAdded {
ec.appendCIlFromEC(oEC, cIlIdx)
}
}
// Merge will merge a list of EventCosts into this one
func (ec *EventCost) Merge(ecs ...*EventCost) {
fmt.Printf("\n#####Enter on merge#####\n")
for _, newEC := range ecs {
fmt.Printf("len(ecs.Chargers) : %+v\n", len(newEC.Charges))
ec.AccountSummary = newEC.AccountSummary // updated AccountSummary information
for cIlIdx := range newEC.Charges {
ec.AppendChargingIntervalFromEventCost(newEC, cIlIdx)

View File

@@ -33,7 +33,6 @@ type ChargingInterval struct {
usage *time.Duration // cache usage computation for this interval
ecUsageIdx *time.Duration // computed value of totalUsage at the starting of the interval
cost *float64 // cache cost calculation on this interval
}
// PartiallyEquals does not compare CompressFactor, usefull for Merge

View File

@@ -150,10 +150,13 @@ func (self *SMGSession) debit(dur time.Duration, lastUsed *time.Duration) (time.
self.LastDebit = initialExtraDuration + ccDuration
self.TotalUsage += self.LastUsage
ec := engine.NewEventCostFromCallCost(cc, self.CGRID, self.RunID)
fmt.Printf("###New event cost (Chargers) %+v\n\n", utils.ToJSON(ec.Charges))
if self.EventCost == nil {
self.EventCost = ec
} else {
fmt.Printf("###self.EventCost.Chargers before merge %+v\n\n", utils.ToJSON(self.EventCost.Charges))
self.EventCost.Merge(ec)
fmt.Printf("###self.EventCost.Chargers after merge %+v\n\n", utils.ToJSON(self.EventCost.Charges))
}
if ccDuration < dur {
return initialExtraDuration + ccDuration, nil