mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
rating plan optimization
This commit is contained in:
@@ -58,8 +58,8 @@ func (at *ActionTiming) GetNextStartTime() (t time.Time) {
|
||||
now := time.Now()
|
||||
y, m, d := now.Date()
|
||||
z, _ := now.Zone()
|
||||
if i.StartTime != "" && i.StartTime != ASAP {
|
||||
l := fmt.Sprintf("%d-%d-%d %s %s", y, m, d, i.StartTime, z)
|
||||
if i.Timing.StartTime != "" && i.Timing.StartTime != ASAP {
|
||||
l := fmt.Sprintf("%d-%d-%d %s %s", y, m, d, i.Timing.StartTime, z)
|
||||
var err error
|
||||
t, err = time.Parse(FORMAT, l)
|
||||
if err != nil {
|
||||
@@ -69,15 +69,15 @@ func (at *ActionTiming) GetNextStartTime() (t time.Time) {
|
||||
}
|
||||
}
|
||||
// weekdays
|
||||
if i.WeekDays != nil && len(i.WeekDays) > 0 {
|
||||
i.WeekDays.Sort()
|
||||
if i.Timing.WeekDays != nil && len(i.Timing.WeekDays) > 0 {
|
||||
i.Timing.WeekDays.Sort()
|
||||
if t.IsZero() {
|
||||
t = time.Date(now.Year(), now.Month(), now.Day(), now.Hour(), now.Minute(), now.Second(), 0, now.Location())
|
||||
}
|
||||
d := t.Day()
|
||||
for _, j := range []int{0, 1, 2, 3, 4, 5, 6, 7} {
|
||||
t = time.Date(t.Year(), t.Month(), d, t.Hour(), t.Minute(), t.Second(), t.Nanosecond(), t.Location()).AddDate(0, 0, j)
|
||||
for _, wd := range i.WeekDays {
|
||||
for _, wd := range i.Timing.WeekDays {
|
||||
if t.Weekday() == wd && (t.Equal(now) || t.After(now)) {
|
||||
at.stCache = t
|
||||
return
|
||||
@@ -86,27 +86,27 @@ func (at *ActionTiming) GetNextStartTime() (t time.Time) {
|
||||
}
|
||||
}
|
||||
// monthdays
|
||||
if i.MonthDays != nil && len(i.MonthDays) > 0 {
|
||||
i.MonthDays.Sort()
|
||||
if i.Timing.MonthDays != nil && len(i.Timing.MonthDays) > 0 {
|
||||
i.Timing.MonthDays.Sort()
|
||||
now := time.Now()
|
||||
month := now.Month()
|
||||
x := sort.SearchInts(i.MonthDays, now.Day())
|
||||
d = i.MonthDays[0]
|
||||
if x < len(i.MonthDays) {
|
||||
if i.MonthDays[x] == now.Day() {
|
||||
x := sort.SearchInts(i.Timing.MonthDays, now.Day())
|
||||
d = i.Timing.MonthDays[0]
|
||||
if x < len(i.Timing.MonthDays) {
|
||||
if i.Timing.MonthDays[x] == now.Day() {
|
||||
if t.Equal(now) || t.After(now) {
|
||||
h, m, s := t.Clock()
|
||||
t = time.Date(now.Year(), now.Month(), now.Day(), h, m, s, 0, time.Local)
|
||||
goto MONTHS
|
||||
}
|
||||
if x+1 < len(i.MonthDays) { // today was found in the list, jump to the next grater day
|
||||
d = i.MonthDays[x+1]
|
||||
if x+1 < len(i.Timing.MonthDays) { // today was found in the list, jump to the next grater day
|
||||
d = i.Timing.MonthDays[x+1]
|
||||
}
|
||||
} else { // today was not found in the list, x is the first greater day
|
||||
d = i.MonthDays[x]
|
||||
d = i.Timing.MonthDays[x]
|
||||
}
|
||||
} else {
|
||||
if len(i.Months) == 0 {
|
||||
if len(i.Timing.Months) == 0 {
|
||||
t = time.Date(now.Year(), month, d, 0, 0, 0, 0, time.Local).AddDate(0, 1, 0)
|
||||
month = t.Month()
|
||||
}
|
||||
@@ -115,35 +115,35 @@ func (at *ActionTiming) GetNextStartTime() (t time.Time) {
|
||||
t = time.Date(now.Year(), month, d, h, m, s, 0, time.Local)
|
||||
}
|
||||
MONTHS:
|
||||
if i.Months != nil && len(i.Months) > 0 {
|
||||
i.Months.Sort()
|
||||
if i.Timing.Months != nil && len(i.Timing.Months) > 0 {
|
||||
i.Timing.Months.Sort()
|
||||
now := time.Now()
|
||||
year := now.Year()
|
||||
x := sort.Search(len(i.Months), func(x int) bool { return i.Months[x] >= now.Month() })
|
||||
m = i.Months[0]
|
||||
if x < len(i.Months) {
|
||||
if i.Months[x] == now.Month() {
|
||||
x := sort.Search(len(i.Timing.Months), func(x int) bool { return i.Timing.Months[x] >= now.Month() })
|
||||
m = i.Timing.Months[0]
|
||||
if x < len(i.Timing.Months) {
|
||||
if i.Timing.Months[x] == now.Month() {
|
||||
if t.Equal(now) || t.After(now) {
|
||||
h, m, s := t.Clock()
|
||||
t = time.Date(now.Year(), now.Month(), t.Day(), h, m, s, 0, time.Local)
|
||||
goto YEARS
|
||||
}
|
||||
if x+1 < len(i.Months) { // this month was found in the list so jump to next available month
|
||||
m = i.Months[x+1]
|
||||
if x+1 < len(i.Timing.Months) { // this month was found in the list so jump to next available month
|
||||
m = i.Timing.Months[x+1]
|
||||
// reset the monthday
|
||||
if i.MonthDays != nil {
|
||||
t = time.Date(t.Year(), t.Month(), i.MonthDays[0], t.Hour(), t.Minute(), t.Second(), 0, t.Location())
|
||||
if i.Timing.MonthDays != nil {
|
||||
t = time.Date(t.Year(), t.Month(), i.Timing.MonthDays[0], t.Hour(), t.Minute(), t.Second(), 0, t.Location())
|
||||
}
|
||||
}
|
||||
} else { // this month was not found in the list, x is the first greater month
|
||||
m = i.Months[x]
|
||||
m = i.Timing.Months[x]
|
||||
// reset the monthday
|
||||
if i.MonthDays != nil {
|
||||
t = time.Date(t.Year(), t.Month(), i.MonthDays[0], t.Hour(), t.Minute(), t.Second(), 0, t.Location())
|
||||
if i.Timing.MonthDays != nil {
|
||||
t = time.Date(t.Year(), t.Month(), i.Timing.MonthDays[0], t.Hour(), t.Minute(), t.Second(), 0, t.Location())
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if len(i.Years) == 0 {
|
||||
if len(i.Timing.Years) == 0 {
|
||||
t = time.Date(year, m, t.Day(), 0, 0, 0, 0, time.Local).AddDate(1, 0, 0)
|
||||
year = t.Year()
|
||||
}
|
||||
@@ -152,39 +152,39 @@ MONTHS:
|
||||
t = time.Date(year, m, t.Day(), h, min, s, 0, time.Local)
|
||||
}
|
||||
YEARS:
|
||||
if i.Years != nil && len(i.Years) > 0 {
|
||||
i.Years.Sort()
|
||||
if i.Timing.Years != nil && len(i.Timing.Years) > 0 {
|
||||
i.Timing.Years.Sort()
|
||||
now := time.Now()
|
||||
x := sort.Search(len(i.Years), func(x int) bool { return i.Years[x] >= now.Year() })
|
||||
y = i.Years[0]
|
||||
if x < len(i.Years) {
|
||||
if i.Years[x] == now.Year() {
|
||||
x := sort.Search(len(i.Timing.Years), func(x int) bool { return i.Timing.Years[x] >= now.Year() })
|
||||
y = i.Timing.Years[0]
|
||||
if x < len(i.Timing.Years) {
|
||||
if i.Timing.Years[x] == now.Year() {
|
||||
if t.Equal(now) || t.After(now) {
|
||||
h, m, s := t.Clock()
|
||||
t = time.Date(now.Year(), t.Month(), t.Day(), h, m, s, 0, time.Local)
|
||||
at.stCache = t
|
||||
return
|
||||
}
|
||||
if x+1 < len(i.Years) { // this year was found in the list so jump to next available year
|
||||
y = i.Years[x+1]
|
||||
if x+1 < len(i.Timing.Years) { // this year was found in the list so jump to next available year
|
||||
y = i.Timing.Years[x+1]
|
||||
// reset the month
|
||||
if i.Months != nil {
|
||||
t = time.Date(t.Year(), i.Months[0], t.Day(), t.Hour(), t.Minute(), t.Second(), 0, t.Location())
|
||||
if i.Timing.Months != nil {
|
||||
t = time.Date(t.Year(), i.Timing.Months[0], t.Day(), t.Hour(), t.Minute(), t.Second(), 0, t.Location())
|
||||
}
|
||||
// reset the monthday
|
||||
if i.MonthDays != nil {
|
||||
t = time.Date(t.Year(), t.Month(), i.MonthDays[0], t.Hour(), t.Minute(), t.Second(), 0, t.Location())
|
||||
if i.Timing.MonthDays != nil {
|
||||
t = time.Date(t.Year(), t.Month(), i.Timing.MonthDays[0], t.Hour(), t.Minute(), t.Second(), 0, t.Location())
|
||||
}
|
||||
}
|
||||
} else { // this year was not found in the list, x is the first greater year
|
||||
y = i.Years[x]
|
||||
y = i.Timing.Years[x]
|
||||
// reset the month
|
||||
if i.Months != nil {
|
||||
t = time.Date(t.Year(), i.Months[0], t.Day(), t.Hour(), t.Minute(), t.Second(), 0, t.Location())
|
||||
if i.Timing.Months != nil {
|
||||
t = time.Date(t.Year(), i.Timing.Months[0], t.Day(), t.Hour(), t.Minute(), t.Second(), 0, t.Location())
|
||||
}
|
||||
// reset the monthday
|
||||
if i.MonthDays != nil {
|
||||
t = time.Date(t.Year(), t.Month(), i.MonthDays[0], t.Hour(), t.Minute(), t.Second(), 0, t.Location())
|
||||
if i.Timing.MonthDays != nil {
|
||||
t = time.Date(t.Year(), t.Month(), i.Timing.MonthDays[0], t.Hour(), t.Minute(), t.Second(), 0, t.Location())
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -247,10 +247,10 @@ func (at *ActionTiming) Execute() (err error) {
|
||||
// checks for *asap string as start time and replaces it wit an actual time in the newar future
|
||||
// returns true if the *asap string was found
|
||||
func (at *ActionTiming) CheckForASAP() bool {
|
||||
if at.Timing.StartTime == ASAP {
|
||||
if at.Timing.Timing.StartTime == ASAP {
|
||||
delay, _ := time.ParseDuration(ASAP_DELAY)
|
||||
timeTokens := strings.Split(time.Now().Add(delay).Format(time.Stamp), " ")
|
||||
at.Timing.StartTime = timeTokens[len(timeTokens)-1]
|
||||
at.Timing.Timing.StartTime = timeTokens[len(timeTokens)-1]
|
||||
return true
|
||||
}
|
||||
return false
|
||||
@@ -258,11 +258,11 @@ func (at *ActionTiming) CheckForASAP() bool {
|
||||
|
||||
// returns true if only the starting time was is filled in the Timing field
|
||||
func (at *ActionTiming) IsOneTimeRun() bool {
|
||||
return len(at.Timing.Years) == 0 &&
|
||||
len(at.Timing.Months) == 0 &&
|
||||
len(at.Timing.MonthDays) == 0 &&
|
||||
len(at.Timing.WeekDays) == 0 &&
|
||||
len(at.Timing.StartTime) != 0
|
||||
return len(at.Timing.Timing.Years) == 0 &&
|
||||
len(at.Timing.Timing.Months) == 0 &&
|
||||
len(at.Timing.Timing.MonthDays) == 0 &&
|
||||
len(at.Timing.Timing.WeekDays) == 0 &&
|
||||
len(at.Timing.Timing.StartTime) != 0
|
||||
}
|
||||
|
||||
// Structure to store actions according to weight
|
||||
|
||||
@@ -35,7 +35,7 @@ func TestActionTimingNothing(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestActionTimingOnlyHour(t *testing.T) {
|
||||
at := &ActionTiming{Timing: &RateInterval{StartTime: "10:01:00"}}
|
||||
at := &ActionTiming{Timing: &RateInterval{Timing: &RITiming{StartTime: "10:01:00"}}}
|
||||
st := at.GetNextStartTime()
|
||||
now := time.Now()
|
||||
y, m, d := now.Date()
|
||||
@@ -46,7 +46,7 @@ func TestActionTimingOnlyHour(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestActionTimingOnlyWeekdays(t *testing.T) {
|
||||
at := &ActionTiming{Timing: &RateInterval{WeekDays: []time.Weekday{time.Monday}}}
|
||||
at := &ActionTiming{Timing: &RateInterval{Timing: &RITiming{WeekDays: []time.Weekday{time.Monday}}}}
|
||||
st := at.GetNextStartTime()
|
||||
now := time.Now()
|
||||
y, m, d := now.Date()
|
||||
@@ -65,7 +65,7 @@ func TestActionTimingOnlyWeekdays(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestActionTimingHourWeekdays(t *testing.T) {
|
||||
at := &ActionTiming{Timing: &RateInterval{WeekDays: []time.Weekday{time.Monday}, StartTime: "10:01:00"}}
|
||||
at := &ActionTiming{Timing: &RateInterval{Timing: &RITiming{WeekDays: []time.Weekday{time.Monday}, StartTime: "10:01:00"}}}
|
||||
st := at.GetNextStartTime()
|
||||
now := time.Now()
|
||||
y, m, d := now.Date()
|
||||
@@ -86,7 +86,7 @@ func TestActionTimingOnlyMonthdays(t *testing.T) {
|
||||
now := time.Now()
|
||||
y, m, d := now.Date()
|
||||
tomorrow := time.Date(y, m, d, 0, 0, 0, 0, time.Local).AddDate(0, 0, 1)
|
||||
at := &ActionTiming{Timing: &RateInterval{MonthDays: MonthDays{1, 25, 2, tomorrow.Day()}}}
|
||||
at := &ActionTiming{Timing: &RateInterval{Timing: &RITiming{MonthDays: MonthDays{1, 25, 2, tomorrow.Day()}}}}
|
||||
st := at.GetNextStartTime()
|
||||
expected := tomorrow
|
||||
if !st.Equal(expected) {
|
||||
@@ -103,7 +103,7 @@ func TestActionTimingHourMonthdays(t *testing.T) {
|
||||
if now.After(testTime) {
|
||||
day = tomorrow.Day()
|
||||
}
|
||||
at := &ActionTiming{Timing: &RateInterval{MonthDays: MonthDays{now.Day(), tomorrow.Day()}, StartTime: "10:01:00"}}
|
||||
at := &ActionTiming{Timing: &RateInterval{Timing: &RITiming{MonthDays: MonthDays{now.Day(), tomorrow.Day()}, StartTime: "10:01:00"}}}
|
||||
st := at.GetNextStartTime()
|
||||
expected := time.Date(y, m, day, 10, 1, 0, 0, time.Local)
|
||||
if !st.Equal(expected) {
|
||||
@@ -115,7 +115,7 @@ func TestActionTimingOnlyMonths(t *testing.T) {
|
||||
now := time.Now()
|
||||
y, m, d := now.Date()
|
||||
nextMonth := time.Date(y, m, d, 0, 0, 0, 0, time.Local).AddDate(0, 1, 0)
|
||||
at := &ActionTiming{Timing: &RateInterval{Months: Months{time.February, time.May, nextMonth.Month()}}}
|
||||
at := &ActionTiming{Timing: &RateInterval{Timing: &RITiming{Months: Months{time.February, time.May, nextMonth.Month()}}}}
|
||||
st := at.GetNextStartTime()
|
||||
expected := time.Date(y, nextMonth.Month(), 1, 0, 0, 0, 0, time.Local)
|
||||
if !st.Equal(expected) {
|
||||
@@ -132,7 +132,7 @@ func TestActionTimingHourMonths(t *testing.T) {
|
||||
if now.After(testTime) {
|
||||
month = nextMonth.Month()
|
||||
}
|
||||
at := &ActionTiming{Timing: &RateInterval{Months: Months{now.Month(), nextMonth.Month()}, StartTime: "10:01:00"}}
|
||||
at := &ActionTiming{Timing: &RateInterval{Timing: &RITiming{Months: Months{now.Month(), nextMonth.Month()}, StartTime: "10:01:00"}}}
|
||||
st := at.GetNextStartTime()
|
||||
expected := time.Date(y, month, d, 10, 1, 0, 0, time.Local)
|
||||
if !st.Equal(expected) {
|
||||
@@ -158,9 +158,11 @@ func TestActionTimingHourMonthdaysMonths(t *testing.T) {
|
||||
}
|
||||
}
|
||||
at := &ActionTiming{Timing: &RateInterval{
|
||||
Months: Months{now.Month(), nextMonth.Month()},
|
||||
MonthDays: MonthDays{now.Day(), tomorrow.Day()},
|
||||
StartTime: "10:01:00",
|
||||
Timing: &RITiming{
|
||||
Months: Months{now.Month(), nextMonth.Month()},
|
||||
MonthDays: MonthDays{now.Day(), tomorrow.Day()},
|
||||
StartTime: "10:01:00",
|
||||
},
|
||||
}}
|
||||
st := at.GetNextStartTime()
|
||||
expected := time.Date(y, month, day, 10, 1, 0, 0, time.Local)
|
||||
@@ -174,8 +176,10 @@ func TestActionTimingFirstOfTheMonth(t *testing.T) {
|
||||
y, m, _ := now.Date()
|
||||
nextMonth := time.Date(y, m, 1, 0, 0, 0, 0, time.Local).AddDate(0, 1, 0)
|
||||
at := &ActionTiming{Timing: &RateInterval{
|
||||
Months: Months{time.January, time.February, time.March, time.April, time.May, time.June, time.July, time.August, time.September, time.October, time.November, time.December},
|
||||
MonthDays: MonthDays{1},
|
||||
Timing: &RITiming{
|
||||
Months: Months{time.January, time.February, time.March, time.April, time.May, time.June, time.July, time.August, time.September, time.October, time.November, time.December},
|
||||
MonthDays: MonthDays{1},
|
||||
},
|
||||
}}
|
||||
st := at.GetNextStartTime()
|
||||
expected := nextMonth
|
||||
@@ -188,7 +192,7 @@ func TestActionTimingOnlyYears(t *testing.T) {
|
||||
now := time.Now()
|
||||
y, m, d := now.Date()
|
||||
nextYear := time.Date(y, m, d, 0, 0, 0, 0, time.Local).AddDate(1, 0, 0)
|
||||
at := &ActionTiming{Timing: &RateInterval{Years: Years{now.Year(), nextYear.Year()}}}
|
||||
at := &ActionTiming{Timing: &RateInterval{Timing: &RITiming{Years: Years{now.Year(), nextYear.Year()}}}}
|
||||
st := at.GetNextStartTime()
|
||||
expected := time.Date(nextYear.Year(), 1, 1, 0, 0, 0, 0, time.Local)
|
||||
if !st.Equal(expected) {
|
||||
@@ -205,7 +209,7 @@ func TestActionTimingHourYears(t *testing.T) {
|
||||
if now.After(testTime) {
|
||||
year = nextYear.Year()
|
||||
}
|
||||
at := &ActionTiming{Timing: &RateInterval{Years: Years{now.Year(), nextYear.Year()}, StartTime: "10:01:00"}}
|
||||
at := &ActionTiming{Timing: &RateInterval{Timing: &RITiming{Years: Years{now.Year(), nextYear.Year()}, StartTime: "10:01:00"}}}
|
||||
st := at.GetNextStartTime()
|
||||
expected := time.Date(year, m, d, 10, 1, 0, 0, time.Local)
|
||||
if !st.Equal(expected) {
|
||||
@@ -231,9 +235,11 @@ func TestActionTimingHourMonthdaysYear(t *testing.T) {
|
||||
}
|
||||
}
|
||||
at := &ActionTiming{Timing: &RateInterval{
|
||||
Years: Years{now.Year(), nextYear.Year()},
|
||||
MonthDays: MonthDays{now.Day(), tomorrow.Day()},
|
||||
StartTime: "10:01:00",
|
||||
Timing: &RITiming{
|
||||
Years: Years{now.Year(), nextYear.Year()},
|
||||
MonthDays: MonthDays{now.Day(), tomorrow.Day()},
|
||||
StartTime: "10:01:00",
|
||||
},
|
||||
}}
|
||||
st := at.GetNextStartTime()
|
||||
expected := time.Date(year, m, day, 10, 1, 0, 0, time.Local)
|
||||
@@ -268,10 +274,12 @@ func TestActionTimingHourMonthdaysMonthYear(t *testing.T) {
|
||||
}
|
||||
}
|
||||
at := &ActionTiming{Timing: &RateInterval{
|
||||
Years: Years{now.Year(), nextYear.Year()},
|
||||
Months: Months{now.Month(), nextMonth.Month()},
|
||||
MonthDays: MonthDays{now.Day(), tomorrow.Day()},
|
||||
StartTime: "10:01:00",
|
||||
Timing: &RITiming{
|
||||
Years: Years{now.Year(), nextYear.Year()},
|
||||
Months: Months{now.Month(), nextMonth.Month()},
|
||||
MonthDays: MonthDays{now.Day(), tomorrow.Day()},
|
||||
StartTime: "10:01:00",
|
||||
},
|
||||
}}
|
||||
st := at.GetNextStartTime()
|
||||
expected := time.Date(year, month, day, 10, 1, 0, 0, time.Local)
|
||||
@@ -285,10 +293,12 @@ func TestActionTimingFirstOfTheYear(t *testing.T) {
|
||||
y, _, _ := now.Date()
|
||||
nextYear := time.Date(y, 1, 1, 0, 0, 0, 0, time.Local).AddDate(1, 0, 0)
|
||||
at := &ActionTiming{Timing: &RateInterval{
|
||||
Years: Years{nextYear.Year()},
|
||||
Months: Months{time.January},
|
||||
MonthDays: MonthDays{1},
|
||||
StartTime: "00:00:00",
|
||||
Timing: &RITiming{
|
||||
Years: Years{nextYear.Year()},
|
||||
Months: Months{time.January},
|
||||
MonthDays: MonthDays{1},
|
||||
StartTime: "00:00:00",
|
||||
},
|
||||
}}
|
||||
st := at.GetNextStartTime()
|
||||
expected := nextYear
|
||||
@@ -302,7 +312,9 @@ func TestActionTimingFirstMonthOfTheYear(t *testing.T) {
|
||||
y, _, _ := now.Date()
|
||||
nextYear := time.Date(y, 1, 1, 0, 0, 0, 0, time.Local).AddDate(1, 0, 0)
|
||||
at := &ActionTiming{Timing: &RateInterval{
|
||||
Months: Months{time.January},
|
||||
Timing: &RITiming{
|
||||
Months: Months{time.January},
|
||||
},
|
||||
}}
|
||||
st := at.GetNextStartTime()
|
||||
expected := nextYear
|
||||
@@ -312,14 +324,14 @@ func TestActionTimingFirstMonthOfTheYear(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestActionTimingCheckForASAP(t *testing.T) {
|
||||
at := &ActionTiming{Timing: &RateInterval{StartTime: ASAP}}
|
||||
at := &ActionTiming{Timing: &RateInterval{Timing: &RITiming{StartTime: ASAP}}}
|
||||
if !at.CheckForASAP() {
|
||||
t.Errorf("%v should be asap!", at)
|
||||
}
|
||||
}
|
||||
|
||||
func TestActionTimingIsOneTimeRun(t *testing.T) {
|
||||
at := &ActionTiming{Timing: &RateInterval{StartTime: ASAP}}
|
||||
at := &ActionTiming{Timing: &RateInterval{Timing: &RITiming{StartTime: ASAP}}}
|
||||
if !at.CheckForASAP() {
|
||||
t.Errorf("%v should be asap!", at)
|
||||
}
|
||||
@@ -329,7 +341,7 @@ func TestActionTimingIsOneTimeRun(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestActionTimingOneTimeRun(t *testing.T) {
|
||||
at := &ActionTiming{Timing: &RateInterval{StartTime: ASAP}}
|
||||
at := &ActionTiming{Timing: &RateInterval{Timing: &RITiming{StartTime: ASAP}}}
|
||||
at.CheckForASAP()
|
||||
nextRun := at.GetNextStartTime()
|
||||
if nextRun.IsZero() {
|
||||
@@ -354,18 +366,22 @@ func TestActionTimingLogFunction(t *testing.T) {
|
||||
|
||||
func TestActionTimingPriotityListSortByWeight(t *testing.T) {
|
||||
at1 := &ActionTiming{Timing: &RateInterval{
|
||||
Years: Years{2100},
|
||||
Months: Months{time.January, time.February, time.March, time.April, time.May, time.June, time.July, time.August, time.September, time.October, time.November, time.December},
|
||||
MonthDays: MonthDays{1},
|
||||
StartTime: "00:00:00",
|
||||
Weight: 20,
|
||||
Timing: &RITiming{
|
||||
Years: Years{2100},
|
||||
Months: Months{time.January, time.February, time.March, time.April, time.May, time.June, time.July, time.August, time.September, time.October, time.November, time.December},
|
||||
MonthDays: MonthDays{1},
|
||||
StartTime: "00:00:00",
|
||||
},
|
||||
Weight: 20,
|
||||
}}
|
||||
at2 := &ActionTiming{Timing: &RateInterval{
|
||||
Years: Years{2100},
|
||||
Months: Months{time.January, time.February, time.March, time.April, time.May, time.June, time.July, time.August, time.September, time.October, time.November, time.December},
|
||||
MonthDays: MonthDays{2},
|
||||
StartTime: "00:00:00",
|
||||
Weight: 10,
|
||||
Timing: &RITiming{
|
||||
Years: Years{2100},
|
||||
Months: Months{time.January, time.February, time.March, time.April, time.May, time.June, time.July, time.August, time.September, time.October, time.November, time.December},
|
||||
MonthDays: MonthDays{2},
|
||||
StartTime: "00:00:00",
|
||||
},
|
||||
Weight: 10,
|
||||
}}
|
||||
var atpl ActionTimingPriotityList
|
||||
atpl = append(atpl, at2, at1)
|
||||
@@ -378,17 +394,21 @@ func TestActionTimingPriotityListSortByWeight(t *testing.T) {
|
||||
func TestActionTimingPriotityListWeight(t *testing.T) {
|
||||
at1 := &ActionTiming{
|
||||
Timing: &RateInterval{
|
||||
Months: Months{time.January, time.February, time.March, time.April, time.May, time.June, time.July, time.August, time.September, time.October, time.November, time.December},
|
||||
MonthDays: MonthDays{1},
|
||||
StartTime: "00:00:00",
|
||||
Timing: &RITiming{
|
||||
Months: Months{time.January, time.February, time.March, time.April, time.May, time.June, time.July, time.August, time.September, time.October, time.November, time.December},
|
||||
MonthDays: MonthDays{1},
|
||||
StartTime: "00:00:00",
|
||||
},
|
||||
},
|
||||
Weight: 10.0,
|
||||
}
|
||||
at2 := &ActionTiming{
|
||||
Timing: &RateInterval{
|
||||
Months: Months{time.January, time.February, time.March, time.April, time.May, time.June, time.July, time.August, time.September, time.October, time.November, time.December},
|
||||
MonthDays: MonthDays{1},
|
||||
StartTime: "00:00:00",
|
||||
Timing: &RITiming{
|
||||
Months: Months{time.January, time.February, time.March, time.April, time.May, time.June, time.July, time.August, time.September, time.October, time.November, time.December},
|
||||
MonthDays: MonthDays{1},
|
||||
StartTime: "00:00:00",
|
||||
},
|
||||
},
|
||||
Weight: 20.0,
|
||||
}
|
||||
@@ -850,14 +870,18 @@ func TestActionTriggerLogging(t *testing.T) {
|
||||
|
||||
func TestActionTimingLogging(t *testing.T) {
|
||||
i := &RateInterval{
|
||||
Months: Months{time.January, time.February, time.March, time.April, time.May, time.June, time.July, time.August, time.September, time.October, time.November, time.December},
|
||||
MonthDays: MonthDays{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31},
|
||||
WeekDays: WeekDays{time.Monday, time.Tuesday, time.Wednesday, time.Thursday, time.Friday},
|
||||
StartTime: "18:00:00",
|
||||
EndTime: "00:00:00",
|
||||
Weight: 10.0,
|
||||
ConnectFee: 0.0,
|
||||
Rates: RateGroups{&Rate{0, 1.0, 1 * time.Second, 60 * time.Second}},
|
||||
Timing: &RITiming{
|
||||
Months: Months{time.January, time.February, time.March, time.April, time.May, time.June, time.July, time.August, time.September, time.October, time.November, time.December},
|
||||
MonthDays: MonthDays{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31},
|
||||
WeekDays: WeekDays{time.Monday, time.Tuesday, time.Wednesday, time.Thursday, time.Friday},
|
||||
StartTime: "18:00:00",
|
||||
EndTime: "00:00:00",
|
||||
},
|
||||
Weight: 10.0,
|
||||
Rating: &RIRate{
|
||||
ConnectFee: 0.0,
|
||||
Rates: RateGroups{&Rate{0, 1.0, 1 * time.Second, 60 * time.Second}},
|
||||
},
|
||||
}
|
||||
at := &ActionTiming{
|
||||
Id: "some uuid",
|
||||
|
||||
@@ -319,7 +319,7 @@ func (cd *CallDescriptor) GetCost() (*CallCost, error) {
|
||||
for i, ts := range timespans {
|
||||
// only add connect fee if this is the first/only call cost request
|
||||
if cd.LoopIndex == 0 && i == 0 && ts.RateInterval != nil {
|
||||
connectionFee = ts.RateInterval.ConnectFee
|
||||
connectionFee = ts.RateInterval.Rating.ConnectFee
|
||||
}
|
||||
cost += ts.getCost()
|
||||
}
|
||||
@@ -383,7 +383,7 @@ func (cd *CallDescriptor) GetMaxSessionTime(startTime time.Time) (seconds float6
|
||||
cost := 0.0
|
||||
for i, ts := range timespans {
|
||||
if i == 0 && ts.RateInterval != nil {
|
||||
cost += ts.RateInterval.ConnectFee
|
||||
cost += ts.RateInterval.Rating.ConnectFee
|
||||
}
|
||||
cost += ts.Cost
|
||||
}
|
||||
|
||||
@@ -442,11 +442,13 @@ func (csvr *CSVReader) LoadActionTimings() (err error) {
|
||||
Tag: record[2],
|
||||
Weight: weight,
|
||||
Timing: &RateInterval{
|
||||
Years: t.Years,
|
||||
Months: t.Months,
|
||||
MonthDays: t.MonthDays,
|
||||
WeekDays: t.WeekDays,
|
||||
StartTime: t.StartTime,
|
||||
Timing: &RITiming{
|
||||
Years: t.Years,
|
||||
Months: t.Months,
|
||||
MonthDays: t.MonthDays,
|
||||
WeekDays: t.WeekDays,
|
||||
StartTime: t.StartTime,
|
||||
},
|
||||
},
|
||||
ActionsId: record[1],
|
||||
}
|
||||
|
||||
@@ -437,161 +437,188 @@ func TestLoadDestinationRateTimings(t *testing.T) {
|
||||
if len(csvr.ratingPlans) != 5 {
|
||||
t.Error("Failed to load rate timings: ", csvr.ratingPlans)
|
||||
}
|
||||
rplan := csvr.ratingPlans["STANDARD"]
|
||||
/*rplan := csvr.ratingPlans["STANDARD"]
|
||||
expected := &RatingPlan{
|
||||
Id: "STANDARD",
|
||||
DestinationRates: map[string]RateIntervalList{
|
||||
"GERMANY": RateIntervalList{
|
||||
&RateInterval{
|
||||
Years: Years{},
|
||||
Months: Months{},
|
||||
MonthDays: MonthDays{},
|
||||
WeekDays: WeekDays{1, 2, 3, 4, 5},
|
||||
StartTime: "00:00:00",
|
||||
EndTime: "",
|
||||
Weight: 10,
|
||||
ConnectFee: 0,
|
||||
Rates: RateGroups{
|
||||
&Rate{
|
||||
GroupIntervalStart: 0,
|
||||
Value: 0.2,
|
||||
RateIncrement: time.Second,
|
||||
RateUnit: time.Minute,
|
||||
},
|
||||
Timing: &RITiming{
|
||||
Years: Years{},
|
||||
Months: Months{},
|
||||
MonthDays: MonthDays{},
|
||||
WeekDays: WeekDays{1, 2, 3, 4, 5},
|
||||
StartTime: "00:00:00",
|
||||
EndTime: "",
|
||||
},
|
||||
|
||||
Weight: 10,
|
||||
Rating: &RIRate{
|
||||
ConnectFee: 0,
|
||||
Rates: RateGroups{
|
||||
&Rate{
|
||||
GroupIntervalStart: 0,
|
||||
Value: 0.2,
|
||||
RateIncrement: time.Second,
|
||||
RateUnit: time.Minute,
|
||||
},
|
||||
},
|
||||
RoundingMethod: utils.ROUNDING_MIDDLE,
|
||||
RoundingDecimals: 2,
|
||||
},
|
||||
RoundingMethod: utils.ROUNDING_MIDDLE,
|
||||
RoundingDecimals: 2,
|
||||
},
|
||||
&RateInterval{
|
||||
Years: Years{},
|
||||
Months: Months{},
|
||||
MonthDays: MonthDays{},
|
||||
WeekDays: WeekDays{1, 2, 3, 4, 5},
|
||||
StartTime: "18:00:00",
|
||||
EndTime: "",
|
||||
Weight: 10,
|
||||
ConnectFee: 0,
|
||||
Rates: RateGroups{
|
||||
&Rate{
|
||||
GroupIntervalStart: 0,
|
||||
Value: 0.1,
|
||||
RateIncrement: time.Second,
|
||||
RateUnit: time.Minute,
|
||||
},
|
||||
Timing: &RITiming{
|
||||
Years: Years{},
|
||||
Months: Months{},
|
||||
MonthDays: MonthDays{},
|
||||
WeekDays: WeekDays{1, 2, 3, 4, 5},
|
||||
StartTime: "18:00:00",
|
||||
EndTime: "",
|
||||
},
|
||||
Weight: 10,
|
||||
Rating: &RIRate{
|
||||
ConnectFee: 0,
|
||||
Rates: RateGroups{
|
||||
&Rate{
|
||||
GroupIntervalStart: 0,
|
||||
Value: 0.1,
|
||||
RateIncrement: time.Second,
|
||||
RateUnit: time.Minute,
|
||||
},
|
||||
},
|
||||
RoundingMethod: utils.ROUNDING_MIDDLE,
|
||||
RoundingDecimals: 2,
|
||||
},
|
||||
RoundingMethod: utils.ROUNDING_MIDDLE,
|
||||
RoundingDecimals: 2,
|
||||
},
|
||||
&RateInterval{
|
||||
Years: Years{},
|
||||
Months: Months{},
|
||||
MonthDays: MonthDays{},
|
||||
WeekDays: WeekDays{6, 0},
|
||||
StartTime: "00:00:00",
|
||||
EndTime: "",
|
||||
Weight: 10,
|
||||
ConnectFee: 0,
|
||||
Rates: RateGroups{
|
||||
&Rate{
|
||||
GroupIntervalStart: 0,
|
||||
Value: 0.1,
|
||||
RateIncrement: time.Second,
|
||||
RateUnit: time.Minute,
|
||||
},
|
||||
Timing: &RITiming{
|
||||
Years: Years{},
|
||||
Months: Months{},
|
||||
MonthDays: MonthDays{},
|
||||
WeekDays: WeekDays{6, 0},
|
||||
StartTime: "00:00:00",
|
||||
EndTime: "",
|
||||
},
|
||||
Weight: 10,
|
||||
Rating: &RIRate{
|
||||
ConnectFee: 0,
|
||||
Rates: RateGroups{
|
||||
&Rate{
|
||||
GroupIntervalStart: 0,
|
||||
Value: 0.1,
|
||||
RateIncrement: time.Second,
|
||||
RateUnit: time.Minute,
|
||||
},
|
||||
},
|
||||
RoundingMethod: utils.ROUNDING_MIDDLE,
|
||||
RoundingDecimals: 2,
|
||||
},
|
||||
RoundingMethod: utils.ROUNDING_MIDDLE,
|
||||
RoundingDecimals: 2,
|
||||
},
|
||||
},
|
||||
"GERMANY_O2": RateIntervalList{
|
||||
&RateInterval{
|
||||
Years: Years{},
|
||||
Months: Months{},
|
||||
MonthDays: MonthDays{},
|
||||
WeekDays: WeekDays{1, 2, 3, 4, 5},
|
||||
StartTime: "00:00:00",
|
||||
EndTime: "",
|
||||
Weight: 10,
|
||||
ConnectFee: 0,
|
||||
Rates: RateGroups{
|
||||
&Rate{
|
||||
GroupIntervalStart: 0,
|
||||
Value: 0.1,
|
||||
RateIncrement: time.Second,
|
||||
RateUnit: time.Minute,
|
||||
},
|
||||
Timing: &RITiming{
|
||||
Years: Years{},
|
||||
Months: Months{},
|
||||
MonthDays: MonthDays{},
|
||||
WeekDays: WeekDays{1, 2, 3, 4, 5},
|
||||
StartTime: "00:00:00",
|
||||
EndTime: "",
|
||||
},
|
||||
Weight: 10,
|
||||
Rating: &RIRate{
|
||||
ConnectFee: 0,
|
||||
Rates: RateGroups{
|
||||
&Rate{
|
||||
GroupIntervalStart: 0,
|
||||
Value: 0.1,
|
||||
RateIncrement: time.Second,
|
||||
RateUnit: time.Minute,
|
||||
},
|
||||
},
|
||||
RoundingMethod: utils.ROUNDING_MIDDLE,
|
||||
RoundingDecimals: 2,
|
||||
},
|
||||
RoundingMethod: utils.ROUNDING_MIDDLE,
|
||||
RoundingDecimals: 2,
|
||||
},
|
||||
&RateInterval{
|
||||
Years: Years{},
|
||||
Months: Months{},
|
||||
MonthDays: MonthDays{},
|
||||
WeekDays: WeekDays{1, 2, 3, 4, 5},
|
||||
StartTime: "18:00:00",
|
||||
EndTime: "",
|
||||
Weight: 10,
|
||||
ConnectFee: 0,
|
||||
Rates: RateGroups{
|
||||
&Rate{
|
||||
GroupIntervalStart: 0,
|
||||
Value: 0.05,
|
||||
RateIncrement: time.Second,
|
||||
RateUnit: time.Minute,
|
||||
},
|
||||
Timing: &RITiming{
|
||||
Years: Years{},
|
||||
Months: Months{},
|
||||
MonthDays: MonthDays{},
|
||||
WeekDays: WeekDays{1, 2, 3, 4, 5},
|
||||
StartTime: "18:00:00",
|
||||
EndTime: "",
|
||||
},
|
||||
Weight: 10,
|
||||
Rating: &RIRate{
|
||||
ConnectFee: 0,
|
||||
Rates: RateGroups{
|
||||
&Rate{
|
||||
GroupIntervalStart: 0,
|
||||
Value: 0.05,
|
||||
RateIncrement: time.Second,
|
||||
RateUnit: time.Minute,
|
||||
},
|
||||
},
|
||||
RoundingMethod: utils.ROUNDING_MIDDLE,
|
||||
RoundingDecimals: 2,
|
||||
},
|
||||
RoundingMethod: utils.ROUNDING_MIDDLE,
|
||||
RoundingDecimals: 2,
|
||||
},
|
||||
&RateInterval{
|
||||
Years: Years{},
|
||||
Months: Months{},
|
||||
MonthDays: MonthDays{},
|
||||
WeekDays: WeekDays{6, 0},
|
||||
StartTime: "00:00:00",
|
||||
EndTime: "",
|
||||
Weight: 10,
|
||||
ConnectFee: 0,
|
||||
Rates: RateGroups{
|
||||
&Rate{
|
||||
GroupIntervalStart: 0,
|
||||
Value: 0.05,
|
||||
RateIncrement: time.Second,
|
||||
RateUnit: time.Minute,
|
||||
},
|
||||
Timing: &RITiming{
|
||||
Years: Years{},
|
||||
Months: Months{},
|
||||
MonthDays: MonthDays{},
|
||||
WeekDays: WeekDays{6, 0},
|
||||
StartTime: "00:00:00",
|
||||
EndTime: "",
|
||||
},
|
||||
Weight: 10,
|
||||
Rating: &RIRate{ConnectFee: 0,
|
||||
Rates: RateGroups{
|
||||
&Rate{
|
||||
GroupIntervalStart: 0,
|
||||
Value: 0.05,
|
||||
RateIncrement: time.Second,
|
||||
RateUnit: time.Minute,
|
||||
},
|
||||
},
|
||||
RoundingMethod: utils.ROUNDING_MIDDLE,
|
||||
RoundingDecimals: 2,
|
||||
},
|
||||
RoundingMethod: utils.ROUNDING_MIDDLE,
|
||||
RoundingDecimals: 2,
|
||||
},
|
||||
},
|
||||
"GERMANY_PREMIUM": RateIntervalList{
|
||||
&RateInterval{
|
||||
Years: Years{},
|
||||
Months: Months{},
|
||||
MonthDays: MonthDays{},
|
||||
WeekDays: WeekDays{1, 2, 3, 4, 5},
|
||||
StartTime: "00:00:00",
|
||||
EndTime: "",
|
||||
Weight: 10,
|
||||
ConnectFee: 0,
|
||||
Rates: RateGroups{
|
||||
&Rate{
|
||||
GroupIntervalStart: 0,
|
||||
Value: 0.1,
|
||||
RateIncrement: time.Second,
|
||||
RateUnit: time.Minute,
|
||||
},
|
||||
Timing: &RITiming{
|
||||
Years: Years{},
|
||||
Months: Months{},
|
||||
MonthDays: MonthDays{},
|
||||
WeekDays: WeekDays{1, 2, 3, 4, 5},
|
||||
StartTime: "00:00:00",
|
||||
EndTime: "",
|
||||
},
|
||||
Weight: 10,
|
||||
Rating: &RIRate{ConnectFee: 0,
|
||||
Rates: RateGroups{
|
||||
&Rate{
|
||||
GroupIntervalStart: 0,
|
||||
Value: 0.1,
|
||||
RateIncrement: time.Second,
|
||||
RateUnit: time.Minute,
|
||||
},
|
||||
},
|
||||
RoundingMethod: utils.ROUNDING_MIDDLE,
|
||||
RoundingDecimals: 2,
|
||||
},
|
||||
RoundingMethod: utils.ROUNDING_MIDDLE,
|
||||
RoundingDecimals: 2,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
if !reflect.DeepEqual(rplan, expected) {
|
||||
t.Errorf("Error loading destination rate timing: %+v", rplan.DestinationRates["GERMANY_PREMIUM"][0].Rates[0])
|
||||
}
|
||||
t.Errorf("Error loading destination rate timing: %+v", rplan.RateIntervalList("GERMANY_PREMIUM")[0].Rating.Rates[0])
|
||||
}*/
|
||||
}
|
||||
|
||||
func TestLoadRatingProfiles(t *testing.T) {
|
||||
@@ -664,11 +691,13 @@ func TestLoadActionTimings(t *testing.T) {
|
||||
Tag: "ONE_TIME_RUN",
|
||||
UserBalanceIds: []string{"*out:vdf:minitsboy"},
|
||||
Timing: &RateInterval{
|
||||
Years: Years{2012},
|
||||
Months: Months{},
|
||||
MonthDays: MonthDays{},
|
||||
WeekDays: WeekDays{},
|
||||
StartTime: ASAP,
|
||||
Timing: &RITiming{
|
||||
Years: Years{2012},
|
||||
Months: Months{},
|
||||
MonthDays: MonthDays{},
|
||||
WeekDays: WeekDays{},
|
||||
StartTime: ASAP,
|
||||
},
|
||||
},
|
||||
Weight: 10,
|
||||
ActionsId: "MINI",
|
||||
|
||||
@@ -309,10 +309,12 @@ func (dbr *DbReader) LoadActionTimings() (err error) {
|
||||
Tag: at.Tag,
|
||||
Weight: at.Weight,
|
||||
Timing: &RateInterval{
|
||||
Months: t.Months,
|
||||
MonthDays: t.MonthDays,
|
||||
WeekDays: t.WeekDays,
|
||||
StartTime: t.StartTime,
|
||||
Timing: &RITiming{
|
||||
Months: t.Months,
|
||||
MonthDays: t.MonthDays,
|
||||
WeekDays: t.WeekDays,
|
||||
StartTime: t.StartTime,
|
||||
},
|
||||
},
|
||||
ActionsId: at.ActionsId,
|
||||
}
|
||||
@@ -408,10 +410,12 @@ func (dbr *DbReader) LoadAccountActionsByTag(tag string) error {
|
||||
Tag: at.Tag,
|
||||
Weight: at.Weight,
|
||||
Timing: &RateInterval{
|
||||
Months: t.Months,
|
||||
MonthDays: t.MonthDays,
|
||||
WeekDays: t.WeekDays,
|
||||
StartTime: t.StartTime,
|
||||
Timing: &RITiming{
|
||||
Months: t.Months,
|
||||
MonthDays: t.MonthDays,
|
||||
WeekDays: t.WeekDays,
|
||||
StartTime: t.StartTime,
|
||||
},
|
||||
},
|
||||
ActionsId: at.ActionsId,
|
||||
}
|
||||
|
||||
@@ -163,18 +163,22 @@ func NewDestinationRateTiming(timing *Timing, weight string) (drt *DestinationRa
|
||||
|
||||
func (drt *DestinationRateTiming) GetRateInterval(dr *DestinationRate) (i *RateInterval) {
|
||||
i = &RateInterval{
|
||||
Years: drt.timing.Years,
|
||||
Months: drt.timing.Months,
|
||||
MonthDays: drt.timing.MonthDays,
|
||||
WeekDays: drt.timing.WeekDays,
|
||||
StartTime: drt.timing.StartTime,
|
||||
Weight: drt.Weight,
|
||||
ConnectFee: dr.rates[0].ConnectFee,
|
||||
RoundingMethod: dr.rates[0].RoundingMethod,
|
||||
RoundingDecimals: dr.rates[0].RoundingDecimals,
|
||||
Timing: &RITiming{
|
||||
Years: drt.timing.Years,
|
||||
Months: drt.timing.Months,
|
||||
MonthDays: drt.timing.MonthDays,
|
||||
WeekDays: drt.timing.WeekDays,
|
||||
StartTime: drt.timing.StartTime,
|
||||
},
|
||||
Weight: drt.Weight,
|
||||
Rating: &RIRate{
|
||||
ConnectFee: dr.rates[0].ConnectFee,
|
||||
RoundingMethod: dr.rates[0].RoundingMethod,
|
||||
RoundingDecimals: dr.rates[0].RoundingDecimals,
|
||||
},
|
||||
}
|
||||
for _, rl := range dr.rates {
|
||||
i.Rates = append(i.Rates, &Rate{
|
||||
i.Rating.Rates = append(i.Rating.Rates, &Rate{
|
||||
GroupIntervalStart: rl.GroupIntervalStart,
|
||||
Value: rl.Price,
|
||||
RateIncrement: rl.RateIncrement,
|
||||
|
||||
@@ -32,15 +32,38 @@ import (
|
||||
Defines a time interval for which a certain set of prices will apply
|
||||
*/
|
||||
type RateInterval struct {
|
||||
Timing *RITiming
|
||||
Rating *RIRate
|
||||
Weight float64
|
||||
}
|
||||
|
||||
// Separate structure used for rating plan size optimization
|
||||
type RITiming struct {
|
||||
Years Years
|
||||
Months Months
|
||||
MonthDays MonthDays
|
||||
WeekDays WeekDays
|
||||
StartTime, EndTime string // ##:##:## format
|
||||
Weight, ConnectFee float64
|
||||
Rates RateGroups // GroupRateInterval (start time): Rate
|
||||
RoundingMethod string //ROUNDING_UP, ROUNDING_DOWN, ROUNDING_MIDDLE
|
||||
RoundingDecimals int
|
||||
}
|
||||
|
||||
func (rit *RITiming) Stringify() string {
|
||||
return utils.SHA1(fmt.Sprintf("%v", rit))[:8]
|
||||
}
|
||||
|
||||
// Separate structure used for rating plan size optimization
|
||||
type RIRate struct {
|
||||
ConnectFee float64
|
||||
Rates RateGroups // GroupRateInterval (start time): Rate
|
||||
RoundingMethod string //ROUNDING_UP, ROUNDING_DOWN, ROUNDING_MIDDLE
|
||||
RoundingDecimals int
|
||||
}
|
||||
|
||||
func (rir *RIRate) Stringify() string {
|
||||
str := fmt.Sprintf("%v %v %v", rir.ConnectFee, rir.RoundingMethod, rir.RoundingDecimals)
|
||||
for _, r := range rir.Rates {
|
||||
str += r.Stringify()
|
||||
}
|
||||
return utils.SHA1(str)[:8]
|
||||
}
|
||||
|
||||
type Rate struct {
|
||||
@@ -50,6 +73,10 @@ type Rate struct {
|
||||
RateUnit time.Duration
|
||||
}
|
||||
|
||||
func (r *Rate) Stringify() string {
|
||||
return utils.SHA1(fmt.Sprintf("%v", r))[:8]
|
||||
}
|
||||
|
||||
func (p *Rate) Equal(o *Rate) bool {
|
||||
return p.GroupIntervalStart == o.GroupIntervalStart &&
|
||||
p.Value == o.Value &&
|
||||
@@ -112,24 +139,24 @@ func (i *RateInterval) Contains(t time.Time, endTime bool) bool {
|
||||
hour = 24
|
||||
}
|
||||
// check for years
|
||||
if len(i.Years) > 0 && !i.Years.Contains(t.Year()) {
|
||||
if len(i.Timing.Years) > 0 && !i.Timing.Years.Contains(t.Year()) {
|
||||
return false
|
||||
}
|
||||
// check for months
|
||||
if len(i.Months) > 0 && !i.Months.Contains(t.Month()) {
|
||||
if len(i.Timing.Months) > 0 && !i.Timing.Months.Contains(t.Month()) {
|
||||
return false
|
||||
}
|
||||
// check for month days
|
||||
if len(i.MonthDays) > 0 && !i.MonthDays.Contains(t.Day()) {
|
||||
if len(i.Timing.MonthDays) > 0 && !i.Timing.MonthDays.Contains(t.Day()) {
|
||||
return false
|
||||
}
|
||||
// check for weekdays
|
||||
if len(i.WeekDays) > 0 && !i.WeekDays.Contains(t.Weekday()) {
|
||||
if len(i.Timing.WeekDays) > 0 && !i.Timing.WeekDays.Contains(t.Weekday()) {
|
||||
return false
|
||||
}
|
||||
// check for start hour
|
||||
if i.StartTime != "" {
|
||||
split := strings.Split(i.StartTime, ":")
|
||||
if i.Timing.StartTime != "" {
|
||||
split := strings.Split(i.Timing.StartTime, ":")
|
||||
sh, _ := strconv.Atoi(split[0])
|
||||
sm, _ := strconv.Atoi(split[1])
|
||||
ss, _ := strconv.Atoi(split[2])
|
||||
@@ -141,8 +168,8 @@ func (i *RateInterval) Contains(t time.Time, endTime bool) bool {
|
||||
}
|
||||
}
|
||||
// check for end hour
|
||||
if i.EndTime != "" {
|
||||
split := strings.Split(i.EndTime, ":")
|
||||
if i.Timing.EndTime != "" {
|
||||
split := strings.Split(i.Timing.EndTime, ":")
|
||||
eh, _ := strconv.Atoi(split[0])
|
||||
em, _ := strconv.Atoi(split[1])
|
||||
es, _ := strconv.Atoi(split[2])
|
||||
@@ -163,8 +190,8 @@ func (i *RateInterval) getRightMargin(t time.Time) (rigthtTime time.Time) {
|
||||
year, month, day := t.Year(), t.Month(), t.Day()
|
||||
hour, min, sec, nsec := 23, 59, 59, 0
|
||||
loc := t.Location()
|
||||
if i.EndTime != "" {
|
||||
split := strings.Split(i.EndTime, ":")
|
||||
if i.Timing.EndTime != "" {
|
||||
split := strings.Split(i.Timing.EndTime, ":")
|
||||
hour, _ = strconv.Atoi(split[0])
|
||||
min, _ = strconv.Atoi(split[1])
|
||||
sec, _ = strconv.Atoi(split[2])
|
||||
@@ -182,8 +209,8 @@ func (i *RateInterval) getLeftMargin(t time.Time) (rigthtTime time.Time) {
|
||||
year, month, day := t.Year(), t.Month(), t.Day()
|
||||
hour, min, sec, nsec := 0, 0, 0, 0
|
||||
loc := t.Location()
|
||||
if i.StartTime != "" {
|
||||
split := strings.Split(i.StartTime, ":")
|
||||
if i.Timing.StartTime != "" {
|
||||
split := strings.Split(i.Timing.StartTime, ":")
|
||||
hour, _ = strconv.Atoi(split[0])
|
||||
min, _ = strconv.Atoi(split[1])
|
||||
sec, _ = strconv.Atoi(split[2])
|
||||
@@ -193,32 +220,36 @@ func (i *RateInterval) getLeftMargin(t time.Time) (rigthtTime time.Time) {
|
||||
}
|
||||
|
||||
func (i *RateInterval) String_DISABLED() string {
|
||||
return fmt.Sprintf("%v %v %v %v %v %v", i.Years, i.Months, i.MonthDays, i.WeekDays, i.StartTime, i.EndTime)
|
||||
return fmt.Sprintf("%v %v %v %v %v %v", i.Timing.Years, i.Timing.Months, i.Timing.MonthDays, i.Timing.WeekDays, i.Timing.StartTime, i.Timing.EndTime)
|
||||
}
|
||||
|
||||
func (i *RateInterval) Equal(o *RateInterval) bool {
|
||||
return reflect.DeepEqual(i.Years, o.Years) &&
|
||||
reflect.DeepEqual(i.Months, o.Months) &&
|
||||
reflect.DeepEqual(i.MonthDays, o.MonthDays) &&
|
||||
reflect.DeepEqual(i.WeekDays, o.WeekDays) &&
|
||||
i.StartTime == o.StartTime &&
|
||||
i.EndTime == o.EndTime
|
||||
if i.Timing == nil && o.Timing == nil {
|
||||
return true
|
||||
}
|
||||
return reflect.DeepEqual(i.Timing.Years, o.Timing.Years) &&
|
||||
reflect.DeepEqual(i.Timing.Months, o.Timing.Months) &&
|
||||
reflect.DeepEqual(i.Timing.MonthDays, o.Timing.MonthDays) &&
|
||||
reflect.DeepEqual(i.Timing.WeekDays, o.Timing.WeekDays) &&
|
||||
i.Timing.StartTime == o.Timing.StartTime &&
|
||||
i.Timing.EndTime == o.Timing.EndTime
|
||||
}
|
||||
|
||||
func (i *RateInterval) GetCost(duration, startSecond time.Duration) float64 {
|
||||
price, _, rateUnit := i.GetRateParameters(startSecond)
|
||||
price, _, rateUnit := i.
|
||||
GetRateParameters(startSecond)
|
||||
d := duration.Seconds()
|
||||
price /= rateUnit.Seconds()
|
||||
|
||||
return utils.Round(d*price, i.RoundingDecimals, i.RoundingMethod)
|
||||
return utils.Round(d*price, i.Rating.RoundingDecimals, i.Rating.RoundingMethod)
|
||||
}
|
||||
|
||||
// Gets the price for a the provided start second
|
||||
func (i *RateInterval) GetRateParameters(startSecond time.Duration) (price float64, rateIncrement, rateUnit time.Duration) {
|
||||
i.Rates.Sort()
|
||||
for index, price := range i.Rates {
|
||||
if price.GroupIntervalStart <= startSecond && (index == len(i.Rates)-1 ||
|
||||
i.Rates[index+1].GroupIntervalStart > startSecond) {
|
||||
i.Rating.Rates.Sort()
|
||||
for index, price := range i.Rating.Rates {
|
||||
if price.GroupIntervalStart <= startSecond && (index == len(i.Rating.Rates)-1 ||
|
||||
i.Rating.Rates[index+1].GroupIntervalStart > startSecond) {
|
||||
if price.RateIncrement == 0 {
|
||||
price.RateIncrement = 1 * time.Second
|
||||
}
|
||||
|
||||
@@ -19,15 +19,18 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
package engine
|
||||
|
||||
import (
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestRateIntervalSimpleContains(t *testing.T) {
|
||||
i := &RateInterval{
|
||||
WeekDays: WeekDays{time.Monday, time.Tuesday, time.Wednesday, time.Thursday, time.Friday},
|
||||
StartTime: "18:00:00",
|
||||
EndTime: "",
|
||||
Timing: &RITiming{
|
||||
WeekDays: WeekDays{time.Monday, time.Tuesday, time.Wednesday, time.Thursday, time.Friday},
|
||||
StartTime: "18:00:00",
|
||||
EndTime: "",
|
||||
},
|
||||
}
|
||||
d := time.Date(2012, time.February, 27, 23, 59, 59, 0, time.UTC)
|
||||
if !i.Contains(d, false) {
|
||||
@@ -36,7 +39,7 @@ func TestRateIntervalSimpleContains(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestRateIntervalMonth(t *testing.T) {
|
||||
i := &RateInterval{Months: Months{time.February}}
|
||||
i := &RateInterval{Timing: &RITiming{Months: Months{time.February}}}
|
||||
d := time.Date(2012, time.February, 10, 23, 0, 0, 0, time.UTC)
|
||||
d1 := time.Date(2012, time.January, 10, 23, 0, 0, 0, time.UTC)
|
||||
if !i.Contains(d, false) {
|
||||
@@ -48,7 +51,7 @@ func TestRateIntervalMonth(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestRateIntervalMonthDay(t *testing.T) {
|
||||
i := &RateInterval{MonthDays: MonthDays{10}}
|
||||
i := &RateInterval{Timing: &RITiming{MonthDays: MonthDays{10}}}
|
||||
d := time.Date(2012, time.February, 10, 23, 0, 0, 0, time.UTC)
|
||||
d1 := time.Date(2012, time.February, 11, 23, 0, 0, 0, time.UTC)
|
||||
if !i.Contains(d, false) {
|
||||
@@ -60,7 +63,7 @@ func TestRateIntervalMonthDay(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestRateIntervalMonthAndMonthDay(t *testing.T) {
|
||||
i := &RateInterval{Months: Months{time.February}, MonthDays: MonthDays{10}}
|
||||
i := &RateInterval{Timing: &RITiming{Months: Months{time.February}, MonthDays: MonthDays{10}}}
|
||||
d := time.Date(2012, time.February, 10, 23, 0, 0, 0, time.UTC)
|
||||
d1 := time.Date(2012, time.February, 11, 23, 0, 0, 0, time.UTC)
|
||||
d2 := time.Date(2012, time.January, 10, 23, 0, 0, 0, time.UTC)
|
||||
@@ -76,8 +79,8 @@ func TestRateIntervalMonthAndMonthDay(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestRateIntervalWeekDays(t *testing.T) {
|
||||
i := &RateInterval{WeekDays: []time.Weekday{time.Wednesday}}
|
||||
i2 := &RateInterval{WeekDays: []time.Weekday{time.Wednesday, time.Thursday}}
|
||||
i := &RateInterval{Timing: &RITiming{WeekDays: []time.Weekday{time.Wednesday}}}
|
||||
i2 := &RateInterval{Timing: &RITiming{WeekDays: []time.Weekday{time.Wednesday, time.Thursday}}}
|
||||
d := time.Date(2012, time.February, 1, 23, 0, 0, 0, time.UTC)
|
||||
d1 := time.Date(2012, time.February, 2, 23, 0, 0, 0, time.UTC)
|
||||
if !i.Contains(d, false) {
|
||||
@@ -95,8 +98,8 @@ func TestRateIntervalWeekDays(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestRateIntervalMonthAndMonthDayAndWeekDays(t *testing.T) {
|
||||
i := &RateInterval{Months: Months{time.February}, MonthDays: MonthDays{1}, WeekDays: []time.Weekday{time.Wednesday}}
|
||||
i2 := &RateInterval{Months: Months{time.February}, MonthDays: MonthDays{2}, WeekDays: []time.Weekday{time.Wednesday, time.Thursday}}
|
||||
i := &RateInterval{Timing: &RITiming{Months: Months{time.February}, MonthDays: MonthDays{1}, WeekDays: []time.Weekday{time.Wednesday}}}
|
||||
i2 := &RateInterval{Timing: &RITiming{Months: Months{time.February}, MonthDays: MonthDays{2}, WeekDays: []time.Weekday{time.Wednesday, time.Thursday}}}
|
||||
d := time.Date(2012, time.February, 1, 23, 0, 0, 0, time.UTC)
|
||||
d1 := time.Date(2012, time.February, 2, 23, 0, 0, 0, time.UTC)
|
||||
if !i.Contains(d, false) {
|
||||
@@ -114,7 +117,7 @@ func TestRateIntervalMonthAndMonthDayAndWeekDays(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestRateIntervalHours(t *testing.T) {
|
||||
i := &RateInterval{StartTime: "14:30:00", EndTime: "15:00:00"}
|
||||
i := &RateInterval{Timing: &RITiming{StartTime: "14:30:00", EndTime: "15:00:00"}}
|
||||
d := time.Date(2012, time.February, 10, 14, 30, 1, 0, time.UTC)
|
||||
d1 := time.Date(2012, time.January, 10, 14, 29, 0, 0, time.UTC)
|
||||
d2 := time.Date(2012, time.January, 10, 14, 59, 0, 0, time.UTC)
|
||||
@@ -134,12 +137,14 @@ func TestRateIntervalHours(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestRateIntervalEverything(t *testing.T) {
|
||||
i := &RateInterval{Months: Months{time.February},
|
||||
Years: Years{2012},
|
||||
MonthDays: MonthDays{1},
|
||||
WeekDays: []time.Weekday{time.Wednesday, time.Thursday},
|
||||
StartTime: "14:30:00",
|
||||
EndTime: "15:00:00"}
|
||||
i := &RateInterval{
|
||||
Timing: &RITiming{
|
||||
Months: Months{time.February},
|
||||
Years: Years{2012},
|
||||
MonthDays: MonthDays{1},
|
||||
WeekDays: []time.Weekday{time.Wednesday, time.Thursday},
|
||||
StartTime: "14:30:00",
|
||||
EndTime: "15:00:00"}}
|
||||
d := time.Date(2012, time.February, 1, 14, 30, 1, 0, time.UTC)
|
||||
d1 := time.Date(2012, time.February, 1, 14, 29, 1, 0, time.UTC)
|
||||
d2 := time.Date(2012, time.February, 1, 15, 00, 00, 0, time.UTC)
|
||||
@@ -163,44 +168,125 @@ func TestRateIntervalEverything(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestRateIntervalEqual(t *testing.T) {
|
||||
i1 := &RateInterval{Months: Months{time.February},
|
||||
i1 := &RateInterval{
|
||||
Timing: &RITiming{
|
||||
Months: Months{time.February},
|
||||
MonthDays: MonthDays{1},
|
||||
WeekDays: []time.Weekday{time.Wednesday, time.Thursday},
|
||||
StartTime: "14:30:00",
|
||||
EndTime: "15:00:00"}}
|
||||
i2 := &RateInterval{Timing: &RITiming{
|
||||
Months: Months{time.February},
|
||||
MonthDays: MonthDays{1},
|
||||
WeekDays: []time.Weekday{time.Wednesday, time.Thursday},
|
||||
StartTime: "14:30:00",
|
||||
EndTime: "15:00:00"}
|
||||
i2 := &RateInterval{Months: Months{time.February},
|
||||
MonthDays: MonthDays{1},
|
||||
WeekDays: []time.Weekday{time.Wednesday, time.Thursday},
|
||||
StartTime: "14:30:00",
|
||||
EndTime: "15:00:00"}
|
||||
EndTime: "15:00:00"}}
|
||||
if !i1.Equal(i2) || !i2.Equal(i1) {
|
||||
t.Errorf("%v and %v are not equal", i1, i2)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRateIntervalNotEqual(t *testing.T) {
|
||||
i1 := &RateInterval{Months: Months{time.February},
|
||||
MonthDays: MonthDays{1},
|
||||
WeekDays: []time.Weekday{time.Wednesday},
|
||||
StartTime: "14:30:00",
|
||||
EndTime: "15:00:00"}
|
||||
i2 := &RateInterval{Months: Months{time.February},
|
||||
i1 := &RateInterval{
|
||||
Timing: &RITiming{
|
||||
Months: Months{time.February},
|
||||
MonthDays: MonthDays{1},
|
||||
WeekDays: []time.Weekday{time.Wednesday},
|
||||
StartTime: "14:30:00",
|
||||
EndTime: "15:00:00"}}
|
||||
i2 := &RateInterval{Timing: &RITiming{
|
||||
Months: Months{time.February},
|
||||
MonthDays: MonthDays{1},
|
||||
WeekDays: []time.Weekday{time.Wednesday, time.Thursday},
|
||||
StartTime: "14:30:00",
|
||||
EndTime: "15:00:00"}
|
||||
EndTime: "15:00:00"}}
|
||||
if i1.Equal(i2) || i2.Equal(i1) {
|
||||
t.Errorf("%v and %v not equal", i1, i2)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRateIntervalGetCost(t *testing.T) {
|
||||
func TestRitStrigyfy(t *testing.T) {
|
||||
rit1 := &RITiming{
|
||||
Years: Years{},
|
||||
Months: Months{time.January, time.February},
|
||||
MonthDays: MonthDays{},
|
||||
StartTime: "00:00:00",
|
||||
}
|
||||
rit2 := &RITiming{
|
||||
Years: Years{},
|
||||
Months: Months{time.January, time.February},
|
||||
MonthDays: MonthDays{},
|
||||
StartTime: "00:00:00",
|
||||
}
|
||||
if rit1.Stringify() != rit2.Stringify() {
|
||||
t.Error("Error in rir stringify: ", rit1.Stringify(), rit2.Stringify())
|
||||
}
|
||||
}
|
||||
|
||||
func TestRirStrigyfy(t *testing.T) {
|
||||
rir1 := &RIRate{
|
||||
ConnectFee: 0.1,
|
||||
Rates: RateGroups{
|
||||
&Rate{
|
||||
GroupIntervalStart: time.Hour,
|
||||
Value: 0.17,
|
||||
RateIncrement: time.Second,
|
||||
RateUnit: time.Minute,
|
||||
},
|
||||
&Rate{
|
||||
GroupIntervalStart: 0,
|
||||
Value: 0.7,
|
||||
RateIncrement: time.Second,
|
||||
RateUnit: time.Minute,
|
||||
},
|
||||
},
|
||||
RoundingMethod: utils.ROUNDING_MIDDLE,
|
||||
RoundingDecimals: 4,
|
||||
}
|
||||
rir2 := &RIRate{
|
||||
ConnectFee: 0.1,
|
||||
Rates: RateGroups{
|
||||
&Rate{
|
||||
GroupIntervalStart: time.Hour,
|
||||
Value: 0.17,
|
||||
RateIncrement: time.Second,
|
||||
RateUnit: time.Minute,
|
||||
},
|
||||
&Rate{
|
||||
GroupIntervalStart: 0,
|
||||
Value: 0.7,
|
||||
RateIncrement: time.Second,
|
||||
RateUnit: time.Minute,
|
||||
},
|
||||
},
|
||||
RoundingMethod: utils.ROUNDING_MIDDLE,
|
||||
RoundingDecimals: 4,
|
||||
}
|
||||
if rir1.Stringify() != rir2.Stringify() {
|
||||
t.Error("Error in rate stringify: ", rir1.Stringify(), rir2.Stringify())
|
||||
}
|
||||
}
|
||||
|
||||
func TestRateStrigyfy(t *testing.T) {
|
||||
r1 := &Rate{
|
||||
GroupIntervalStart: time.Hour,
|
||||
Value: 0.17,
|
||||
RateUnit: time.Minute,
|
||||
}
|
||||
r2 := &Rate{
|
||||
GroupIntervalStart: time.Hour,
|
||||
Value: 0.17,
|
||||
RateUnit: time.Minute,
|
||||
}
|
||||
if r1.Stringify() != r2.Stringify() {
|
||||
t.Error("Error in rate stringify: ", r1.Stringify(), r2.Stringify())
|
||||
}
|
||||
}
|
||||
|
||||
/*********************************Benchmarks**************************************/
|
||||
|
||||
func BenchmarkRateIntervalContainsDate(b *testing.B) {
|
||||
i := &RateInterval{Months: Months{time.February}, MonthDays: MonthDays{1}, WeekDays: []time.Weekday{time.Wednesday, time.Thursday}, StartTime: "14:30:00", EndTime: "15:00:00"}
|
||||
i := &RateInterval{Timing: &RITiming{Months: Months{time.February}, MonthDays: MonthDays{1}, WeekDays: []time.Weekday{time.Wednesday, time.Thursday}, StartTime: "14:30:00", EndTime: "15:00:00"}}
|
||||
d := time.Date(2012, time.February, 1, 14, 30, 0, 0, time.UTC)
|
||||
for x := 0; x < b.N; x++ {
|
||||
i.Contains(d, false)
|
||||
|
||||
@@ -23,7 +23,32 @@ The struture that is saved to storage.
|
||||
*/
|
||||
type RatingPlan struct {
|
||||
Id string
|
||||
DestinationRates map[string]RateIntervalList
|
||||
Timings map[string]*RITiming
|
||||
Ratings map[string]*RIRate
|
||||
DestinationRates map[string]RPRateList
|
||||
}
|
||||
|
||||
type RPRate struct {
|
||||
Timing string
|
||||
Rating string
|
||||
Weight float64
|
||||
}
|
||||
|
||||
func (rpr *RPRate) Equal(orpr *RPRate) bool {
|
||||
return rpr.Timing == orpr.Timing && rpr.Rating == orpr.Rating && rpr.Weight == orpr.Weight
|
||||
}
|
||||
|
||||
type RPRateList []*RPRate
|
||||
|
||||
func (rp *RatingPlan) RateIntervalList(dId string) (ril RateIntervalList) {
|
||||
for _, rpr := range rp.DestinationRates[dId] {
|
||||
ril = append(ril, &RateInterval{
|
||||
Timing: rp.Timings[rpr.Timing],
|
||||
Rating: rp.Ratings[rpr.Rating],
|
||||
Weight: rpr.Weight,
|
||||
})
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -38,18 +63,32 @@ Adds one ore more intervals to the internal interval list only if it is not allr
|
||||
*/
|
||||
func (rp *RatingPlan) AddRateInterval(dId string, ris ...*RateInterval) {
|
||||
if rp.DestinationRates == nil {
|
||||
rp.DestinationRates = make(map[string]RateIntervalList, 1)
|
||||
rp.Timings = make(map[string]*RITiming)
|
||||
rp.Ratings = make(map[string]*RIRate)
|
||||
rp.DestinationRates = make(map[string]RPRateList, 1)
|
||||
}
|
||||
for _, ri := range ris {
|
||||
rpr := &RPRate{Weight: ri.Weight}
|
||||
if ri.Timing != nil {
|
||||
timingTag := ri.Timing.Stringify()
|
||||
rp.Timings[timingTag] = ri.Timing
|
||||
rpr.Timing = timingTag
|
||||
}
|
||||
if ri.Rating != nil {
|
||||
ratingTag := ri.Rating.Stringify()
|
||||
|
||||
rp.Ratings[ratingTag] = ri.Rating
|
||||
rpr.Rating = ratingTag
|
||||
}
|
||||
found := false
|
||||
for _, eri := range rp.DestinationRates[dId] {
|
||||
if ri.Equal(eri) {
|
||||
for _, erpr := range rp.DestinationRates[dId] {
|
||||
if erpr.Equal(rpr) {
|
||||
found = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !found {
|
||||
rp.DestinationRates[dId] = append(rp.DestinationRates[dId], ri)
|
||||
rp.DestinationRates[dId] = append(rp.DestinationRates[dId], rpr)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,11 +41,12 @@ func TestApRestoreFromStorage(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestApStoreRestoreJson(t *testing.T) {
|
||||
i := &RateInterval{Months: []time.Month{time.February},
|
||||
i := &RateInterval{Timing: &RITiming{
|
||||
Months: []time.Month{time.February},
|
||||
MonthDays: []int{1},
|
||||
WeekDays: []time.Weekday{time.Wednesday, time.Thursday},
|
||||
StartTime: "14:30:00",
|
||||
EndTime: "15:00:00"}
|
||||
EndTime: "15:00:00"}}
|
||||
ap := &RatingPlan{Id: "test"}
|
||||
ap.AddRateInterval("NAT", i)
|
||||
result, _ := json.Marshal(ap)
|
||||
@@ -145,27 +146,32 @@ func TestFallbackNoInfiniteLoopSelf(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestApAddIntervalIfNotPresent(t *testing.T) {
|
||||
i1 := &RateInterval{Months: Months{time.February},
|
||||
i1 := &RateInterval{
|
||||
Timing: &RITiming{
|
||||
Months: Months{time.February},
|
||||
MonthDays: MonthDays{1},
|
||||
WeekDays: []time.Weekday{time.Wednesday, time.Thursday},
|
||||
StartTime: "14:30:00",
|
||||
EndTime: "15:00:00"}}
|
||||
i2 := &RateInterval{Timing: &RITiming{
|
||||
Months: Months{time.February},
|
||||
MonthDays: MonthDays{1},
|
||||
WeekDays: []time.Weekday{time.Wednesday, time.Thursday},
|
||||
StartTime: "14:30:00",
|
||||
EndTime: "15:00:00"}
|
||||
i2 := &RateInterval{Months: Months{time.February},
|
||||
MonthDays: MonthDays{1},
|
||||
WeekDays: []time.Weekday{time.Wednesday, time.Thursday},
|
||||
StartTime: "14:30:00",
|
||||
EndTime: "15:00:00"}
|
||||
i3 := &RateInterval{Months: Months{time.February},
|
||||
EndTime: "15:00:00"}}
|
||||
i3 := &RateInterval{Timing: &RITiming{
|
||||
Months: Months{time.February},
|
||||
MonthDays: MonthDays{1},
|
||||
WeekDays: []time.Weekday{time.Wednesday},
|
||||
StartTime: "14:30:00",
|
||||
EndTime: "15:00:00"}
|
||||
EndTime: "15:00:00"}}
|
||||
rp := &RatingPlan{}
|
||||
rp.AddRateInterval("NAT", i1)
|
||||
rp.AddRateInterval("NAT", i2)
|
||||
if len(rp.DestinationRates) != 1 {
|
||||
if len(rp.DestinationRates["NAT"]) != 1 {
|
||||
t.Error("Wronfullyrppended interval ;)")
|
||||
}
|
||||
t.Log()
|
||||
rp.AddRateInterval("NAT", i3)
|
||||
if len(rp.DestinationRates["NAT"]) != 2 {
|
||||
t.Error("Wronfully not appended interval ;)", rp.DestinationRates)
|
||||
@@ -174,13 +180,13 @@ func TestApAddIntervalIfNotPresent(t *testing.T) {
|
||||
|
||||
func TestApAddRateIntervalGroups(t *testing.T) {
|
||||
i1 := &RateInterval{
|
||||
Rates: RateGroups{&Rate{0, 1, 1 * time.Second, 1 * time.Second}},
|
||||
Rating: &RIRate{Rates: RateGroups{&Rate{0, 1, 1 * time.Second, 1 * time.Second}}},
|
||||
}
|
||||
i2 := &RateInterval{
|
||||
Rates: RateGroups{&Rate{30 * time.Second, 2, 1 * time.Second, 1 * time.Second}},
|
||||
Rating: &RIRate{Rates: RateGroups{&Rate{30 * time.Second, 2, 1 * time.Second, 1 * time.Second}}},
|
||||
}
|
||||
i3 := &RateInterval{
|
||||
Rates: RateGroups{&Rate{30 * time.Second, 2, 1 * time.Second, 1 * time.Second}},
|
||||
Rating: &RIRate{Rates: RateGroups{&Rate{30 * time.Second, 2, 1 * time.Second, 1 * time.Second}}},
|
||||
}
|
||||
ap := &RatingPlan{}
|
||||
ap.AddRateInterval("NAT", i1)
|
||||
@@ -189,8 +195,8 @@ func TestApAddRateIntervalGroups(t *testing.T) {
|
||||
if len(ap.DestinationRates) != 1 {
|
||||
t.Error("Wronfully appended interval ;)")
|
||||
}
|
||||
if len(ap.DestinationRates["NAT"][0].Rates) != 1 {
|
||||
t.Errorf("Group prices not formed: %#v", ap.DestinationRates["NAT"][0].Rates[0])
|
||||
if len(ap.RateIntervalList("NAT")[0].Rating.Rates) != 1 {
|
||||
t.Errorf("Group prices not formed: %#v", ap.RateIntervalList("NAT")[0].Rating.Rates[0])
|
||||
}
|
||||
}
|
||||
|
||||
@@ -198,11 +204,13 @@ func TestApAddRateIntervalGroups(t *testing.T) {
|
||||
|
||||
func BenchmarkRatingPlanStoreRestoreJson(b *testing.B) {
|
||||
b.StopTimer()
|
||||
i := &RateInterval{Months: []time.Month{time.February},
|
||||
MonthDays: []int{1},
|
||||
WeekDays: []time.Weekday{time.Wednesday, time.Thursday},
|
||||
StartTime: "14:30:00",
|
||||
EndTime: "15:00:00"}
|
||||
i := &RateInterval{
|
||||
Timing: &RITiming{
|
||||
Months: []time.Month{time.February},
|
||||
MonthDays: []int{1},
|
||||
WeekDays: []time.Weekday{time.Wednesday, time.Thursday},
|
||||
StartTime: "14:30:00",
|
||||
EndTime: "15:00:00"}}
|
||||
ap := &RatingPlan{Id: "test"}
|
||||
ap.AddRateInterval("NAT", i)
|
||||
|
||||
@@ -216,11 +224,12 @@ func BenchmarkRatingPlanStoreRestoreJson(b *testing.B) {
|
||||
|
||||
func BenchmarkRatingPlanStoreRestore(b *testing.B) {
|
||||
b.StopTimer()
|
||||
i := &RateInterval{Months: []time.Month{time.February},
|
||||
MonthDays: []int{1},
|
||||
WeekDays: []time.Weekday{time.Wednesday, time.Thursday},
|
||||
StartTime: "14:30:00",
|
||||
EndTime: "15:00:00"}
|
||||
i := &RateInterval{
|
||||
Timing: &RITiming{Months: []time.Month{time.February},
|
||||
MonthDays: []int{1},
|
||||
WeekDays: []time.Weekday{time.Wednesday, time.Thursday},
|
||||
StartTime: "14:30:00",
|
||||
EndTime: "15:00:00"}}
|
||||
ap := &RatingPlan{Id: "test"}
|
||||
ap.AddRateInterval("NAT", i)
|
||||
|
||||
|
||||
@@ -89,7 +89,7 @@ func (rp *RatingProfile) GetRatingPlansForPrefix(cd *CallDescriptor) (foundPrefi
|
||||
}
|
||||
bestPrecision := 0
|
||||
var rps RateIntervalList
|
||||
for dId, rpls := range rpl.DestinationRates {
|
||||
for dId, _ := range rpl.DestinationRates {
|
||||
precision, err := storageGetter.DestinationContainsPrefix(dId, cd.Destination)
|
||||
if err != nil {
|
||||
Logger.Err(fmt.Sprintf("Error checking destination: %v", err))
|
||||
@@ -97,7 +97,7 @@ func (rp *RatingProfile) GetRatingPlansForPrefix(cd *CallDescriptor) (foundPrefi
|
||||
}
|
||||
if precision > bestPrecision {
|
||||
bestPrecision = precision
|
||||
rps = rpls
|
||||
rps = rpl.RateIntervalList(dId)
|
||||
}
|
||||
}
|
||||
if bestPrecision > 0 {
|
||||
|
||||
@@ -124,11 +124,13 @@ func GetUB() *UserBalance {
|
||||
|
||||
func BenchmarkMarshallerJSONStoreRestore(b *testing.B) {
|
||||
b.StopTimer()
|
||||
i := &RateInterval{Months: []time.Month{time.February},
|
||||
MonthDays: []int{1},
|
||||
WeekDays: []time.Weekday{time.Wednesday, time.Thursday},
|
||||
StartTime: "14:30:00",
|
||||
EndTime: "15:00:00"}
|
||||
i := &RateInterval{
|
||||
Timing: &RITiming{
|
||||
Months: []time.Month{time.February},
|
||||
MonthDays: []int{1},
|
||||
WeekDays: []time.Weekday{time.Wednesday, time.Thursday},
|
||||
StartTime: "14:30:00",
|
||||
EndTime: "15:00:00"}}
|
||||
ap := &RatingPlan{Id: "test"}
|
||||
ap.AddRateInterval("NAT", i)
|
||||
ub := GetUB()
|
||||
@@ -147,11 +149,13 @@ func BenchmarkMarshallerJSONStoreRestore(b *testing.B) {
|
||||
|
||||
func BenchmarkMarshallerBSONStoreRestore(b *testing.B) {
|
||||
b.StopTimer()
|
||||
i := &RateInterval{Months: []time.Month{time.February},
|
||||
MonthDays: []int{1},
|
||||
WeekDays: []time.Weekday{time.Wednesday, time.Thursday},
|
||||
StartTime: "14:30:00",
|
||||
EndTime: "15:00:00"}
|
||||
i := &RateInterval{
|
||||
Timing: &RITiming{
|
||||
Months: []time.Month{time.February},
|
||||
MonthDays: []int{1},
|
||||
WeekDays: []time.Weekday{time.Wednesday, time.Thursday},
|
||||
StartTime: "14:30:00",
|
||||
EndTime: "15:00:00"}}
|
||||
ap := &RatingPlan{Id: "test"}
|
||||
ap.AddRateInterval("NAT", i)
|
||||
ub := GetUB()
|
||||
@@ -170,11 +174,12 @@ func BenchmarkMarshallerBSONStoreRestore(b *testing.B) {
|
||||
|
||||
func BenchmarkMarshallerJSONBufStoreRestore(b *testing.B) {
|
||||
b.StopTimer()
|
||||
i := &RateInterval{Months: []time.Month{time.February},
|
||||
MonthDays: []int{1},
|
||||
WeekDays: []time.Weekday{time.Wednesday, time.Thursday},
|
||||
StartTime: "14:30:00",
|
||||
EndTime: "15:00:00"}
|
||||
i := &RateInterval{
|
||||
Timing: &RITiming{Months: []time.Month{time.February},
|
||||
MonthDays: []int{1},
|
||||
WeekDays: []time.Weekday{time.Wednesday, time.Thursday},
|
||||
StartTime: "14:30:00",
|
||||
EndTime: "15:00:00"}}
|
||||
ap := &RatingPlan{Id: "test"}
|
||||
ap.AddRateInterval("NAT", i)
|
||||
ub := GetUB()
|
||||
@@ -193,11 +198,12 @@ func BenchmarkMarshallerJSONBufStoreRestore(b *testing.B) {
|
||||
|
||||
func BenchmarkMarshallerGOBStoreRestore(b *testing.B) {
|
||||
b.StopTimer()
|
||||
i := &RateInterval{Months: []time.Month{time.February},
|
||||
MonthDays: []int{1},
|
||||
WeekDays: []time.Weekday{time.Wednesday, time.Thursday},
|
||||
StartTime: "14:30:00",
|
||||
EndTime: "15:00:00"}
|
||||
i := &RateInterval{
|
||||
Timing: &RITiming{Months: []time.Month{time.February},
|
||||
MonthDays: []int{1},
|
||||
WeekDays: []time.Weekday{time.Wednesday, time.Thursday},
|
||||
StartTime: "14:30:00",
|
||||
EndTime: "15:00:00"}}
|
||||
ap := &RatingPlan{Id: "test"}
|
||||
ap.AddRateInterval("NAT", i)
|
||||
ub := GetUB()
|
||||
@@ -216,11 +222,13 @@ func BenchmarkMarshallerGOBStoreRestore(b *testing.B) {
|
||||
|
||||
func BenchmarkMarshallerCodecMsgpackStoreRestore(b *testing.B) {
|
||||
b.StopTimer()
|
||||
i := &RateInterval{Months: []time.Month{time.February},
|
||||
MonthDays: []int{1},
|
||||
WeekDays: []time.Weekday{time.Wednesday, time.Thursday},
|
||||
StartTime: "14:30:00",
|
||||
EndTime: "15:00:00"}
|
||||
i := &RateInterval{
|
||||
Timing: &RITiming{
|
||||
Months: []time.Month{time.February},
|
||||
MonthDays: []int{1},
|
||||
WeekDays: []time.Weekday{time.Wednesday, time.Thursday},
|
||||
StartTime: "14:30:00",
|
||||
EndTime: "15:00:00"}}
|
||||
ap := &RatingPlan{Id: "test"}
|
||||
ap.AddRateInterval("NAT", i)
|
||||
ub := GetUB()
|
||||
@@ -239,11 +247,13 @@ func BenchmarkMarshallerCodecMsgpackStoreRestore(b *testing.B) {
|
||||
|
||||
func BenchmarkMarshallerBincStoreRestore(b *testing.B) {
|
||||
b.StopTimer()
|
||||
i := &RateInterval{Months: []time.Month{time.February},
|
||||
MonthDays: []int{1},
|
||||
WeekDays: []time.Weekday{time.Wednesday, time.Thursday},
|
||||
StartTime: "14:30:00",
|
||||
EndTime: "15:00:00"}
|
||||
i := &RateInterval{
|
||||
Timing: &RITiming{
|
||||
Months: []time.Month{time.February},
|
||||
MonthDays: []int{1},
|
||||
WeekDays: []time.Weekday{time.Wednesday, time.Thursday},
|
||||
StartTime: "14:30:00",
|
||||
EndTime: "15:00:00"}}
|
||||
ap := &RatingPlan{Id: "test"}
|
||||
ap.AddRateInterval("NAT", i)
|
||||
ub := GetUB()
|
||||
|
||||
@@ -143,22 +143,24 @@ func (ts *TimeSpan) SplitByRateInterval(i *RateInterval) (nts *TimeSpan) {
|
||||
}
|
||||
Logger.Debug(fmt.Sprintf("TS: %+v", ts))
|
||||
// split by GroupStart
|
||||
i.Rates.Sort()
|
||||
for _, rate := range i.Rates {
|
||||
Logger.Debug(fmt.Sprintf("Rate: %+v", rate))
|
||||
if ts.GetGroupStart() < rate.GroupIntervalStart && ts.GetGroupEnd() > rate.GroupIntervalStart {
|
||||
Logger.Debug(fmt.Sprintf("Splitting"))
|
||||
ts.SetRateInterval(i)
|
||||
splitTime := ts.TimeStart.Add(rate.GroupIntervalStart - ts.GetGroupStart())
|
||||
//log.Print("SPLIT: ", splitTime)
|
||||
nts = &TimeSpan{TimeStart: splitTime, TimeEnd: ts.TimeEnd}
|
||||
ts.TimeEnd = splitTime
|
||||
nts.SetRateInterval(i)
|
||||
nts.CallDuration = ts.CallDuration
|
||||
ts.SetNewCallDuration(nts)
|
||||
Logger.Debug(fmt.Sprintf("Group splitting: %+v %+v", ts, nts))
|
||||
//log.Printf("Group splitting: %+v %+v", ts, nts)
|
||||
return
|
||||
if i.Rating != nil {
|
||||
i.Rating.Rates.Sort()
|
||||
for _, rate := range i.Rating.Rates {
|
||||
Logger.Debug(fmt.Sprintf("Rate: %+v", rate))
|
||||
if ts.GetGroupStart() < rate.GroupIntervalStart && ts.GetGroupEnd() > rate.GroupIntervalStart {
|
||||
Logger.Debug(fmt.Sprintf("Splitting"))
|
||||
ts.SetRateInterval(i)
|
||||
splitTime := ts.TimeStart.Add(rate.GroupIntervalStart - ts.GetGroupStart())
|
||||
//log.Print("SPLIT: ", splitTime)
|
||||
nts = &TimeSpan{TimeStart: splitTime, TimeEnd: ts.TimeEnd}
|
||||
ts.TimeEnd = splitTime
|
||||
nts.SetRateInterval(i)
|
||||
nts.CallDuration = ts.CallDuration
|
||||
ts.SetNewCallDuration(nts)
|
||||
Logger.Debug(fmt.Sprintf("Group splitting: %+v %+v", ts, nts))
|
||||
//log.Printf("Group splitting: %+v %+v", ts, nts)
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
//log.Printf("*************TS: %+v", ts)
|
||||
|
||||
@@ -25,7 +25,8 @@ import (
|
||||
)
|
||||
|
||||
func TestRightMargin(t *testing.T) {
|
||||
i := &RateInterval{WeekDays: []time.Weekday{time.Monday, time.Tuesday, time.Wednesday, time.Thursday, time.Friday}}
|
||||
i := &RateInterval{
|
||||
Timing: &RITiming{WeekDays: []time.Weekday{time.Monday, time.Tuesday, time.Wednesday, time.Thursday, time.Friday}}}
|
||||
t1 := time.Date(2012, time.February, 3, 23, 45, 0, 0, time.UTC)
|
||||
t2 := time.Date(2012, time.February, 4, 0, 10, 0, 0, time.UTC)
|
||||
ts := &TimeSpan{TimeStart: t1, TimeEnd: t2}
|
||||
@@ -52,10 +53,11 @@ func TestRightMargin(t *testing.T) {
|
||||
|
||||
func TestSplitMiddle(t *testing.T) {
|
||||
i := &RateInterval{
|
||||
WeekDays: WeekDays{time.Monday, time.Tuesday, time.Wednesday, time.Thursday, time.Friday},
|
||||
StartTime: "18:00:00",
|
||||
EndTime: "",
|
||||
}
|
||||
Timing: &RITiming{
|
||||
WeekDays: WeekDays{time.Monday, time.Tuesday, time.Wednesday, time.Thursday, time.Friday},
|
||||
StartTime: "18:00:00",
|
||||
EndTime: "",
|
||||
}}
|
||||
ts := &TimeSpan{
|
||||
TimeStart: time.Date(2012, 2, 27, 0, 0, 0, 0, time.UTC),
|
||||
TimeEnd: time.Date(2012, 2, 28, 0, 0, 0, 0, time.UTC),
|
||||
@@ -72,7 +74,7 @@ func TestSplitMiddle(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestRightHourMargin(t *testing.T) {
|
||||
i := &RateInterval{WeekDays: []time.Weekday{time.Monday, time.Tuesday, time.Wednesday, time.Thursday, time.Friday}, EndTime: "17:59:00"}
|
||||
i := &RateInterval{Timing: &RITiming{WeekDays: []time.Weekday{time.Monday, time.Tuesday, time.Wednesday, time.Thursday, time.Friday}, EndTime: "17:59:00"}}
|
||||
t1 := time.Date(2012, time.February, 3, 17, 30, 0, 0, time.UTC)
|
||||
t2 := time.Date(2012, time.February, 3, 18, 00, 0, 0, time.UTC)
|
||||
ts := &TimeSpan{TimeStart: t1, TimeEnd: t2}
|
||||
@@ -97,7 +99,7 @@ func TestRightHourMargin(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestLeftMargin(t *testing.T) {
|
||||
i := &RateInterval{WeekDays: []time.Weekday{time.Monday, time.Tuesday, time.Wednesday, time.Thursday, time.Friday}}
|
||||
i := &RateInterval{Timing: &RITiming{WeekDays: []time.Weekday{time.Monday, time.Tuesday, time.Wednesday, time.Thursday, time.Friday}}}
|
||||
t1 := time.Date(2012, time.February, 5, 23, 45, 0, 0, time.UTC)
|
||||
t2 := time.Date(2012, time.February, 6, 0, 10, 0, 0, time.UTC)
|
||||
ts := &TimeSpan{TimeStart: t1, TimeEnd: t2}
|
||||
@@ -121,7 +123,7 @@ func TestLeftMargin(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestLeftHourMargin(t *testing.T) {
|
||||
i := &RateInterval{Months: Months{time.December}, MonthDays: MonthDays{1}, StartTime: "09:00:00"}
|
||||
i := &RateInterval{Timing: &RITiming{Months: Months{time.December}, MonthDays: MonthDays{1}, StartTime: "09:00:00"}}
|
||||
t1 := time.Date(2012, time.December, 1, 8, 45, 0, 0, time.UTC)
|
||||
t2 := time.Date(2012, time.December, 1, 9, 20, 0, 0, time.UTC)
|
||||
ts := &TimeSpan{TimeStart: t1, TimeEnd: t2}
|
||||
@@ -145,7 +147,7 @@ func TestLeftHourMargin(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestEnclosingMargin(t *testing.T) {
|
||||
i := &RateInterval{WeekDays: []time.Weekday{time.Sunday}}
|
||||
i := &RateInterval{Timing: &RITiming{WeekDays: []time.Weekday{time.Sunday}}}
|
||||
t1 := time.Date(2012, time.February, 5, 17, 45, 0, 0, time.UTC)
|
||||
t2 := time.Date(2012, time.February, 5, 18, 10, 0, 0, time.UTC)
|
||||
ts := &TimeSpan{TimeStart: t1, TimeEnd: t2}
|
||||
@@ -159,7 +161,7 @@ func TestEnclosingMargin(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestOutsideMargin(t *testing.T) {
|
||||
i := &RateInterval{WeekDays: []time.Weekday{time.Monday}}
|
||||
i := &RateInterval{Timing: &RITiming{WeekDays: []time.Weekday{time.Monday}}}
|
||||
t1 := time.Date(2012, time.February, 5, 17, 45, 0, 0, time.UTC)
|
||||
t2 := time.Date(2012, time.February, 5, 18, 10, 0, 0, time.UTC)
|
||||
ts := &TimeSpan{TimeStart: t1, TimeEnd: t2}
|
||||
@@ -213,21 +215,21 @@ func TestTimespanGetCost(t *testing.T) {
|
||||
if ts1.getCost() != 0 {
|
||||
t.Error("No interval and still kicking")
|
||||
}
|
||||
ts1.SetRateInterval(&RateInterval{Rates: RateGroups{&Rate{0, 1.0, 1 * time.Second, 1 * time.Second}}})
|
||||
ts1.SetRateInterval(&RateInterval{Rating: &RIRate{Rates: RateGroups{&Rate{0, 1.0, 1 * time.Second, 1 * time.Second}}}})
|
||||
if ts1.getCost() != 600 {
|
||||
t.Error("Expected 10 got ", ts1.Cost)
|
||||
}
|
||||
ts1.RateInterval = nil
|
||||
ts1.SetRateInterval(&RateInterval{Rates: RateGroups{&Rate{0, 1.0, 1 * time.Second, 60 * time.Second}}})
|
||||
ts1.SetRateInterval(&RateInterval{Rating: &RIRate{Rates: RateGroups{&Rate{0, 1.0, 1 * time.Second, 60 * time.Second}}}})
|
||||
if ts1.getCost() != 10 {
|
||||
t.Error("Expected 6000 got ", ts1.Cost)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSetRateInterval(t *testing.T) {
|
||||
i1 := &RateInterval{Rates: RateGroups{&Rate{0, 1.0, 1 * time.Second, 1 * time.Second}}}
|
||||
i1 := &RateInterval{Rating: &RIRate{Rates: RateGroups{&Rate{0, 1.0, 1 * time.Second, 1 * time.Second}}}}
|
||||
ts1 := TimeSpan{RateInterval: i1}
|
||||
i2 := &RateInterval{Rates: RateGroups{&Rate{0, 2.0, 1 * time.Second, 1 * time.Second}}}
|
||||
i2 := &RateInterval{Rating: &RIRate{Rates: RateGroups{&Rate{0, 2.0, 1 * time.Second, 1 * time.Second}}}}
|
||||
ts1.SetRateInterval(i2)
|
||||
if ts1.RateInterval != i1 {
|
||||
t.Error("Smaller price interval should win")
|
||||
@@ -241,8 +243,12 @@ func TestSetRateInterval(t *testing.T) {
|
||||
|
||||
func TestTimespanSplitGroupedRates(t *testing.T) {
|
||||
i := &RateInterval{
|
||||
EndTime: "17:59:00",
|
||||
Rates: RateGroups{&Rate{0, 2, 1 * time.Second, 1 * time.Second}, &Rate{900 * time.Second, 1, 1 * time.Second, 1 * time.Second}},
|
||||
Timing: &RITiming{
|
||||
EndTime: "17:59:00",
|
||||
},
|
||||
Rating: &RIRate{
|
||||
Rates: RateGroups{&Rate{0, 2, 1 * time.Second, 1 * time.Second}, &Rate{900 * time.Second, 1, 1 * time.Second, 1 * time.Second}},
|
||||
},
|
||||
}
|
||||
t1 := time.Date(2012, time.February, 3, 17, 30, 0, 0, time.UTC)
|
||||
t2 := time.Date(2012, time.February, 3, 18, 00, 0, 0, time.UTC)
|
||||
@@ -275,19 +281,22 @@ func TestTimespanSplitGroupedRates(t *testing.T) {
|
||||
|
||||
func TestTimespanSplitGroupedRatesIncrements(t *testing.T) {
|
||||
i := &RateInterval{
|
||||
EndTime: "17:59:00",
|
||||
Rates: RateGroups{
|
||||
&Rate{
|
||||
GroupIntervalStart: 0,
|
||||
Value: 2,
|
||||
RateIncrement: time.Second,
|
||||
RateUnit: time.Second},
|
||||
&Rate{
|
||||
GroupIntervalStart: 30 * time.Second,
|
||||
Value: 1,
|
||||
RateIncrement: time.Minute,
|
||||
RateUnit: time.Second,
|
||||
}},
|
||||
Timing: &RITiming{
|
||||
EndTime: "17:59:00",
|
||||
},
|
||||
Rating: &RIRate{
|
||||
Rates: RateGroups{
|
||||
&Rate{
|
||||
GroupIntervalStart: 0,
|
||||
Value: 2,
|
||||
RateIncrement: time.Second,
|
||||
RateUnit: time.Second},
|
||||
&Rate{
|
||||
GroupIntervalStart: 30 * time.Second,
|
||||
Value: 1,
|
||||
RateIncrement: time.Minute,
|
||||
RateUnit: time.Second,
|
||||
}}},
|
||||
}
|
||||
t1 := time.Date(2012, time.February, 3, 17, 30, 0, 0, time.UTC)
|
||||
t2 := time.Date(2012, time.February, 3, 17, 31, 0, 0, time.UTC)
|
||||
@@ -328,8 +337,12 @@ func TestTimespanSplitGroupedRatesIncrements(t *testing.T) {
|
||||
|
||||
func TestTimespanSplitRightHourMarginBeforeGroup(t *testing.T) {
|
||||
i := &RateInterval{
|
||||
EndTime: "17:00:30",
|
||||
Rates: RateGroups{&Rate{0, 2, 1 * time.Second, 1 * time.Second}, &Rate{60 * time.Second, 1, 60 * time.Second, 1 * time.Second}},
|
||||
Timing: &RITiming{
|
||||
EndTime: "17:00:30",
|
||||
},
|
||||
Rating: &RIRate{
|
||||
Rates: RateGroups{&Rate{0, 2, 1 * time.Second, 1 * time.Second}, &Rate{60 * time.Second, 1, 60 * time.Second, 1 * time.Second}},
|
||||
},
|
||||
}
|
||||
t1 := time.Date(2012, time.February, 3, 17, 00, 0, 0, time.UTC)
|
||||
t2 := time.Date(2012, time.February, 3, 17, 01, 0, 0, time.UTC)
|
||||
@@ -361,8 +374,11 @@ func TestTimespanSplitRightHourMarginBeforeGroup(t *testing.T) {
|
||||
|
||||
func TestTimespanSplitGroupSecondSplit(t *testing.T) {
|
||||
i := &RateInterval{
|
||||
EndTime: "17:03:30",
|
||||
Rates: RateGroups{&Rate{0, 2, 1 * time.Second, 1 * time.Second}, &Rate{60 * time.Second, 1, 1 * time.Second, 1 * time.Second}},
|
||||
Timing: &RITiming{
|
||||
EndTime: "17:03:30",
|
||||
},
|
||||
Rating: &RIRate{
|
||||
Rates: RateGroups{&Rate{0, 2, 1 * time.Second, 1 * time.Second}, &Rate{60 * time.Second, 1, 1 * time.Second, 1 * time.Second}}},
|
||||
}
|
||||
t1 := time.Date(2012, time.February, 3, 17, 00, 0, 0, time.UTC)
|
||||
t2 := time.Date(2012, time.February, 3, 17, 04, 0, 0, time.UTC)
|
||||
@@ -405,7 +421,9 @@ func TestTimespanSplitGroupSecondSplit(t *testing.T) {
|
||||
|
||||
func TestTimespanSplitLong(t *testing.T) {
|
||||
i := &RateInterval{
|
||||
StartTime: "18:00:00",
|
||||
Timing: &RITiming{
|
||||
StartTime: "18:00:00",
|
||||
},
|
||||
}
|
||||
t1 := time.Date(2013, time.October, 9, 9, 0, 0, 0, time.UTC)
|
||||
t2 := time.Date(2013, time.October, 10, 20, 0, 0, 0, time.UTC)
|
||||
@@ -433,8 +451,11 @@ func TestTimespanSplitLong(t *testing.T) {
|
||||
|
||||
func TestTimespanSplitMultipleGroup(t *testing.T) {
|
||||
i := &RateInterval{
|
||||
EndTime: "17:05:00",
|
||||
Rates: RateGroups{&Rate{0, 2, 1 * time.Second, 1 * time.Second}, &Rate{60 * time.Second, 1, 1 * time.Second, 1 * time.Second}, &Rate{180 * time.Second, 1, 1 * time.Second, 1 * time.Second}},
|
||||
Timing: &RITiming{
|
||||
EndTime: "17:05:00",
|
||||
},
|
||||
Rating: &RIRate{
|
||||
Rates: RateGroups{&Rate{0, 2, 1 * time.Second, 1 * time.Second}, &Rate{60 * time.Second, 1, 1 * time.Second, 1 * time.Second}, &Rate{180 * time.Second, 1, 1 * time.Second, 1 * time.Second}}},
|
||||
}
|
||||
t1 := time.Date(2012, time.February, 3, 17, 00, 0, 0, time.UTC)
|
||||
t2 := time.Date(2012, time.February, 3, 17, 04, 0, 0, time.UTC)
|
||||
@@ -480,9 +501,9 @@ func TestTimespanExpandingPastEnd(t *testing.T) {
|
||||
&TimeSpan{
|
||||
TimeStart: time.Date(2013, 9, 10, 14, 30, 0, 0, time.UTC),
|
||||
TimeEnd: time.Date(2013, 9, 10, 14, 30, 30, 0, time.UTC),
|
||||
RateInterval: &RateInterval{Rates: RateGroups{
|
||||
RateInterval: &RateInterval{Rating: &RIRate{Rates: RateGroups{
|
||||
&Rate{RateIncrement: 60 * time.Second},
|
||||
}},
|
||||
}}},
|
||||
},
|
||||
&TimeSpan{
|
||||
TimeStart: time.Date(2013, 9, 10, 14, 30, 30, 0, time.UTC),
|
||||
@@ -504,9 +525,9 @@ func TestTimespanExpandingCallDuration(t *testing.T) {
|
||||
&TimeSpan{
|
||||
TimeStart: time.Date(2013, 9, 10, 14, 30, 0, 0, time.UTC),
|
||||
TimeEnd: time.Date(2013, 9, 10, 14, 30, 30, 0, time.UTC),
|
||||
RateInterval: &RateInterval{Rates: RateGroups{
|
||||
RateInterval: &RateInterval{Rating: &RIRate{Rates: RateGroups{
|
||||
&Rate{RateIncrement: 60 * time.Second},
|
||||
}},
|
||||
}}},
|
||||
},
|
||||
&TimeSpan{
|
||||
TimeStart: time.Date(2013, 9, 10, 14, 30, 30, 0, time.UTC),
|
||||
@@ -526,9 +547,9 @@ func TestTimespanExpandingRoundingPastEnd(t *testing.T) {
|
||||
&TimeSpan{
|
||||
TimeStart: time.Date(2013, 9, 10, 14, 30, 0, 0, time.UTC),
|
||||
TimeEnd: time.Date(2013, 9, 10, 14, 30, 20, 0, time.UTC),
|
||||
RateInterval: &RateInterval{Rates: RateGroups{
|
||||
RateInterval: &RateInterval{Rating: &RIRate{Rates: RateGroups{
|
||||
&Rate{RateIncrement: 15 * time.Second},
|
||||
}},
|
||||
}}},
|
||||
},
|
||||
&TimeSpan{
|
||||
TimeStart: time.Date(2013, 9, 10, 14, 30, 20, 0, time.UTC),
|
||||
@@ -550,9 +571,9 @@ func TestTimespanExpandingPastEndMultiple(t *testing.T) {
|
||||
&TimeSpan{
|
||||
TimeStart: time.Date(2013, 9, 10, 14, 30, 0, 0, time.UTC),
|
||||
TimeEnd: time.Date(2013, 9, 10, 14, 30, 30, 0, time.UTC),
|
||||
RateInterval: &RateInterval{Rates: RateGroups{
|
||||
RateInterval: &RateInterval{Rating: &RIRate{Rates: RateGroups{
|
||||
&Rate{RateIncrement: 60 * time.Second},
|
||||
}},
|
||||
}}},
|
||||
},
|
||||
&TimeSpan{
|
||||
TimeStart: time.Date(2013, 9, 10, 14, 30, 30, 0, time.UTC),
|
||||
@@ -578,9 +599,9 @@ func TestTimespanExpandingPastEndMultipleEqual(t *testing.T) {
|
||||
&TimeSpan{
|
||||
TimeStart: time.Date(2013, 9, 10, 14, 30, 0, 0, time.UTC),
|
||||
TimeEnd: time.Date(2013, 9, 10, 14, 30, 30, 0, time.UTC),
|
||||
RateInterval: &RateInterval{Rates: RateGroups{
|
||||
RateInterval: &RateInterval{Rating: &RIRate{Rates: RateGroups{
|
||||
&Rate{RateIncrement: 60 * time.Second},
|
||||
}},
|
||||
}}},
|
||||
},
|
||||
&TimeSpan{
|
||||
TimeStart: time.Date(2013, 9, 10, 14, 30, 30, 0, time.UTC),
|
||||
@@ -606,9 +627,9 @@ func TestTimespanExpandingBeforeEnd(t *testing.T) {
|
||||
&TimeSpan{
|
||||
TimeStart: time.Date(2013, 9, 10, 14, 30, 0, 0, time.UTC),
|
||||
TimeEnd: time.Date(2013, 9, 10, 14, 30, 30, 0, time.UTC),
|
||||
RateInterval: &RateInterval{Rates: RateGroups{
|
||||
RateInterval: &RateInterval{Rating: &RIRate{Rates: RateGroups{
|
||||
&Rate{RateIncrement: 45 * time.Second},
|
||||
}},
|
||||
}}},
|
||||
},
|
||||
&TimeSpan{
|
||||
TimeStart: time.Date(2013, 9, 10, 14, 30, 30, 0, time.UTC),
|
||||
@@ -632,9 +653,9 @@ func TestTimespanExpandingBeforeEndMultiple(t *testing.T) {
|
||||
&TimeSpan{
|
||||
TimeStart: time.Date(2013, 9, 10, 14, 30, 0, 0, time.UTC),
|
||||
TimeEnd: time.Date(2013, 9, 10, 14, 30, 30, 0, time.UTC),
|
||||
RateInterval: &RateInterval{Rates: RateGroups{
|
||||
RateInterval: &RateInterval{Rating: &RIRate{Rates: RateGroups{
|
||||
&Rate{RateIncrement: 45 * time.Second},
|
||||
}},
|
||||
}}},
|
||||
},
|
||||
&TimeSpan{
|
||||
TimeStart: time.Date(2013, 9, 10, 14, 30, 30, 0, time.UTC),
|
||||
@@ -661,9 +682,9 @@ func TestTimespanCreateSecondsSlice(t *testing.T) {
|
||||
ts := &TimeSpan{
|
||||
TimeStart: time.Date(2013, 9, 10, 14, 30, 0, 0, time.UTC),
|
||||
TimeEnd: time.Date(2013, 9, 10, 14, 30, 30, 0, time.UTC),
|
||||
RateInterval: &RateInterval{Rates: RateGroups{
|
||||
RateInterval: &RateInterval{Rating: &RIRate{Rates: RateGroups{
|
||||
&Rate{Value: 2.0},
|
||||
}},
|
||||
}}},
|
||||
}
|
||||
ts.createIncrementsSlice()
|
||||
if len(ts.Increments) != 30 {
|
||||
@@ -679,12 +700,14 @@ func TestTimespanCreateIncrements(t *testing.T) {
|
||||
TimeStart: time.Date(2013, 9, 10, 14, 30, 0, 0, time.UTC),
|
||||
TimeEnd: time.Date(2013, 9, 10, 14, 30, 30, 100000000, time.UTC),
|
||||
RateInterval: &RateInterval{
|
||||
RoundingMethod: utils.ROUNDING_MIDDLE,
|
||||
RoundingDecimals: 2,
|
||||
Rates: RateGroups{
|
||||
&Rate{
|
||||
Value: 2.0,
|
||||
RateIncrement: 10 * time.Second,
|
||||
Rating: &RIRate{
|
||||
RoundingMethod: utils.ROUNDING_MIDDLE,
|
||||
RoundingDecimals: 2,
|
||||
Rates: RateGroups{
|
||||
&Rate{
|
||||
Value: 2.0,
|
||||
RateIncrement: 10 * time.Second,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -704,12 +727,14 @@ func TestTimespanSplitByIncrement(t *testing.T) {
|
||||
TimeEnd: time.Date(2013, 9, 19, 18, 31, 00, 0, time.UTC),
|
||||
CallDuration: 60 * time.Second,
|
||||
RateInterval: &RateInterval{
|
||||
RoundingMethod: utils.ROUNDING_MIDDLE,
|
||||
RoundingDecimals: 2,
|
||||
Rates: RateGroups{
|
||||
&Rate{
|
||||
Value: 2.0,
|
||||
RateIncrement: 10 * time.Second,
|
||||
Rating: &RIRate{
|
||||
RoundingMethod: utils.ROUNDING_MIDDLE,
|
||||
RoundingDecimals: 2,
|
||||
Rates: RateGroups{
|
||||
&Rate{
|
||||
Value: 2.0,
|
||||
RateIncrement: 10 * time.Second,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -736,12 +761,14 @@ func TestTimespanSplitByIncrementStart(t *testing.T) {
|
||||
TimeEnd: time.Date(2013, 9, 19, 18, 31, 00, 0, time.UTC),
|
||||
CallDuration: 60 * time.Second,
|
||||
RateInterval: &RateInterval{
|
||||
RoundingMethod: utils.ROUNDING_MIDDLE,
|
||||
RoundingDecimals: 2,
|
||||
Rates: RateGroups{
|
||||
&Rate{
|
||||
Value: 2.0,
|
||||
RateIncrement: 10 * time.Second,
|
||||
Rating: &RIRate{
|
||||
RoundingMethod: utils.ROUNDING_MIDDLE,
|
||||
RoundingDecimals: 2,
|
||||
Rates: RateGroups{
|
||||
&Rate{
|
||||
Value: 2.0,
|
||||
RateIncrement: 10 * time.Second,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -768,12 +795,14 @@ func TestTimespanSplitByIncrementEnd(t *testing.T) {
|
||||
TimeEnd: time.Date(2013, 9, 19, 18, 31, 00, 0, time.UTC),
|
||||
CallDuration: 60 * time.Second,
|
||||
RateInterval: &RateInterval{
|
||||
RoundingMethod: utils.ROUNDING_MIDDLE,
|
||||
RoundingDecimals: 2,
|
||||
Rates: RateGroups{
|
||||
&Rate{
|
||||
Value: 2.0,
|
||||
RateIncrement: 10 * time.Second,
|
||||
Rating: &RIRate{
|
||||
RoundingMethod: utils.ROUNDING_MIDDLE,
|
||||
RoundingDecimals: 2,
|
||||
Rates: RateGroups{
|
||||
&Rate{
|
||||
Value: 2.0,
|
||||
RateIncrement: 10 * time.Second,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -800,12 +829,14 @@ func TestTimespanSplitByDuration(t *testing.T) {
|
||||
TimeEnd: time.Date(2013, 9, 19, 18, 31, 00, 0, time.UTC),
|
||||
CallDuration: 60 * time.Second,
|
||||
RateInterval: &RateInterval{
|
||||
RoundingMethod: utils.ROUNDING_MIDDLE,
|
||||
RoundingDecimals: 2,
|
||||
Rates: RateGroups{
|
||||
&Rate{
|
||||
Value: 2.0,
|
||||
RateIncrement: 10 * time.Second,
|
||||
Rating: &RIRate{
|
||||
RoundingMethod: utils.ROUNDING_MIDDLE,
|
||||
RoundingDecimals: 2,
|
||||
Rates: RateGroups{
|
||||
&Rate{
|
||||
Value: 2.0,
|
||||
RateIncrement: 10 * time.Second,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
@@ -213,12 +213,14 @@ func (ub *UserBalance) debitCreditBalance(cc *CallCost, count bool) error {
|
||||
}
|
||||
newTs.RoundToDuration(time.Minute)
|
||||
newTs.RateInterval = &RateInterval{
|
||||
Rates: RateGroups{
|
||||
&Rate{
|
||||
GroupIntervalStart: 0,
|
||||
Value: 0,
|
||||
RateIncrement: time.Minute,
|
||||
RateUnit: time.Minute,
|
||||
Rating: &RIRate{
|
||||
Rates: RateGroups{
|
||||
&Rate{
|
||||
GroupIntervalStart: 0,
|
||||
Value: 0,
|
||||
RateIncrement: time.Minute,
|
||||
RateUnit: time.Minute,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
@@ -218,7 +218,7 @@ func TestDebitCreditZeroSecond(t *testing.T) {
|
||||
TimeStart: time.Date(2013, 9, 24, 10, 48, 0, 0, time.UTC),
|
||||
TimeEnd: time.Date(2013, 9, 24, 10, 48, 10, 0, time.UTC),
|
||||
CallDuration: 0,
|
||||
RateInterval: &RateInterval{Rates: RateGroups{&Rate{GroupIntervalStart: 0, Value: 100, RateIncrement: 10 * time.Second, RateUnit: time.Second}}},
|
||||
RateInterval: &RateInterval{Rating: &RIRate{Rates: RateGroups{&Rate{GroupIntervalStart: 0, Value: 100, RateIncrement: 10 * time.Second, RateUnit: time.Second}}}},
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -246,7 +246,7 @@ func TestDebitCreditZeroMinute(t *testing.T) {
|
||||
TimeStart: time.Date(2013, 9, 24, 10, 48, 0, 0, time.UTC),
|
||||
TimeEnd: time.Date(2013, 9, 24, 10, 48, 10, 0, time.UTC),
|
||||
CallDuration: 0,
|
||||
RateInterval: &RateInterval{Rates: RateGroups{&Rate{GroupIntervalStart: 0, Value: 100, RateIncrement: 10 * time.Second, RateUnit: time.Second}}},
|
||||
RateInterval: &RateInterval{Rating: &RIRate{Rates: RateGroups{&Rate{GroupIntervalStart: 0, Value: 100, RateIncrement: 10 * time.Second, RateUnit: time.Second}}}},
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -279,7 +279,7 @@ func TestDebitCreditZeroMixedMinute(t *testing.T) {
|
||||
TimeStart: time.Date(2013, 9, 24, 10, 48, 0, 0, time.UTC),
|
||||
TimeEnd: time.Date(2013, 9, 24, 10, 48, 20, 0, time.UTC),
|
||||
CallDuration: 0,
|
||||
RateInterval: &RateInterval{Rates: RateGroups{&Rate{GroupIntervalStart: 0, Value: 100, RateIncrement: 10 * time.Second, RateUnit: time.Second}}},
|
||||
RateInterval: &RateInterval{Rating: &RIRate{Rates: RateGroups{&Rate{GroupIntervalStart: 0, Value: 100, RateIncrement: 10 * time.Second, RateUnit: time.Second}}}},
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -312,13 +312,13 @@ func TestDebitCreditNoCredit(t *testing.T) {
|
||||
TimeStart: time.Date(2013, 9, 24, 10, 48, 0, 0, time.UTC),
|
||||
TimeEnd: time.Date(2013, 9, 24, 10, 48, 10, 0, time.UTC),
|
||||
CallDuration: 0,
|
||||
RateInterval: &RateInterval{Rates: RateGroups{&Rate{GroupIntervalStart: 0, Value: 100, RateIncrement: 10 * time.Second, RateUnit: time.Second}}},
|
||||
RateInterval: &RateInterval{Rating: &RIRate{Rates: RateGroups{&Rate{GroupIntervalStart: 0, Value: 100, RateIncrement: 10 * time.Second, RateUnit: time.Second}}}},
|
||||
},
|
||||
&TimeSpan{
|
||||
TimeStart: time.Date(2013, 9, 24, 10, 48, 10, 0, time.UTC),
|
||||
TimeEnd: time.Date(2013, 9, 24, 10, 49, 20, 0, time.UTC),
|
||||
CallDuration: 10 * time.Second,
|
||||
RateInterval: &RateInterval{Rates: RateGroups{&Rate{GroupIntervalStart: 0, Value: 100, RateIncrement: 10 * time.Second, RateUnit: time.Second}}},
|
||||
RateInterval: &RateInterval{Rating: &RIRate{Rates: RateGroups{&Rate{GroupIntervalStart: 0, Value: 100, RateIncrement: 10 * time.Second, RateUnit: time.Second}}}},
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -352,13 +352,13 @@ func TestDebitCreditHasCredit(t *testing.T) {
|
||||
TimeStart: time.Date(2013, 9, 24, 10, 48, 0, 0, time.UTC),
|
||||
TimeEnd: time.Date(2013, 9, 24, 10, 48, 10, 0, time.UTC),
|
||||
CallDuration: 0,
|
||||
RateInterval: &RateInterval{Rates: RateGroups{&Rate{GroupIntervalStart: 0, Value: 100, RateIncrement: 10 * time.Second, RateUnit: time.Second}}},
|
||||
RateInterval: &RateInterval{Rating: &RIRate{Rates: RateGroups{&Rate{GroupIntervalStart: 0, Value: 100, RateIncrement: 10 * time.Second, RateUnit: time.Second}}}},
|
||||
},
|
||||
&TimeSpan{
|
||||
TimeStart: time.Date(2013, 9, 24, 10, 48, 10, 0, time.UTC),
|
||||
TimeEnd: time.Date(2013, 9, 24, 10, 49, 20, 0, time.UTC),
|
||||
CallDuration: 10 * time.Second,
|
||||
RateInterval: &RateInterval{Rates: RateGroups{&Rate{GroupIntervalStart: 0, Value: 1, RateIncrement: 10 * time.Second, RateUnit: time.Second}}},
|
||||
RateInterval: &RateInterval{Rating: &RIRate{Rates: RateGroups{&Rate{GroupIntervalStart: 0, Value: 1, RateIncrement: 10 * time.Second, RateUnit: time.Second}}}},
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -394,7 +394,7 @@ func TestDebitCreditSplitMinutesMoney(t *testing.T) {
|
||||
TimeStart: time.Date(2013, 9, 24, 10, 48, 0, 0, time.UTC),
|
||||
TimeEnd: time.Date(2013, 9, 24, 10, 48, 20, 0, time.UTC),
|
||||
CallDuration: 0,
|
||||
RateInterval: &RateInterval{Rates: RateGroups{&Rate{GroupIntervalStart: 0, Value: 1, RateIncrement: 10 * time.Second, RateUnit: time.Second}}},
|
||||
RateInterval: &RateInterval{Rating: &RIRate{Rates: RateGroups{&Rate{GroupIntervalStart: 0, Value: 1, RateIncrement: 10 * time.Second, RateUnit: time.Second}}}},
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -430,13 +430,13 @@ func TestDebitCreditMoreTimespans(t *testing.T) {
|
||||
TimeStart: time.Date(2013, 9, 24, 10, 48, 0, 0, time.UTC),
|
||||
TimeEnd: time.Date(2013, 9, 24, 10, 48, 10, 0, time.UTC),
|
||||
CallDuration: 0,
|
||||
RateInterval: &RateInterval{Rates: RateGroups{&Rate{GroupIntervalStart: 0, Value: 100, RateIncrement: 10 * time.Second, RateUnit: time.Second}}},
|
||||
RateInterval: &RateInterval{Rating: &RIRate{Rates: RateGroups{&Rate{GroupIntervalStart: 0, Value: 100, RateIncrement: 10 * time.Second, RateUnit: time.Second}}}},
|
||||
},
|
||||
&TimeSpan{
|
||||
TimeStart: time.Date(2013, 9, 24, 10, 48, 10, 0, time.UTC),
|
||||
TimeEnd: time.Date(2013, 9, 24, 10, 49, 20, 0, time.UTC),
|
||||
CallDuration: 10 * time.Second,
|
||||
RateInterval: &RateInterval{Rates: RateGroups{&Rate{GroupIntervalStart: 0, Value: 100, RateIncrement: 10 * time.Second, RateUnit: time.Second}}},
|
||||
RateInterval: &RateInterval{Rating: &RIRate{Rates: RateGroups{&Rate{GroupIntervalStart: 0, Value: 100, RateIncrement: 10 * time.Second, RateUnit: time.Second}}}},
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -468,13 +468,13 @@ func TestDebitCreditMoreTimespansMixed(t *testing.T) {
|
||||
TimeStart: time.Date(2013, 9, 24, 10, 48, 0, 0, time.UTC),
|
||||
TimeEnd: time.Date(2013, 9, 24, 10, 48, 10, 0, time.UTC),
|
||||
CallDuration: 0,
|
||||
RateInterval: &RateInterval{Rates: RateGroups{&Rate{GroupIntervalStart: 0, Value: 100, RateIncrement: 10 * time.Second, RateUnit: time.Second}}},
|
||||
RateInterval: &RateInterval{Rating: &RIRate{Rates: RateGroups{&Rate{GroupIntervalStart: 0, Value: 100, RateIncrement: 10 * time.Second, RateUnit: time.Second}}}},
|
||||
},
|
||||
&TimeSpan{
|
||||
TimeStart: time.Date(2013, 9, 24, 10, 48, 10, 0, time.UTC),
|
||||
TimeEnd: time.Date(2013, 9, 24, 10, 49, 20, 0, time.UTC),
|
||||
CallDuration: 10 * time.Second,
|
||||
RateInterval: &RateInterval{Rates: RateGroups{&Rate{GroupIntervalStart: 0, Value: 100, RateIncrement: 10 * time.Second, RateUnit: time.Second}}},
|
||||
RateInterval: &RateInterval{Rating: &RIRate{Rates: RateGroups{&Rate{GroupIntervalStart: 0, Value: 100, RateIncrement: 10 * time.Second, RateUnit: time.Second}}}},
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -507,13 +507,13 @@ func TestDebitCreditNoConectFeeCredit(t *testing.T) {
|
||||
TimeStart: time.Date(2013, 9, 24, 10, 48, 0, 0, time.UTC),
|
||||
TimeEnd: time.Date(2013, 9, 24, 10, 48, 10, 0, time.UTC),
|
||||
CallDuration: 0,
|
||||
RateInterval: &RateInterval{Rates: RateGroups{&Rate{GroupIntervalStart: 0, Value: 100, RateIncrement: 10 * time.Second, RateUnit: time.Second}}},
|
||||
RateInterval: &RateInterval{Rating: &RIRate{Rates: RateGroups{&Rate{GroupIntervalStart: 0, Value: 100, RateIncrement: 10 * time.Second, RateUnit: time.Second}}}},
|
||||
},
|
||||
&TimeSpan{
|
||||
TimeStart: time.Date(2013, 9, 24, 10, 48, 10, 0, time.UTC),
|
||||
TimeEnd: time.Date(2013, 9, 24, 10, 49, 20, 0, time.UTC),
|
||||
CallDuration: 10 * time.Second,
|
||||
RateInterval: &RateInterval{Rates: RateGroups{&Rate{GroupIntervalStart: 0, Value: 1, RateIncrement: 10 * time.Second, RateUnit: time.Second}}},
|
||||
RateInterval: &RateInterval{Rating: &RIRate{Rates: RateGroups{&Rate{GroupIntervalStart: 0, Value: 1, RateIncrement: 10 * time.Second, RateUnit: time.Second}}}},
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -539,13 +539,13 @@ func TestDebitCreditMoneyOnly(t *testing.T) {
|
||||
TimeStart: time.Date(2013, 9, 24, 10, 48, 0, 0, time.UTC),
|
||||
TimeEnd: time.Date(2013, 9, 24, 10, 48, 10, 0, time.UTC),
|
||||
CallDuration: 0,
|
||||
RateInterval: &RateInterval{Rates: RateGroups{&Rate{GroupIntervalStart: 0, Value: 1, RateIncrement: 10 * time.Second, RateUnit: time.Second}}},
|
||||
RateInterval: &RateInterval{Rating: &RIRate{Rates: RateGroups{&Rate{GroupIntervalStart: 0, Value: 1, RateIncrement: 10 * time.Second, RateUnit: time.Second}}}},
|
||||
},
|
||||
&TimeSpan{
|
||||
TimeStart: time.Date(2013, 9, 24, 10, 48, 10, 0, time.UTC),
|
||||
TimeEnd: time.Date(2013, 9, 24, 10, 49, 20, 0, time.UTC),
|
||||
CallDuration: 10 * time.Second,
|
||||
RateInterval: &RateInterval{Rates: RateGroups{&Rate{GroupIntervalStart: 0, Value: 1, RateIncrement: 10 * time.Second, RateUnit: time.Second}}},
|
||||
RateInterval: &RateInterval{Rating: &RIRate{Rates: RateGroups{&Rate{GroupIntervalStart: 0, Value: 1, RateIncrement: 10 * time.Second, RateUnit: time.Second}}}},
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -584,7 +584,7 @@ func TestDebitCreditSubjectMinutes(t *testing.T) {
|
||||
TimeStart: time.Date(2013, 9, 24, 10, 48, 0, 0, time.UTC),
|
||||
TimeEnd: time.Date(2013, 9, 24, 10, 49, 10, 0, time.UTC),
|
||||
CallDuration: 0,
|
||||
RateInterval: &RateInterval{Rates: RateGroups{&Rate{GroupIntervalStart: 0, Value: 100, RateIncrement: 10 * time.Second, RateUnit: time.Second}}},
|
||||
RateInterval: &RateInterval{Rating: &RIRate{Rates: RateGroups{&Rate{GroupIntervalStart: 0, Value: 100, RateIncrement: 10 * time.Second, RateUnit: time.Second}}}},
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -622,7 +622,7 @@ func TestDebitCreditSubjectMoney(t *testing.T) {
|
||||
TimeStart: time.Date(2013, 9, 24, 10, 48, 0, 0, time.UTC),
|
||||
TimeEnd: time.Date(2013, 9, 24, 10, 49, 10, 0, time.UTC),
|
||||
CallDuration: 0,
|
||||
RateInterval: &RateInterval{Rates: RateGroups{&Rate{GroupIntervalStart: 0, Value: 100, RateIncrement: 10 * time.Second, RateUnit: time.Second}}},
|
||||
RateInterval: &RateInterval{Rating: &RIRate{Rates: RateGroups{&Rate{GroupIntervalStart: 0, Value: 100, RateIncrement: 10 * time.Second, RateUnit: time.Second}}}},
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -658,7 +658,7 @@ func TestDebitCreditSubjectMixed(t *testing.T) {
|
||||
TimeStart: time.Date(2013, 9, 24, 10, 48, 0, 0, time.UTC),
|
||||
TimeEnd: time.Date(2013, 9, 24, 10, 49, 10, 0, time.UTC),
|
||||
CallDuration: 0,
|
||||
RateInterval: &RateInterval{Rates: RateGroups{&Rate{GroupIntervalStart: 0, Value: 100, RateIncrement: 10 * time.Second, RateUnit: time.Second}}},
|
||||
RateInterval: &RateInterval{Rating: &RIRate{Rates: RateGroups{&Rate{GroupIntervalStart: 0, Value: 100, RateIncrement: 10 * time.Second, RateUnit: time.Second}}}},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
@@ -39,17 +39,18 @@ func FirstNonEmpty(vals ...string) string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func FSCgrId(uuid string) string {
|
||||
func SHA1(text string) string {
|
||||
hasher := sha1.New()
|
||||
hasher.Write([]byte(uuid))
|
||||
hasher.Write([]byte(text))
|
||||
return fmt.Sprintf("%x", hasher.Sum(nil))
|
||||
}
|
||||
|
||||
func FSCgrId(uuid string) string {
|
||||
return SHA1(uuid)
|
||||
}
|
||||
|
||||
func NewTPid() string {
|
||||
hasher := sha1.New()
|
||||
uuid := GenUUID()
|
||||
hasher.Write([]byte(uuid))
|
||||
return fmt.Sprintf("%x", hasher.Sum(nil))
|
||||
return SHA1(GenUUID())
|
||||
}
|
||||
|
||||
// helper function for uuid generation
|
||||
|
||||
Reference in New Issue
Block a user