timings and rate groups validation

This commit is contained in:
Radu Ioan Fericean
2015-05-21 15:41:05 +03:00
parent 3a0fe8e67c
commit bb6a7ea6c3
5 changed files with 143 additions and 35 deletions

View File

@@ -20,6 +20,7 @@ package engine
import (
"encoding/json"
"math"
"github.com/cgrates/cgrates/history"
)
@@ -114,7 +115,7 @@ func (rp *RatingPlan) GetHistoryRecord() history.Record {
}
// IsValid determines if the rating plan covers a continous period of time
func (rp *RatingPlan) IsValid() bool {
func (rp *RatingPlan) isContinous() bool {
weekdays := make([]int, 7)
for _, tm := range rp.Timings {
// if it is a blank timing than it will match all
@@ -146,3 +147,31 @@ func (rp *RatingPlan) IsValid() bool {
}
return false
}
func (rp *RatingPlan) areRatesSane() bool {
for _, rating := range rp.Ratings {
rating.Rates.Sort()
for i, rate := range rating.Rates {
if i < (len(rating.Rates) - 1) {
nextRate := rating.Rates[i+1]
if nextRate.GroupIntervalStart <= rate.GroupIntervalStart {
return false
}
if math.Mod(nextRate.GroupIntervalStart.Seconds(), rate.RateIncrement.Seconds()) != 0 {
return false
}
}
}
}
return true
}
func (rp *RatingPlan) areTimingsSane() bool {
for _, timing := range rp.Timings {
if (len(timing.Years) != 0 || len(timing.Months) != 0 || len(timing.MonthDays) != 0) &&
len(timing.WeekDays) != 0 {
return false
}
}
return true
}