Added rating id and destination id to call cost

This commit is contained in:
Radu Ioan Fericean
2014-03-17 18:37:20 +02:00
parent e2e3b8d2f2
commit f6741c6d88
6 changed files with 24 additions and 14 deletions

View File

@@ -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++ {

View File

@@ -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"])
}
}

View File

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

View File

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

View File

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

View File

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