From 39700e1c667de9977ddc6f07a930386ae88ea713 Mon Sep 17 00:00:00 2001 From: Radu Ioan Fericean Date: Wed, 15 Jul 2015 22:11:52 +0300 Subject: [PATCH 1/3] callcost merge simplified, possible fix for #118 --- engine/callcost.go | 15 ++------------- engine/callcost_test.go | 4 ++-- 2 files changed, 4 insertions(+), 15 deletions(-) diff --git a/engine/callcost.go b/engine/callcost.go index 19a02bd3b..acfa8c525 100644 --- a/engine/callcost.go +++ b/engine/callcost.go @@ -20,7 +20,6 @@ package engine import ( "encoding/json" "errors" - "reflect" "time" "github.com/cgrates/cgrates/utils" @@ -40,18 +39,8 @@ 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...) - } + // just add all timespans + cc.Timespans = append(cc.Timespans, other.Timespans...) cc.Cost += other.Cost } diff --git a/engine/callcost_test.go b/engine/callcost_test.go index 5349b104b..6b3d6701f 100644 --- a/engine/callcost_test.go +++ b/engine/callcost_test.go @@ -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) From 0b5591747f312dd3a34d84ddbb43131e09f2d279 Mon Sep 17 00:00:00 2001 From: Radu Ioan Fericean Date: Thu, 16 Jul 2015 10:41:08 +0300 Subject: [PATCH 2/3] removed merge timespans check --- engine/callcost.go | 4 ---- 1 file changed, 4 deletions(-) diff --git a/engine/callcost.go b/engine/callcost.go index acfa8c525..238619491 100644 --- a/engine/callcost.go +++ b/engine/callcost.go @@ -36,10 +36,6 @@ 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 - } - // just add all timespans cc.Timespans = append(cc.Timespans, other.Timespans...) cc.Cost += other.Cost } From d5ca85573f20b7f23f22f27844d47d108f738560 Mon Sep 17 00:00:00 2001 From: Radu Ioan Fericean Date: Thu, 16 Jul 2015 10:58:13 +0300 Subject: [PATCH 3/3] added call details logging --- sessionmanager/session.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/sessionmanager/session.go b/sessionmanager/session.go index 5a378ca3d..e117112e9 100644 --- a/sessionmanager/session.go +++ b/sessionmanager/session.go @@ -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(),