mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-25 17:18:44 +05:00
started prepaid processing
This commit is contained in:
@@ -35,10 +35,6 @@ func (ub *UserBudget) GetSecondsForPrefix(prefix string) (seconds int) {
|
||||
return
|
||||
}
|
||||
|
||||
func (ub *UserBudget) GetSecondsForSecondPrice(price float64) (seconds int) {
|
||||
return
|
||||
}
|
||||
|
||||
type Destination struct {
|
||||
id string
|
||||
prefixes []string
|
||||
|
||||
@@ -46,22 +46,28 @@ func (cd *CallDescriptor) GetKey() string {
|
||||
}
|
||||
|
||||
/*
|
||||
Splits the call timespan into sub time spans accordin to the activation periods intervals.
|
||||
Splits the call descriptor timespan into sub time spans according to the activation periods intervals.
|
||||
*/
|
||||
func (cd *CallDescriptor) splitInTimeSpans() (timespans []*TimeSpan) {
|
||||
return cd.splitTimeSpan(&TimeSpan{TimeStart: cd.TimeStart, TimeEnd: cd.TimeEnd})
|
||||
}
|
||||
|
||||
/*
|
||||
Splits the received timespan into sub time spans according to the activation periods intervals.
|
||||
*/
|
||||
func (cd *CallDescriptor) splitTimeSpan(firstSpan *TimeSpan) (timespans []*TimeSpan) {
|
||||
if len(cd.ActivationPeriods) == 0 {
|
||||
log.Print("Nothing to split, move along... ", cd)
|
||||
return
|
||||
}
|
||||
ts1 := &TimeSpan{TimeStart: cd.TimeStart, TimeEnd: cd.TimeEnd}
|
||||
ts1.ActivationPeriod = cd.ActivationPeriods[0]
|
||||
firstSpan.ActivationPeriod = cd.ActivationPeriods[0]
|
||||
|
||||
// split on activation periods
|
||||
timespans = append(timespans, ts1)
|
||||
timespans = append(timespans, firstSpan)
|
||||
afterStart, afterEnd := false, false //optimization for multiple activation periods
|
||||
for _, ap := range cd.ActivationPeriods {
|
||||
if !afterStart && !afterEnd && ap.ActivationTime.Before(cd.TimeStart) {
|
||||
ts1.ActivationPeriod = ap
|
||||
firstSpan.ActivationPeriod = ap
|
||||
} else {
|
||||
afterStart = true
|
||||
for i := 0; i < len(timespans); i++ {
|
||||
@@ -116,7 +122,7 @@ func (cd *CallDescriptor) RestoreFromStorage(sg StorageGetter) (destPrefix strin
|
||||
/*
|
||||
Creates a CallCost structure with the cost nformation calculated for the received CallDescriptor.
|
||||
*/
|
||||
func (cd *CallDescriptor) GetCost(sg StorageGetter) (result *CallCost, err error) {
|
||||
func (cd *CallDescriptor) GetCost(sg StorageGetter) (*CallCost, error) {
|
||||
destPrefix, err := cd.RestoreFromStorage(sg)
|
||||
|
||||
timespans := cd.splitInTimeSpans()
|
||||
@@ -141,6 +147,20 @@ func (cd *CallDescriptor) GetCost(sg StorageGetter) (result *CallCost, err error
|
||||
return cc, err
|
||||
}
|
||||
|
||||
/*
|
||||
Returns
|
||||
*/
|
||||
func (cd *CallDescriptor) getPresentSecondCost(sg StorageGetter) (cost float64, err error) {
|
||||
_, err = cd.RestoreFromStorage(sg)
|
||||
now := time.Now()
|
||||
oneSecond,_ := time.ParseDuration("1s")
|
||||
ts := &TimeSpan{TimeStart: now, TimeEnd: now.Add(oneSecond)}
|
||||
timespans := cd.splitTimeSpan(ts)
|
||||
|
||||
cost = timespans[0].GetCost()
|
||||
return
|
||||
}
|
||||
|
||||
/*
|
||||
The output structure that will be returned with the call cost information.
|
||||
*/
|
||||
|
||||
@@ -137,6 +137,20 @@ func TestUniquePrice(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestSecodCost(t *testing.T) {
|
||||
getter, _ := NewRedisStorage("tcp:127.0.0.1:6379", 10)
|
||||
defer getter.Close()
|
||||
|
||||
t1 := time.Date(2012, time.February, 8, 22, 50, 0, 0, time.UTC)
|
||||
t2 := time.Date(2012, time.February, 8, 23, 50, 21, 0, time.UTC)
|
||||
cd := &CallDescriptor{CstmId: "vdf", Subject: "rif", DestinationPrefix: "0723", TimeStart: t1, TimeEnd: t2}
|
||||
result, _ := cd.getPresentSecondCost(getter)
|
||||
expected := 0.016
|
||||
if result != expected {
|
||||
t.Errorf("Expected %v was %v", expected, result)
|
||||
}
|
||||
}
|
||||
|
||||
/*********************************** BENCHMARKS ***************************************/
|
||||
func BenchmarkRedisGetting(b *testing.B) {
|
||||
b.StopTimer()
|
||||
|
||||
Reference in New Issue
Block a user