callcost merge simplified, possible fix for #118

This commit is contained in:
Radu Ioan Fericean
2015-07-15 22:11:52 +03:00
parent 986114be13
commit 39700e1c66
2 changed files with 4 additions and 15 deletions

View File

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

View File

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