mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Merge branch 'master' of https://github.com/cgrates/cgrates
This commit is contained in:
@@ -20,7 +20,6 @@ package engine
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"reflect"
|
||||
"time"
|
||||
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
@@ -37,21 +36,7 @@ type CallCost struct {
|
||||
|
||||
// Merges the received timespan if they are similar (same activation period, same interval, same minute info.
|
||||
func (cc *CallCost) Merge(other *CallCost) {
|
||||
if len(cc.Timespans)-1 < 0 || len(other.Timespans) == 0 {
|
||||
return
|
||||
}
|
||||
ts := cc.Timespans[len(cc.Timespans)-1]
|
||||
otherTs := other.Timespans[0]
|
||||
if reflect.DeepEqual(ts.ratingInfo, otherTs.ratingInfo) &&
|
||||
reflect.DeepEqual(ts.RateInterval, otherTs.RateInterval) {
|
||||
// extend the last timespan with
|
||||
ts.TimeEnd = ts.TimeEnd.Add(otherTs.GetDuration())
|
||||
// add the rest of the timspans
|
||||
cc.Timespans = append(cc.Timespans, other.Timespans[1:]...)
|
||||
} else {
|
||||
// just add all timespans
|
||||
cc.Timespans = append(cc.Timespans, other.Timespans...)
|
||||
}
|
||||
cc.Timespans = append(cc.Timespans, other.Timespans...)
|
||||
cc.Cost += other.Cost
|
||||
}
|
||||
|
||||
|
||||
@@ -121,8 +121,8 @@ func TestMultipleInputRightMerge(t *testing.T) {
|
||||
t.Errorf("expected 91 was %v", cc2.Cost)
|
||||
}
|
||||
cc1.Merge(cc2)
|
||||
if len(cc1.Timespans) != 2 || cc1.Timespans[0].GetDuration().Seconds() != 120 {
|
||||
t.Error("wrong resulted timespan: ", len(cc1.Timespans))
|
||||
if len(cc1.Timespans) != 3 || cc1.Timespans[0].GetDuration().Seconds() != 60 {
|
||||
t.Error("wrong resulted timespan: ", len(cc1.Timespans), cc1.Timespans[0].GetDuration().Seconds())
|
||||
}
|
||||
if cc1.Cost != 152 {
|
||||
t.Errorf("Exdpected 152 was %v", cc1.Cost)
|
||||
|
||||
@@ -217,8 +217,11 @@ func (s *Session) SaveOperations() {
|
||||
}
|
||||
firstCC := sr.CallCosts[0]
|
||||
for _, cc := range sr.CallCosts[1:] {
|
||||
engine.Logger.Debug(fmt.Sprintf("BEFORE MERGE: %+v", firstCC))
|
||||
firstCC.Merge(cc)
|
||||
engine.Logger.Debug(fmt.Sprintf("AFTER MERGE: %+v", firstCC))
|
||||
}
|
||||
|
||||
var reply string
|
||||
err := s.sessionManager.CdrSrv().LogCallCost(&engine.CallCostLog{
|
||||
CgrId: s.eventStart.GetCgrId(),
|
||||
|
||||
Reference in New Issue
Block a user