Qos strategy consider Weight from SortingData

This commit is contained in:
TeoV
2018-08-02 06:46:50 -04:00
committed by Dan Christian Bogos
parent baecd90446
commit 8aefa9ace8
4 changed files with 123 additions and 42 deletions

View File

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

View File

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

View File

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

View File

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