From f6741c6d88a254353305550109fbd3f5919d6012 Mon Sep 17 00:00:00 2001 From: Radu Ioan Fericean Date: Mon, 17 Mar 2014 18:37:20 +0200 Subject: [PATCH] Added rating id and destination id to call cost --- engine/calldesc.go | 1 + engine/loader_csv_test.go | 5 ++++- engine/loader_helpers.go | 1 + engine/rateinterval.go | 1 + engine/ratingprofile.go | 15 +++++++++------ engine/timespans.go | 15 ++++++++------- 6 files changed, 24 insertions(+), 14 deletions(-) diff --git a/engine/calldesc.go b/engine/calldesc.go index cc87f0b33..928133e6b 100644 --- a/engine/calldesc.go +++ b/engine/calldesc.go @@ -312,6 +312,7 @@ func (cd *CallDescriptor) splitInTimeSpans(firstSpan *TimeSpan) (timespans []*Ti firstSpan.ratingInfo = rp firstSpan.MatchedSubject = rp.MatchedSubject firstSpan.MatchedPrefix = rp.MatchedPrefix + firstSpan.MatchedDestId = rp.MatchedDestId } else { afterStart = true for i := 0; i < len(timespans); i++ { diff --git a/engine/loader_csv_test.go b/engine/loader_csv_test.go index b59e18451..eb7ce86c2 100644 --- a/engine/loader_csv_test.go +++ b/engine/loader_csv_test.go @@ -482,6 +482,7 @@ func TestLoadDestinationRateTimings(t *testing.T) { }, Ratings: map[string]*RIRate{ "d54545c1": &RIRate{ + Id: "R1", ConnectFee: 0, Rates: []*Rate{ &Rate{ @@ -495,6 +496,7 @@ func TestLoadDestinationRateTimings(t *testing.T) { RoundingDecimals: 2, }, "4bb00b9c": &RIRate{ + Id: "R2", ConnectFee: 0, Rates: []*Rate{ &Rate{ @@ -508,6 +510,7 @@ func TestLoadDestinationRateTimings(t *testing.T) { RoundingDecimals: 2, }, "e06c337f": &RIRate{ + Id: "R3", ConnectFee: 0, Rates: []*Rate{ &Rate{ @@ -566,7 +569,7 @@ func TestLoadDestinationRateTimings(t *testing.T) { }, } if !reflect.DeepEqual(rplan, expected) { - t.Errorf("Error loading destination rate timing: %+v", rplan) + t.Errorf("Error loading destination rate timing: %+v", rplan.Ratings["e06c337f"]) } } diff --git a/engine/loader_helpers.go b/engine/loader_helpers.go index 5bc2faff2..cbecc69b7 100644 --- a/engine/loader_helpers.go +++ b/engine/loader_helpers.go @@ -126,6 +126,7 @@ func GetRateInterval(rpl *utils.TPRatingPlanBinding, dr *utils.DestinationRate) }, Weight: rpl.Weight, Rating: &RIRate{ + Id: dr.Rate.RateId, ConnectFee: dr.Rate.RateSlots[0].ConnectFee, RoundingMethod: dr.Rate.RateSlots[0].RoundingMethod, RoundingDecimals: dr.Rate.RateSlots[0].RoundingDecimals, diff --git a/engine/rateinterval.go b/engine/rateinterval.go index a7522c1a6..190c310c7 100644 --- a/engine/rateinterval.go +++ b/engine/rateinterval.go @@ -53,6 +53,7 @@ func (rit *RITiming) Stringify() string { // Separate structure used for rating plan size optimization type RIRate struct { + Id string // informational role only ConnectFee float64 Rates RateGroups // GroupRateInterval (start time): Rate RoundingMethod string //ROUNDING_UP, ROUNDING_DOWN, ROUNDING_MIDDLE diff --git a/engine/ratingprofile.go b/engine/ratingprofile.go index 8bc32afc6..5a959ad69 100644 --- a/engine/ratingprofile.go +++ b/engine/ratingprofile.go @@ -82,6 +82,7 @@ func (rpas RatingPlanActivations) GetActiveForCall(cd *CallDescriptor) RatingPla type RatingInfo struct { MatchedSubject string MatchedPrefix string + MatchedDestId string ActivationTime time.Time RateIntervals RateIntervalList FallbackKeys []string @@ -113,7 +114,8 @@ func (rp *RatingProfile) GetRatingPlansForPrefix(cd *CallDescriptor) (err error) Logger.Err(fmt.Sprintf("Error checking destination: %v", err)) continue } - bestPrecision := 0 + prefix := "" + destinationId := "" var rps RateIntervalList for _, p := range utils.SplitPrefix(cd.Destination, MIN_PREFIX_MATCH) { if x, err := cache2go.GetCached(DESTINATION_PREFIX + p); err == nil { @@ -121,7 +123,8 @@ func (rp *RatingProfile) GetRatingPlansForPrefix(cd *CallDescriptor) (err error) for _, dId := range destIds { if _, ok := rpl.DestinationRates[dId]; ok { rps = rpl.RateIntervalList(dId) - bestPrecision = len(p) + prefix = p + destinationId = dId break } } @@ -132,13 +135,13 @@ func (rp *RatingProfile) GetRatingPlansForPrefix(cd *CallDescriptor) (err error) } // check if it's the first ri and add a blank one for the initial part not covered if index == 0 && cd.TimeStart.Before(rpa.ActivationTime) { - ris = append(ris, &RatingInfo{"", "", cd.TimeStart, nil, []string{cd.GetKey(FALLBACK_SUBJECT)}}) + ris = append(ris, &RatingInfo{"", "", "", cd.TimeStart, nil, []string{cd.GetKey(FALLBACK_SUBJECT)}}) } - if bestPrecision > 0 { - ris = append(ris, &RatingInfo{rp.Id, cd.Destination[:bestPrecision], rpa.ActivationTime, rps, rpa.FallbackKeys}) + if len(prefix) > 0 { + ris = append(ris, &RatingInfo{rp.Id, prefix, destinationId, rpa.ActivationTime, rps, rpa.FallbackKeys}) } else { // add for fallback information - ris = append(ris, &RatingInfo{"", "", rpa.ActivationTime, nil, rpa.FallbackKeys}) + ris = append(ris, &RatingInfo{"", "", "", rpa.ActivationTime, nil, rpa.FallbackKeys}) } } if len(ris) > 0 { diff --git a/engine/timespans.go b/engine/timespans.go index 1c5d528ff..2f8db402b 100644 --- a/engine/timespans.go +++ b/engine/timespans.go @@ -30,13 +30,13 @@ import ( A unit in which a call will be split that has a specific price related interval attached to it. */ type TimeSpan struct { - TimeStart, TimeEnd time.Time - Cost float64 - ratingInfo *RatingInfo - RateInterval *RateInterval - CallDuration time.Duration // the call duration so far till TimeEnd - Increments Increments - MatchedSubject, MatchedPrefix string + TimeStart, TimeEnd time.Time + Cost float64 + ratingInfo *RatingInfo + RateInterval *RateInterval + CallDuration time.Duration // the call duration so far till TimeEnd + Increments Increments + MatchedSubject, MatchedPrefix, MatchedDestId string } type Increment struct { @@ -437,6 +437,7 @@ func (nts *TimeSpan) copyRatingInfo(ts *TimeSpan) { nts.ratingInfo = ts.ratingInfo nts.MatchedSubject = ts.ratingInfo.MatchedSubject nts.MatchedPrefix = ts.ratingInfo.MatchedPrefix + nts.MatchedDestId = ts.ratingInfo.MatchedDestId } // returns a time for the specified second in the time span