diff --git a/engine/eventcost.go b/engine/eventcost.go index 5066dd846..7969a956a 100644 --- a/engine/eventcost.go +++ b/engine/eventcost.go @@ -355,33 +355,16 @@ 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) - 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 { + if lenChargers != 0 && ec.Charges[lenChargers-1].PartiallyEquals(oEC.Charges[cIlIdx]) { + ec.Charges[lenChargers-1].CompressFactor += 1 + } else { 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) diff --git a/engine/libsuppliers.go b/engine/libsuppliers.go index 67342098b..1904b01e4 100644 --- a/engine/libsuppliers.go +++ b/engine/libsuppliers.go @@ -111,7 +111,7 @@ func (sSpls *SortedSuppliers) SortQOS(params []string) { return sSpls.SortedSuppliers[i].globalStats[param] < sSpls.SortedSuppliers[j].globalStats[param] } } - return sSpls.SortedSuppliers[i].globalStats[utils.Weight] > sSpls.SortedSuppliers[j].globalStats[utils.Weight] + return sSpls.SortedSuppliers[i].SortingData[utils.Weight].(float64) > sSpls.SortedSuppliers[j].SortingData[utils.Weight].(float64) }) } diff --git a/engine/libsuppliers_test.go b/engine/libsuppliers_test.go index 1b59af1b5..2e3b14982 100644 --- a/engine/libsuppliers_test.go +++ b/engine/libsuppliers_test.go @@ -624,7 +624,9 @@ func TestLibSuppliersSortQOS6(t *testing.T) { SupplierID: "supplier1", globalStats: map[string]float64{ utils.MetaACD: 0.2, - utils.Weight: 15.0, + }, + SortingData: map[string]interface{}{ + utils.Weight: 15.0, }, SupplierParameters: "param1", }, @@ -632,7 +634,9 @@ func TestLibSuppliersSortQOS6(t *testing.T) { SupplierID: "supplier2", globalStats: map[string]float64{ utils.MetaACD: 0.2, - utils.Weight: 25.0, + }, + SortingData: map[string]interface{}{ + utils.Weight: 25.0, }, SupplierParameters: "param2", }, @@ -640,7 +644,9 @@ func TestLibSuppliersSortQOS6(t *testing.T) { SupplierID: "supplier3", globalStats: map[string]float64{ utils.MetaACD: 0.1, - utils.Weight: 20.0, + }, + SortingData: map[string]interface{}{ + utils.Weight: 20.0, }, SupplierParameters: "param3", }, @@ -653,7 +659,9 @@ func TestLibSuppliersSortQOS6(t *testing.T) { SupplierID: "supplier2", globalStats: map[string]float64{ utils.MetaACD: 0.2, - utils.Weight: 25.0, + }, + SortingData: map[string]interface{}{ + utils.Weight: 25.0, }, SupplierParameters: "param2", }, @@ -661,7 +669,9 @@ func TestLibSuppliersSortQOS6(t *testing.T) { SupplierID: "supplier1", globalStats: map[string]float64{ utils.MetaACD: 0.2, - utils.Weight: 15.0, + }, + SortingData: map[string]interface{}{ + utils.Weight: 15.0, }, SupplierParameters: "param1", }, @@ -670,7 +680,9 @@ func TestLibSuppliersSortQOS6(t *testing.T) { SupplierID: "supplier3", globalStats: map[string]float64{ utils.MetaACD: 0.1, - utils.Weight: 20.0, + }, + SortingData: map[string]interface{}{ + utils.Weight: 20.0, }, SupplierParameters: "param3", }, @@ -688,24 +700,30 @@ func TestLibSuppliersSortQOS7(t *testing.T) { &SortedSupplier{ SupplierID: "supplier1", globalStats: map[string]float64{ - utils.MetaACD: 1000000, - utils.Weight: 15.0, + utils.MetaACD: -1.0, + }, + SortingData: map[string]interface{}{ + utils.Weight: 15.0, }, SupplierParameters: "param1", }, &SortedSupplier{ SupplierID: "supplier2", globalStats: map[string]float64{ - utils.MetaACD: 1000000, - utils.Weight: 25.0, + utils.MetaACD: -1.0, + }, + SortingData: map[string]interface{}{ + utils.Weight: 25.0, }, SupplierParameters: "param2", }, &SortedSupplier{ SupplierID: "supplier3", globalStats: map[string]float64{ - utils.MetaACD: 1000000, - utils.Weight: 20.0, + utils.MetaACD: -1.0, + }, + SortingData: map[string]interface{}{ + utils.Weight: 20.0, }, SupplierParameters: "param3", }, @@ -717,24 +735,107 @@ func TestLibSuppliersSortQOS7(t *testing.T) { &SortedSupplier{ SupplierID: "supplier2", globalStats: map[string]float64{ - utils.MetaACD: 1000000, - utils.Weight: 25.0, + utils.MetaACD: -1.0, + }, + SortingData: map[string]interface{}{ + utils.Weight: 25.0, }, SupplierParameters: "param2", }, &SortedSupplier{ SupplierID: "supplier3", globalStats: map[string]float64{ - utils.MetaACD: 1000000, - utils.Weight: 20.0, + utils.MetaACD: -1.0, + }, + SortingData: map[string]interface{}{ + utils.Weight: 20.0, }, SupplierParameters: "param3", }, &SortedSupplier{ SupplierID: "supplier1", globalStats: map[string]float64{ - utils.MetaACD: 1000000, - utils.Weight: 15.0, + utils.MetaACD: -1.0, + }, + SortingData: map[string]interface{}{ + utils.Weight: 15.0, + }, + SupplierParameters: "param1", + }, + }, + } + if !reflect.DeepEqual(eOrderedSpls, sSpls) { + t.Errorf("Expecting: %s, received: %s", + utils.ToJSON(eOrderedSpls), utils.ToJSON(sSpls)) + } +} + +func TestLibSuppliersSortQOS8(t *testing.T) { + sSpls := &SortedSuppliers{ + SortedSuppliers: []*SortedSupplier{ + &SortedSupplier{ + SupplierID: "supplier1", + globalStats: map[string]float64{ + utils.MetaACD: -1.0, + }, + SortingData: map[string]interface{}{ + utils.Weight: 15.0, + }, + SupplierParameters: "param1", + }, + &SortedSupplier{ + SupplierID: "supplier2", + globalStats: map[string]float64{ + utils.MetaACD: -1.0, + }, + SortingData: map[string]interface{}{ + utils.Weight: 25.0, + }, + SupplierParameters: "param2", + }, + &SortedSupplier{ + SupplierID: "supplier3", + globalStats: map[string]float64{ + utils.MetaACD: 10.0, + }, + SortingData: map[string]interface{}{ + utils.Weight: 20.0, + }, + SupplierParameters: "param3", + }, + }, + } + sSpls.SortQOS([]string{utils.MetaACD}) + eOrderedSpls := &SortedSuppliers{ + SortedSuppliers: []*SortedSupplier{ + &SortedSupplier{ + SupplierID: "supplier3", + globalStats: map[string]float64{ + utils.MetaACD: 10.0, + }, + SortingData: map[string]interface{}{ + utils.Weight: 20.0, + }, + SupplierParameters: "param3", + }, + &SortedSupplier{ + SupplierID: "supplier2", + globalStats: map[string]float64{ + utils.MetaACD: -1.0, + }, + SortingData: map[string]interface{}{ + utils.Weight: 25.0, + }, + SupplierParameters: "param2", + }, + + &SortedSupplier{ + SupplierID: "supplier1", + globalStats: map[string]float64{ + utils.MetaACD: -1.0, + }, + SortingData: map[string]interface{}{ + utils.Weight: 15.0, }, SupplierParameters: "param1", }, diff --git a/sessions/session.go b/sessions/session.go index 088744162..9112347da 100644 --- a/sessions/session.go +++ b/sessions/session.go @@ -150,13 +150,10 @@ 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