extended timespan compression

This commit is contained in:
Radu Ioan Fericean
2016-01-09 18:07:36 +02:00
parent c55734afd3
commit dc5da8663c
7 changed files with 212 additions and 77 deletions

View File

@@ -204,6 +204,8 @@ func (s *Session) Refund(lastCC *engine.CallCost, hangupTime time.Time) error {
TOR: lastCC.TOR,
Increments: refundIncrements,
}
cd.Increments.Compress()
utils.Logger.Info(fmt.Sprintf("Refunding duration %v with cd: %+v", refundDuration, cd))
var response float64
err := s.sessionManager.Rater().RefundIncrements(cd, &response)
if err != nil {

View File

@@ -117,7 +117,7 @@ func TestSessionRefund(t *testing.T) {
cc := &engine.CallCost{Timespans: engine.TimeSpans{ts}}
hangupTime := time.Date(2015, 6, 10, 14, 7, 20, 0, time.UTC)
s.Refund(cc, hangupTime)
if len(mc.refundCd.Increments) != 10 || len(cc.Timespans) != 1 || cc.Timespans[0].TimeEnd != hangupTime {
if len(mc.refundCd.Increments) != 1 || mc.refundCd.Increments[0].GetCompressFactor() != 10 || len(cc.Timespans) != 1 || cc.Timespans[0].TimeEnd != hangupTime {
t.Errorf("Error refunding: %+v, %+v", mc.refundCd.Increments, cc.Timespans[0])
}
}
@@ -137,7 +137,7 @@ func TestSessionRefundAll(t *testing.T) {
cc := &engine.CallCost{Timespans: engine.TimeSpans{ts}}
hangupTime := time.Date(2015, 6, 10, 14, 7, 0, 0, time.UTC)
s.Refund(cc, hangupTime)
if len(mc.refundCd.Increments) != 30 || len(cc.Timespans) != 0 {
if len(mc.refundCd.Increments) != 1 || mc.refundCd.Increments[0].GetCompressFactor() != 30 || len(cc.Timespans) != 0 {
t.Errorf("Error refunding: %+v, %+v", len(mc.refundCd.Increments), cc.Timespans)
}
}
@@ -166,7 +166,7 @@ func TestSessionRefundManyAll(t *testing.T) {
cc := &engine.CallCost{Timespans: engine.TimeSpans{ts1, ts2}}
hangupTime := time.Date(2015, 6, 10, 14, 07, 0, 0, time.UTC)
s.Refund(cc, hangupTime)
if len(mc.refundCd.Increments) != 60 || len(cc.Timespans) != 0 {
if len(mc.refundCd.Increments) != 1 || mc.refundCd.Increments[0].GetCompressFactor() != 60 || len(cc.Timespans) != 0 {
t.Errorf("Error refunding: %+v, %+v", len(mc.refundCd.Increments), cc.Timespans)
}
}

View File

@@ -155,6 +155,8 @@ func (self *SMGSession) refund(refundDuration time.Duration) error {
TOR: lastCC.TOR,
Increments: refundIncrements,
}
cd.Increments.Compress()
utils.Logger.Info(fmt.Sprintf("Refunding duration %v with cd: %+v", refundDuration, cd))
var response float64
err := self.rater.RefundIncrements(cd, &response)
if err != nil {