mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Replaced StatEvent with CGREvent
This commit is contained in:
committed by
Dan Christian Bogos
parent
0118c7f1d4
commit
3a93dabad3
@@ -85,12 +85,12 @@ func (stsv1 *StatSv1) GetQueueIDs(tenant string, qIDs *[]string) error {
|
||||
}
|
||||
|
||||
// ProcessEvent returns processes a new Event
|
||||
func (stsv1 *StatSv1) ProcessEvent(ev *engine.StatEvent, reply *string) error {
|
||||
func (stsv1 *StatSv1) ProcessEvent(ev *utils.CGREvent, reply *string) error {
|
||||
return stsv1.sS.V1ProcessEvent(ev, reply)
|
||||
}
|
||||
|
||||
// GetQueueIDs returns the list of queues IDs in the system
|
||||
func (stsv1 *StatSv1) GetStatQueuesForEvent(ev *engine.StatEvent, reply *engine.StatQueues) (err error) {
|
||||
func (stsv1 *StatSv1) GetStatQueuesForEvent(ev *utils.CGREvent, reply *engine.StatQueues) (err error) {
|
||||
return stsv1.sS.V1GetStatQueuesForEvent(ev, reply)
|
||||
}
|
||||
|
||||
|
||||
@@ -41,8 +41,8 @@ var (
|
||||
statsDelay int
|
||||
)
|
||||
|
||||
var evs = []*engine.StatEvent{
|
||||
&engine.StatEvent{
|
||||
var evs = []*utils.CGREvent{
|
||||
&utils.CGREvent{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "event1",
|
||||
Event: map[string]interface{}{
|
||||
@@ -50,14 +50,14 @@ var evs = []*engine.StatEvent{
|
||||
utils.ANSWER_TIME: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
|
||||
utils.USAGE: time.Duration(135 * time.Second),
|
||||
utils.COST: 123.0}},
|
||||
&engine.StatEvent{
|
||||
&utils.CGREvent{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "event2",
|
||||
Event: map[string]interface{}{
|
||||
utils.ACCOUNT: "1002",
|
||||
utils.ANSWER_TIME: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
|
||||
utils.USAGE: time.Duration(45 * time.Second)}},
|
||||
&engine.StatEvent{
|
||||
&utils.CGREvent{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "event3",
|
||||
Event: map[string]interface{}{
|
||||
@@ -170,7 +170,7 @@ func testV1STSGetStats(t *testing.T) {
|
||||
|
||||
func testV1STSProcessEvent(t *testing.T) {
|
||||
var reply string
|
||||
ev1 := engine.StatEvent{
|
||||
ev1 := utils.CGREvent{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "event1",
|
||||
Event: map[string]interface{}{
|
||||
@@ -199,7 +199,7 @@ func testV1STSProcessEvent(t *testing.T) {
|
||||
} else if !reflect.DeepEqual(expectedMetrics, metrics) {
|
||||
t.Errorf("expecting: %+v, received reply: %s", expectedMetrics, metrics)
|
||||
}
|
||||
ev2 := engine.StatEvent{
|
||||
ev2 := utils.CGREvent{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "event2",
|
||||
Event: map[string]interface{}{
|
||||
@@ -211,7 +211,7 @@ func testV1STSProcessEvent(t *testing.T) {
|
||||
} else if reply != utils.OK {
|
||||
t.Errorf("received reply: %s", reply)
|
||||
}
|
||||
ev3 := &engine.StatEvent{
|
||||
ev3 := &utils.CGREvent{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "event3",
|
||||
Event: map[string]interface{}{
|
||||
|
||||
@@ -19,11 +19,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
package engine
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
"sort"
|
||||
"strconv"
|
||||
"time"
|
||||
)
|
||||
|
||||
@@ -47,103 +45,6 @@ func (sqp *StatQueueProfile) TenantID() string {
|
||||
return utils.ConcatenatedKey(sqp.Tenant, sqp.ID)
|
||||
}
|
||||
|
||||
// StatEvent is an event processed by StatService
|
||||
type StatEvent struct {
|
||||
Tenant string
|
||||
ID string
|
||||
Event map[string]interface{}
|
||||
}
|
||||
|
||||
// TenantID returns the unique identifier based on Tenant and ID
|
||||
func (se StatEvent) TenantID() string {
|
||||
return utils.ConcatenatedKey(se.Tenant, se.ID)
|
||||
}
|
||||
|
||||
// AnswerTime returns the AnswerTime of StatEvent
|
||||
func (se StatEvent) AnswerTime(timezone string) (at time.Time, err error) {
|
||||
atIf, has := se.Event[utils.ANSWER_TIME]
|
||||
if !has {
|
||||
return at, utils.ErrNotFound
|
||||
}
|
||||
if at, canCast := atIf.(time.Time); canCast {
|
||||
return at, nil
|
||||
}
|
||||
atStr, canCast := atIf.(string)
|
||||
if !canCast {
|
||||
return at, errors.New("cannot cast to string")
|
||||
}
|
||||
return utils.ParseTimeDetectLayout(atStr, timezone)
|
||||
}
|
||||
|
||||
// Usage returns the Usage of StatEvent
|
||||
func (se StatEvent) Usage() (at time.Duration, err error) {
|
||||
usIf, has := se.Event[utils.USAGE]
|
||||
if !has {
|
||||
return at, utils.ErrNotFound
|
||||
}
|
||||
if us, canCast := usIf.(time.Duration); canCast {
|
||||
return us, nil
|
||||
}
|
||||
if us, canCast := usIf.(float64); canCast {
|
||||
return time.Duration(int64(us)), nil
|
||||
}
|
||||
usStr, canCast := usIf.(string)
|
||||
if !canCast {
|
||||
return at, errors.New("cannot cast to string")
|
||||
}
|
||||
return utils.ParseDurationWithNanosecs(usStr)
|
||||
}
|
||||
|
||||
// Cost returns the Cost of StatEvent
|
||||
func (se StatEvent) Cost() (cs float64, err error) {
|
||||
csIf, has := se.Event[utils.COST]
|
||||
if !has {
|
||||
return cs, utils.ErrNotFound
|
||||
}
|
||||
if val, canCast := csIf.(float64); canCast {
|
||||
return val, nil
|
||||
}
|
||||
csStr, canCast := csIf.(string)
|
||||
if !canCast {
|
||||
return cs, errors.New("cannot cast to string")
|
||||
}
|
||||
return strconv.ParseFloat(csStr, 64)
|
||||
}
|
||||
|
||||
// Pdd returns the Pdd of StatEvent
|
||||
func (se StatEvent) Pdd() (pdd time.Duration, err error) {
|
||||
pddIf, has := se.Event[utils.PDD]
|
||||
if !has {
|
||||
return pdd, utils.ErrNotFound
|
||||
}
|
||||
if pdd, canCast := pddIf.(time.Duration); canCast {
|
||||
return pdd, nil
|
||||
}
|
||||
if pdd, canCast := pddIf.(float64); canCast {
|
||||
return time.Duration(int64(pdd)), nil
|
||||
}
|
||||
pddStr, canCast := pddIf.(string)
|
||||
if !canCast {
|
||||
return pdd, errors.New("cannot cast to string")
|
||||
}
|
||||
return utils.ParseDurationWithNanosecs(pddStr)
|
||||
}
|
||||
|
||||
// Destination returns the Destination of StatEvent
|
||||
func (se StatEvent) Destination() (ddc string, err error) {
|
||||
ddcIf, has := se.Event[utils.DESTINATION]
|
||||
if !has {
|
||||
return ddc, utils.ErrNotFound
|
||||
}
|
||||
if ddcInt, canCast := ddcIf.(int64); canCast {
|
||||
return strconv.FormatInt(ddcInt, 64), nil
|
||||
}
|
||||
ddcStr, canCast := ddcIf.(string)
|
||||
if !canCast {
|
||||
return ddc, errors.New("cannot cast to string")
|
||||
}
|
||||
return ddcStr, nil
|
||||
}
|
||||
|
||||
// NewStoredStatQueue initiates a StoredStatQueue out of StatQueue
|
||||
func NewStoredStatQueue(sq *StatQueue, ms Marshaler) (sSQ *StoredStatQueue, err error) {
|
||||
@@ -175,7 +76,7 @@ type StoredStatQueue struct {
|
||||
Tenant string
|
||||
ID string
|
||||
SQItems []struct {
|
||||
EventID string // Bounded to the original StatEvent
|
||||
EventID string // Bounded to the original utils.CGREvent
|
||||
ExpiryTime *time.Time // Used to auto-expire events
|
||||
}
|
||||
SQMetrics map[string][]byte
|
||||
@@ -219,7 +120,7 @@ type StatQueue struct {
|
||||
Tenant string
|
||||
ID string
|
||||
SQItems []struct {
|
||||
EventID string // Bounded to the original StatEvent
|
||||
EventID string // Bounded to the original utils.CGREvent
|
||||
ExpiryTime *time.Time // Used to auto-expire events
|
||||
}
|
||||
SQMetrics map[string]StatMetric
|
||||
@@ -234,8 +135,8 @@ func (sq *StatQueue) TenantID() string {
|
||||
return utils.ConcatenatedKey(sq.Tenant, sq.ID)
|
||||
}
|
||||
|
||||
// ProcessEvent processes a StatEvent, returns true if processed
|
||||
func (sq *StatQueue) ProcessEvent(ev *StatEvent) (err error) {
|
||||
// ProcessEvent processes a utils.CGREvent, returns true if processed
|
||||
func (sq *StatQueue) ProcessEvent(ev *utils.CGREvent) (err error) {
|
||||
sq.remExpired()
|
||||
sq.remOnQueueLength()
|
||||
sq.addStatEvent(ev)
|
||||
@@ -283,7 +184,7 @@ func (sq *StatQueue) remOnQueueLength() {
|
||||
}
|
||||
|
||||
// addStatEvent computes metrics for an event
|
||||
func (sq *StatQueue) addStatEvent(ev *StatEvent) {
|
||||
func (sq *StatQueue) addStatEvent(ev *utils.CGREvent) {
|
||||
for metricID, metric := range sq.SQMetrics {
|
||||
if err := metric.AddEvent(ev); err != nil {
|
||||
utils.Logger.Warning(fmt.Sprintf("<StatQueue> metricID: %s, add eventID: %s, error: %s",
|
||||
|
||||
@@ -189,7 +189,7 @@ func TestStatAddStatEvent(t *testing.T) {
|
||||
if asr := asrMetric.GetFloat64Value(); asr != 100 {
|
||||
t.Errorf("received ASR: %v", asr)
|
||||
}
|
||||
ev1 := &StatEvent{Tenant: "cgrates.org", ID: "TestStatAddStatEvent_1"}
|
||||
ev1 := &utils.CGREvent{Tenant: "cgrates.org", ID: "TestStatAddStatEvent_1"}
|
||||
sq.addStatEvent(ev1)
|
||||
if asr := asrMetric.GetFloat64Value(); asr != 50 {
|
||||
t.Errorf("received ASR: %v", asr)
|
||||
|
||||
@@ -49,7 +49,7 @@ type StatMetric interface {
|
||||
GetValue() interface{}
|
||||
GetStringValue(fmtOpts string) (val string)
|
||||
GetFloat64Value() (val float64)
|
||||
AddEvent(ev *StatEvent) error
|
||||
AddEvent(ev *utils.CGREvent) error
|
||||
RemEvent(evTenantID string) error
|
||||
Marshal(ms Marshaler) (marshaled []byte, err error)
|
||||
LoadMarshaled(ms Marshaler, marshaled []byte) (err error)
|
||||
@@ -101,9 +101,9 @@ func (asr *StatASR) GetFloat64Value() (val float64) {
|
||||
}
|
||||
|
||||
// AddEvent is part of StatMetric interface
|
||||
func (asr *StatASR) AddEvent(ev *StatEvent) (err error) {
|
||||
func (asr *StatASR) AddEvent(ev *utils.CGREvent) (err error) {
|
||||
var answered bool
|
||||
if at, err := ev.AnswerTime(config.CgrConfig().DefaultTimezone); err != nil &&
|
||||
if at, err := ev.FieldAsTime(utils.ANSWER_TIME, config.CgrConfig().DefaultTimezone); err != nil &&
|
||||
err != utils.ErrNotFound {
|
||||
return err
|
||||
} else if !at.IsZero() {
|
||||
@@ -189,12 +189,12 @@ func (acd *StatACD) GetFloat64Value() (v float64) {
|
||||
return
|
||||
}
|
||||
|
||||
func (acd *StatACD) AddEvent(ev *StatEvent) (err error) {
|
||||
func (acd *StatACD) AddEvent(ev *utils.CGREvent) (err error) {
|
||||
var value time.Duration
|
||||
if at, err := ev.AnswerTime(config.CgrConfig().DefaultTimezone); err != nil {
|
||||
if at, err := ev.FieldAsTime(utils.ANSWER_TIME, config.CgrConfig().DefaultTimezone); err != nil {
|
||||
return err
|
||||
} else if !at.IsZero() {
|
||||
if duration, err := ev.Usage(); err != nil &&
|
||||
if duration, err := ev.FieldAsDuration(utils.USAGE); err != nil &&
|
||||
err != utils.ErrNotFound {
|
||||
return err
|
||||
} else {
|
||||
@@ -276,12 +276,12 @@ func (tcd *StatTCD) GetFloat64Value() (v float64) {
|
||||
return
|
||||
}
|
||||
|
||||
func (tcd *StatTCD) AddEvent(ev *StatEvent) (err error) {
|
||||
func (tcd *StatTCD) AddEvent(ev *utils.CGREvent) (err error) {
|
||||
var value time.Duration
|
||||
if at, err := ev.AnswerTime(config.CgrConfig().DefaultTimezone); err != nil {
|
||||
if at, err := ev.FieldAsTime(utils.ANSWER_TIME, config.CgrConfig().DefaultTimezone); err != nil {
|
||||
return err
|
||||
} else if !at.IsZero() {
|
||||
if duration, err := ev.Usage(); err != nil &&
|
||||
if duration, err := ev.FieldAsDuration(utils.USAGE); err != nil &&
|
||||
err != utils.ErrNotFound {
|
||||
return err
|
||||
} else {
|
||||
@@ -362,12 +362,12 @@ func (acc *StatACC) GetFloat64Value() (v float64) {
|
||||
return acc.getValue()
|
||||
}
|
||||
|
||||
func (acc *StatACC) AddEvent(ev *StatEvent) (err error) {
|
||||
func (acc *StatACC) AddEvent(ev *utils.CGREvent) (err error) {
|
||||
var value float64
|
||||
if at, err := ev.AnswerTime(config.CgrConfig().DefaultTimezone); err != nil {
|
||||
if at, err := ev.FieldAsTime(utils.ANSWER_TIME, config.CgrConfig().DefaultTimezone); err != nil {
|
||||
return err
|
||||
} else if !at.IsZero() {
|
||||
if cost, err := ev.Cost(); err != nil &&
|
||||
if cost, err := ev.FieldAsFloat64(utils.COST); err != nil &&
|
||||
err != utils.ErrNotFound {
|
||||
return err
|
||||
} else if cost >= 0 {
|
||||
@@ -446,12 +446,12 @@ func (tcc *StatTCC) GetFloat64Value() (v float64) {
|
||||
return tcc.getValue()
|
||||
}
|
||||
|
||||
func (tcc *StatTCC) AddEvent(ev *StatEvent) (err error) {
|
||||
func (tcc *StatTCC) AddEvent(ev *utils.CGREvent) (err error) {
|
||||
var value float64
|
||||
if at, err := ev.AnswerTime(config.CgrConfig().DefaultTimezone); err != nil {
|
||||
if at, err := ev.FieldAsTime(utils.ANSWER_TIME, config.CgrConfig().DefaultTimezone); err != nil {
|
||||
return err
|
||||
} else if !at.IsZero() {
|
||||
if cost, err := ev.Cost(); err != nil &&
|
||||
if cost, err := ev.FieldAsFloat64(utils.COST); err != nil &&
|
||||
err != utils.ErrNotFound {
|
||||
return err
|
||||
} else if cost >= 0 {
|
||||
@@ -534,13 +534,13 @@ func (pdd *StatPDD) GetFloat64Value() (v float64) {
|
||||
return
|
||||
}
|
||||
|
||||
func (pdd *StatPDD) AddEvent(ev *StatEvent) (err error) {
|
||||
func (pdd *StatPDD) AddEvent(ev *utils.CGREvent) (err error) {
|
||||
var value time.Duration
|
||||
if at, err := ev.AnswerTime(config.CgrConfig().DefaultTimezone); err != nil &&
|
||||
if at, err := ev.FieldAsTime(utils.ANSWER_TIME, config.CgrConfig().DefaultTimezone); err != nil &&
|
||||
err != utils.ErrNotFound {
|
||||
return err
|
||||
} else if !at.IsZero() {
|
||||
if duration, err := ev.Pdd(); err != nil &&
|
||||
if duration, err := ev.FieldAsDuration(utils.PDD); err != nil &&
|
||||
err != utils.ErrNotFound {
|
||||
return err
|
||||
} else {
|
||||
@@ -608,9 +608,9 @@ func (ddc *StatDDC) GetFloat64Value() (v float64) {
|
||||
return
|
||||
}
|
||||
|
||||
func (ddc *StatDDC) AddEvent(ev *StatEvent) (err error) {
|
||||
func (ddc *StatDDC) AddEvent(ev *utils.CGREvent) (err error) {
|
||||
var dest string
|
||||
if dest, err = ev.Destination(); err != nil {
|
||||
if dest, err = ev.FieldAsString(utils.DESTINATION); err != nil {
|
||||
return err
|
||||
}
|
||||
if _, has := ddc.Destinations[dest]; !has {
|
||||
|
||||
@@ -26,7 +26,7 @@ import (
|
||||
|
||||
func TestASRGetStringValue(t *testing.T) {
|
||||
asr, _ := NewASR(2)
|
||||
ev := &StatEvent{Tenant: "cgrates.org", ID: "EVENT_1",
|
||||
ev := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_1",
|
||||
Event: map[string]interface{}{
|
||||
"AnswerTime": time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC)}}
|
||||
if strVal := asr.GetStringValue(""); strVal != utils.NOT_AVAILABLE {
|
||||
@@ -36,8 +36,8 @@ func TestASRGetStringValue(t *testing.T) {
|
||||
if strVal := asr.GetStringValue(""); strVal != utils.NOT_AVAILABLE {
|
||||
t.Errorf("wrong asr value: %s", strVal)
|
||||
}
|
||||
ev2 := &StatEvent{Tenant: "cgrates.org", ID: "EVENT_2"}
|
||||
ev3 := &StatEvent{Tenant: "cgrates.org", ID: "EVENT_3"}
|
||||
ev2 := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_2"}
|
||||
ev3 := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_3"}
|
||||
asr.AddEvent(ev2)
|
||||
if strVal := asr.GetStringValue(""); strVal != "50%" {
|
||||
t.Errorf("wrong asr value: %s", strVal)
|
||||
@@ -50,10 +50,10 @@ func TestASRGetStringValue(t *testing.T) {
|
||||
if strVal := asr.GetStringValue(""); strVal != "50%" {
|
||||
t.Errorf("wrong asr value: %s", strVal)
|
||||
}
|
||||
ev4 := &StatEvent{Tenant: "cgrates.org", ID: "EVENT_4",
|
||||
ev4 := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_4",
|
||||
Event: map[string]interface{}{
|
||||
"AnswerTime": time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC)}}
|
||||
ev5 := &StatEvent{Tenant: "cgrates.org", ID: "EVENT_5",
|
||||
ev5 := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_5",
|
||||
Event: map[string]interface{}{
|
||||
"AnswerTime": time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC)}}
|
||||
asr.AddEvent(ev4)
|
||||
@@ -75,15 +75,15 @@ func TestASRGetStringValue(t *testing.T) {
|
||||
|
||||
func TestASRGetValue(t *testing.T) {
|
||||
asr, _ := NewASR(2)
|
||||
ev := &StatEvent{Tenant: "cgrates.org", ID: "EVENT_1",
|
||||
ev := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_1",
|
||||
Event: map[string]interface{}{
|
||||
"AnswerTime": time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC)}}
|
||||
asr.AddEvent(ev)
|
||||
if v := asr.GetValue(); v != -1.0 {
|
||||
t.Errorf("wrong asr value: %f", v)
|
||||
}
|
||||
ev2 := &StatEvent{Tenant: "cgrates.org", ID: "EVENT_2"}
|
||||
ev3 := &StatEvent{Tenant: "cgrates.org", ID: "EVENT_3"}
|
||||
ev2 := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_2"}
|
||||
ev3 := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_3"}
|
||||
asr.AddEvent(ev2)
|
||||
asr.AddEvent(ev3)
|
||||
if v := asr.GetValue(); v != 33.33333 {
|
||||
@@ -93,10 +93,10 @@ func TestASRGetValue(t *testing.T) {
|
||||
if v := asr.GetValue(); v != 50.0 {
|
||||
t.Errorf("wrong asr value: %f", v)
|
||||
}
|
||||
ev4 := &StatEvent{Tenant: "cgrates.org", ID: "EVENT_4",
|
||||
ev4 := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_4",
|
||||
Event: map[string]interface{}{
|
||||
"AnswerTime": time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC)}}
|
||||
ev5 := &StatEvent{Tenant: "cgrates.org", ID: "EVENT_5",
|
||||
ev5 := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_5",
|
||||
Event: map[string]interface{}{
|
||||
"AnswerTime": time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC)}}
|
||||
asr.AddEvent(ev4)
|
||||
@@ -121,7 +121,7 @@ func TestASRGetValue(t *testing.T) {
|
||||
|
||||
func TestACDGetStringValue(t *testing.T) {
|
||||
acd, _ := NewACD(2)
|
||||
ev := &StatEvent{Tenant: "cgrates.org", ID: "EVENT_1",
|
||||
ev := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_1",
|
||||
Event: map[string]interface{}{
|
||||
utils.USAGE: time.Duration(10 * time.Second),
|
||||
"AnswerTime": time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
|
||||
@@ -133,8 +133,8 @@ func TestACDGetStringValue(t *testing.T) {
|
||||
if strVal := acd.GetStringValue(""); strVal != utils.NOT_AVAILABLE {
|
||||
t.Errorf("wrong acd value: %s", strVal)
|
||||
}
|
||||
ev2 := &StatEvent{Tenant: "cgrates.org", ID: "EVENT_2"}
|
||||
ev3 := &StatEvent{Tenant: "cgrates.org", ID: "EVENT_3"}
|
||||
ev2 := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_2"}
|
||||
ev3 := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_3"}
|
||||
acd.AddEvent(ev2)
|
||||
acd.AddEvent(ev3)
|
||||
if strVal := acd.GetStringValue(""); strVal != utils.NOT_AVAILABLE {
|
||||
@@ -147,13 +147,13 @@ func TestACDGetStringValue(t *testing.T) {
|
||||
if strVal := acd.GetStringValue(""); strVal != utils.NOT_AVAILABLE {
|
||||
t.Errorf("wrong acd value: %s", strVal)
|
||||
}
|
||||
ev4 := &StatEvent{Tenant: "cgrates.org", ID: "EVENT_4",
|
||||
ev4 := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_4",
|
||||
Event: map[string]interface{}{
|
||||
"Usage": time.Duration(1 * time.Minute),
|
||||
"AnswerTime": time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
|
||||
},
|
||||
}
|
||||
ev5 := &StatEvent{Tenant: "cgrates.org", ID: "EVENT_5",
|
||||
ev5 := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_5",
|
||||
Event: map[string]interface{}{
|
||||
"Usage": time.Duration(1*time.Minute + 30*time.Second),
|
||||
"AnswerTime": time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
|
||||
@@ -181,7 +181,7 @@ func TestACDGetStringValue(t *testing.T) {
|
||||
|
||||
func TestACDGetFloat64Value(t *testing.T) {
|
||||
acd, _ := NewACD(2)
|
||||
ev := &StatEvent{Tenant: "cgrates.org", ID: "EVENT_1",
|
||||
ev := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_1",
|
||||
Event: map[string]interface{}{
|
||||
"AnswerTime": time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
|
||||
"Usage": time.Duration(10 * time.Second)}}
|
||||
@@ -189,18 +189,18 @@ func TestACDGetFloat64Value(t *testing.T) {
|
||||
if v := acd.GetFloat64Value(); v != -1.0 {
|
||||
t.Errorf("wrong acd value: %v", v)
|
||||
}
|
||||
ev2 := &StatEvent{Tenant: "cgrates.org", ID: "EVENT_2"}
|
||||
ev2 := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_2"}
|
||||
acd.AddEvent(ev2)
|
||||
if v := acd.GetFloat64Value(); v != -1.0 {
|
||||
t.Errorf("wrong acd value: %v", v)
|
||||
}
|
||||
ev4 := &StatEvent{Tenant: "cgrates.org", ID: "EVENT_4",
|
||||
ev4 := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_4",
|
||||
Event: map[string]interface{}{
|
||||
"Usage": time.Duration(1 * time.Minute),
|
||||
"AnswerTime": time.Date(2015, 7, 14, 14, 25, 0, 0, time.UTC),
|
||||
},
|
||||
}
|
||||
ev5 := &StatEvent{Tenant: "cgrates.org", ID: "EVENT_5",
|
||||
ev5 := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_5",
|
||||
Event: map[string]interface{}{
|
||||
"Usage": time.Duration(1*time.Minute + 30*time.Second),
|
||||
"AnswerTime": time.Date(2015, 7, 14, 14, 25, 0, 0, time.UTC),
|
||||
@@ -234,7 +234,7 @@ func TestACDGetFloat64Value(t *testing.T) {
|
||||
|
||||
func TestACDGetValue(t *testing.T) {
|
||||
acd, _ := NewACD(2)
|
||||
ev := &StatEvent{Tenant: "cgrates.org", ID: "EVENT_1",
|
||||
ev := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_1",
|
||||
Event: map[string]interface{}{
|
||||
"AnswerTime": time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
|
||||
"Usage": time.Duration(10 * time.Second)}}
|
||||
@@ -242,11 +242,11 @@ func TestACDGetValue(t *testing.T) {
|
||||
if v := acd.GetValue(); v != time.Duration((-1)*time.Nanosecond) {
|
||||
t.Errorf("wrong acd value: %+v", v)
|
||||
}
|
||||
ev2 := &StatEvent{Tenant: "cgrates.org", ID: "EVENT_2",
|
||||
ev2 := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_2",
|
||||
Event: map[string]interface{}{
|
||||
"AnswerTime": time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
|
||||
"Usage": time.Duration(8 * time.Second)}}
|
||||
ev3 := &StatEvent{Tenant: "cgrates.org", ID: "EVENT_3"}
|
||||
ev3 := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_3"}
|
||||
acd.AddEvent(ev2)
|
||||
acd.AddEvent(ev3)
|
||||
if v := acd.GetValue(); v != time.Duration(9*time.Second) {
|
||||
@@ -260,13 +260,13 @@ func TestACDGetValue(t *testing.T) {
|
||||
if v := acd.GetValue(); v != time.Duration((-1)*time.Nanosecond) {
|
||||
t.Errorf("wrong acd value: %+v", v)
|
||||
}
|
||||
ev4 := &StatEvent{Tenant: "cgrates.org", ID: "EVENT_4",
|
||||
ev4 := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_4",
|
||||
Event: map[string]interface{}{
|
||||
"Usage": time.Duration(1 * time.Minute),
|
||||
"AnswerTime": time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
|
||||
},
|
||||
}
|
||||
ev5 := &StatEvent{Tenant: "cgrates.org", ID: "EVENT_5",
|
||||
ev5 := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_5",
|
||||
Event: map[string]interface{}{
|
||||
"Usage": time.Duration(4*time.Minute + 30*time.Second),
|
||||
"AnswerTime": time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
|
||||
@@ -290,7 +290,7 @@ func TestACDGetValue(t *testing.T) {
|
||||
|
||||
func TestTCDGetStringValue(t *testing.T) {
|
||||
tcd, _ := NewTCD(2)
|
||||
ev := &StatEvent{Tenant: "cgrates.org", ID: "EVENT_1",
|
||||
ev := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_1",
|
||||
Event: map[string]interface{}{
|
||||
"Usage": time.Duration(10 * time.Second),
|
||||
"AnswerTime": time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
|
||||
@@ -302,12 +302,12 @@ func TestTCDGetStringValue(t *testing.T) {
|
||||
if strVal := tcd.GetStringValue(""); strVal != utils.NOT_AVAILABLE {
|
||||
t.Errorf("wrong tcd value: %s", strVal)
|
||||
}
|
||||
ev2 := &StatEvent{Tenant: "cgrates.org", ID: "EVENT_2",
|
||||
ev2 := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_2",
|
||||
Event: map[string]interface{}{
|
||||
"Usage": time.Duration(10 * time.Second),
|
||||
"AnswerTime": time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
|
||||
}}
|
||||
ev3 := &StatEvent{Tenant: "cgrates.org", ID: "EVENT_3"}
|
||||
ev3 := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_3"}
|
||||
tcd.AddEvent(ev2)
|
||||
tcd.AddEvent(ev3)
|
||||
if strVal := tcd.GetStringValue(""); strVal != "20s" {
|
||||
@@ -321,13 +321,13 @@ func TestTCDGetStringValue(t *testing.T) {
|
||||
if strVal := tcd.GetStringValue(""); strVal != utils.NOT_AVAILABLE {
|
||||
t.Errorf("wrong tcd value: %s", strVal)
|
||||
}
|
||||
ev4 := &StatEvent{Tenant: "cgrates.org", ID: "EVENT_4",
|
||||
ev4 := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_4",
|
||||
Event: map[string]interface{}{
|
||||
"Usage": time.Duration(1 * time.Minute),
|
||||
"AnswerTime": time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
|
||||
},
|
||||
}
|
||||
ev5 := &StatEvent{Tenant: "cgrates.org", ID: "EVENT_5",
|
||||
ev5 := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_5",
|
||||
Event: map[string]interface{}{
|
||||
"Usage": time.Duration(1*time.Minute + 30*time.Second),
|
||||
"AnswerTime": time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
|
||||
@@ -351,7 +351,7 @@ func TestTCDGetStringValue(t *testing.T) {
|
||||
|
||||
func TestTCDGetFloat64Value(t *testing.T) {
|
||||
tcd, _ := NewTCD(2)
|
||||
ev := &StatEvent{Tenant: "cgrates.org", ID: "EVENT_1",
|
||||
ev := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_1",
|
||||
Event: map[string]interface{}{
|
||||
"AnswerTime": time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
|
||||
"Usage": time.Duration(10 * time.Second)}}
|
||||
@@ -359,18 +359,18 @@ func TestTCDGetFloat64Value(t *testing.T) {
|
||||
if v := tcd.GetFloat64Value(); v != -1.0 {
|
||||
t.Errorf("wrong tcd value: %f", v)
|
||||
}
|
||||
ev2 := &StatEvent{Tenant: "cgrates.org", ID: "EVENT_2"}
|
||||
ev2 := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_2"}
|
||||
tcd.AddEvent(ev2)
|
||||
if v := tcd.GetFloat64Value(); v != -1.0 {
|
||||
t.Errorf("wrong tcd value: %f", v)
|
||||
}
|
||||
ev4 := &StatEvent{Tenant: "cgrates.org", ID: "EVENT_4",
|
||||
ev4 := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_4",
|
||||
Event: map[string]interface{}{
|
||||
"Usage": time.Duration(1 * time.Minute),
|
||||
"AnswerTime": time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
|
||||
},
|
||||
}
|
||||
ev5 := &StatEvent{Tenant: "cgrates.org", ID: "EVENT_5",
|
||||
ev5 := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_5",
|
||||
Event: map[string]interface{}{
|
||||
"Usage": time.Duration(1*time.Minute + 30*time.Second),
|
||||
"AnswerTime": time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
|
||||
@@ -404,7 +404,7 @@ func TestTCDGetFloat64Value(t *testing.T) {
|
||||
|
||||
func TestTCDGetValue(t *testing.T) {
|
||||
tcd, _ := NewTCD(2)
|
||||
ev := &StatEvent{Tenant: "cgrates.org", ID: "EVENT_1",
|
||||
ev := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_1",
|
||||
Event: map[string]interface{}{
|
||||
"AnswerTime": time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
|
||||
"Usage": time.Duration(10 * time.Second)}}
|
||||
@@ -412,11 +412,11 @@ func TestTCDGetValue(t *testing.T) {
|
||||
if v := tcd.GetValue(); v != time.Duration((-1)*time.Nanosecond) {
|
||||
t.Errorf("wrong tcd value: %+v", v)
|
||||
}
|
||||
ev2 := &StatEvent{Tenant: "cgrates.org", ID: "EVENT_2",
|
||||
ev2 := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_2",
|
||||
Event: map[string]interface{}{
|
||||
"AnswerTime": time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
|
||||
"Usage": time.Duration(5 * time.Second)}}
|
||||
ev3 := &StatEvent{Tenant: "cgrates.org", ID: "EVENT_3"}
|
||||
ev3 := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_3"}
|
||||
tcd.AddEvent(ev2)
|
||||
tcd.AddEvent(ev3)
|
||||
if v := tcd.GetValue(); v != time.Duration(15*time.Second) {
|
||||
@@ -430,13 +430,13 @@ func TestTCDGetValue(t *testing.T) {
|
||||
if v := tcd.GetValue(); v != time.Duration((-1)*time.Nanosecond) {
|
||||
t.Errorf("wrong tcd value: %+v", v)
|
||||
}
|
||||
ev4 := &StatEvent{Tenant: "cgrates.org", ID: "EVENT_4",
|
||||
ev4 := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_4",
|
||||
Event: map[string]interface{}{
|
||||
"Usage": time.Duration(1 * time.Minute),
|
||||
"AnswerTime": time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
|
||||
},
|
||||
}
|
||||
ev5 := &StatEvent{Tenant: "cgrates.org", ID: "EVENT_5",
|
||||
ev5 := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_5",
|
||||
Event: map[string]interface{}{
|
||||
"Usage": time.Duration(1*time.Minute + 30*time.Second),
|
||||
"AnswerTime": time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
|
||||
@@ -460,7 +460,7 @@ func TestTCDGetValue(t *testing.T) {
|
||||
|
||||
func TestACCGetStringValue(t *testing.T) {
|
||||
acc, _ := NewACC(2)
|
||||
ev := &StatEvent{Tenant: "cgrates.org", ID: "EVENT_1",
|
||||
ev := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_1",
|
||||
Event: map[string]interface{}{
|
||||
"AnswerTime": time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
|
||||
"Cost": 12.3}}
|
||||
@@ -471,8 +471,8 @@ func TestACCGetStringValue(t *testing.T) {
|
||||
if strVal := acc.GetStringValue(""); strVal != utils.NOT_AVAILABLE {
|
||||
t.Errorf("wrong acc value: %s", strVal)
|
||||
}
|
||||
ev2 := &StatEvent{Tenant: "cgrates.org", ID: "EVENT_2"}
|
||||
ev3 := &StatEvent{Tenant: "cgrates.org", ID: "EVENT_3",
|
||||
ev2 := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_2"}
|
||||
ev3 := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_3",
|
||||
Event: map[string]interface{}{
|
||||
"AnswerTime": time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
|
||||
"Cost": 12.3}}
|
||||
@@ -485,11 +485,11 @@ func TestACCGetStringValue(t *testing.T) {
|
||||
if strVal := acc.GetStringValue(""); strVal != utils.NOT_AVAILABLE {
|
||||
t.Errorf("wrong acc value: %s", strVal)
|
||||
}
|
||||
ev4 := &StatEvent{Tenant: "cgrates.org", ID: "EVENT_4",
|
||||
ev4 := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_4",
|
||||
Event: map[string]interface{}{
|
||||
"AnswerTime": time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
|
||||
"Cost": 5.6}}
|
||||
ev5 := &StatEvent{Tenant: "cgrates.org", ID: "EVENT_5",
|
||||
ev5 := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_5",
|
||||
Event: map[string]interface{}{
|
||||
"AnswerTime": time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
|
||||
"Cost": 1.2}}
|
||||
@@ -512,7 +512,7 @@ func TestACCGetStringValue(t *testing.T) {
|
||||
|
||||
func TestACCGetValue(t *testing.T) {
|
||||
acc, _ := NewACC(2)
|
||||
ev := &StatEvent{Tenant: "cgrates.org", ID: "EVENT_1",
|
||||
ev := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_1",
|
||||
Event: map[string]interface{}{
|
||||
"AnswerTime": time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
|
||||
"Cost": "12.3"}}
|
||||
@@ -523,8 +523,8 @@ func TestACCGetValue(t *testing.T) {
|
||||
if strVal := acc.GetValue(); strVal != -1.0 {
|
||||
t.Errorf("wrong acc value: %v", strVal)
|
||||
}
|
||||
ev2 := &StatEvent{Tenant: "cgrates.org", ID: "EVENT_2"}
|
||||
ev3 := &StatEvent{Tenant: "cgrates.org", ID: "EVENT_3"}
|
||||
ev2 := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_2"}
|
||||
ev3 := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_3"}
|
||||
acc.AddEvent(ev2)
|
||||
acc.AddEvent(ev3)
|
||||
if strVal := acc.GetValue(); strVal != -1.0 {
|
||||
@@ -534,11 +534,11 @@ func TestACCGetValue(t *testing.T) {
|
||||
if strVal := acc.GetValue(); strVal != -1.0 {
|
||||
t.Errorf("wrong acc value: %v", strVal)
|
||||
}
|
||||
ev4 := &StatEvent{Tenant: "cgrates.org", ID: "EVENT_4",
|
||||
ev4 := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_4",
|
||||
Event: map[string]interface{}{
|
||||
"AnswerTime": time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
|
||||
"Cost": "5.6"}}
|
||||
ev5 := &StatEvent{Tenant: "cgrates.org", ID: "EVENT_5",
|
||||
ev5 := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_5",
|
||||
Event: map[string]interface{}{
|
||||
"AnswerTime": time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
|
||||
"Cost": "1.2"}}
|
||||
@@ -561,7 +561,7 @@ func TestACCGetValue(t *testing.T) {
|
||||
|
||||
func TestTCCGetStringValue(t *testing.T) {
|
||||
tcc, _ := NewTCC(2)
|
||||
ev := &StatEvent{Tenant: "cgrates.org", ID: "EVENT_1",
|
||||
ev := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_1",
|
||||
Event: map[string]interface{}{
|
||||
"AnswerTime": time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
|
||||
"Cost": 12.3}}
|
||||
@@ -572,8 +572,8 @@ func TestTCCGetStringValue(t *testing.T) {
|
||||
if strVal := tcc.GetStringValue(""); strVal != utils.NOT_AVAILABLE {
|
||||
t.Errorf("wrong tcc value: %s", strVal)
|
||||
}
|
||||
ev2 := &StatEvent{Tenant: "cgrates.org", ID: "EVENT_2"}
|
||||
ev3 := &StatEvent{Tenant: "cgrates.org", ID: "EVENT_3",
|
||||
ev2 := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_2"}
|
||||
ev3 := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_3",
|
||||
Event: map[string]interface{}{
|
||||
"AnswerTime": time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
|
||||
"Cost": 5.7}}
|
||||
@@ -586,11 +586,11 @@ func TestTCCGetStringValue(t *testing.T) {
|
||||
if strVal := tcc.GetStringValue(""); strVal != utils.NOT_AVAILABLE {
|
||||
t.Errorf("wrong tcc value: %s", strVal)
|
||||
}
|
||||
ev4 := &StatEvent{Tenant: "cgrates.org", ID: "EVENT_4",
|
||||
ev4 := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_4",
|
||||
Event: map[string]interface{}{
|
||||
"AnswerTime": time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
|
||||
"Cost": 5.6}}
|
||||
ev5 := &StatEvent{Tenant: "cgrates.org", ID: "EVENT_5",
|
||||
ev5 := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_5",
|
||||
Event: map[string]interface{}{
|
||||
"AnswerTime": time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
|
||||
"Cost": 1.2}}
|
||||
@@ -613,7 +613,7 @@ func TestTCCGetStringValue(t *testing.T) {
|
||||
|
||||
func TestTCCGetValue(t *testing.T) {
|
||||
tcc, _ := NewTCC(2)
|
||||
ev := &StatEvent{Tenant: "cgrates.org", ID: "EVENT_1",
|
||||
ev := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_1",
|
||||
Event: map[string]interface{}{
|
||||
"AnswerTime": time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
|
||||
"Cost": "12.3"}}
|
||||
@@ -624,8 +624,8 @@ func TestTCCGetValue(t *testing.T) {
|
||||
if strVal := tcc.GetValue(); strVal != -1.0 {
|
||||
t.Errorf("wrong tcc value: %v", strVal)
|
||||
}
|
||||
ev2 := &StatEvent{Tenant: "cgrates.org", ID: "EVENT_2"}
|
||||
ev3 := &StatEvent{Tenant: "cgrates.org", ID: "EVENT_3",
|
||||
ev2 := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_2"}
|
||||
ev3 := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_3",
|
||||
Event: map[string]interface{}{
|
||||
"AnswerTime": time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
|
||||
"Cost": 1.2}}
|
||||
@@ -638,11 +638,11 @@ func TestTCCGetValue(t *testing.T) {
|
||||
if strVal := tcc.GetValue(); strVal != -1.0 {
|
||||
t.Errorf("wrong tcc value: %v", strVal)
|
||||
}
|
||||
ev4 := &StatEvent{Tenant: "cgrates.org", ID: "EVENT_4",
|
||||
ev4 := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_4",
|
||||
Event: map[string]interface{}{
|
||||
"AnswerTime": time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
|
||||
"Cost": "5.6"}}
|
||||
ev5 := &StatEvent{Tenant: "cgrates.org", ID: "EVENT_5",
|
||||
ev5 := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_5",
|
||||
Event: map[string]interface{}{
|
||||
"AnswerTime": time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
|
||||
"Cost": "1.2"}}
|
||||
@@ -665,7 +665,7 @@ func TestTCCGetValue(t *testing.T) {
|
||||
|
||||
func TestPDDGetStringValue(t *testing.T) {
|
||||
pdd, _ := NewPDD(2)
|
||||
ev := &StatEvent{Tenant: "cgrates.org", ID: "EVENT_1",
|
||||
ev := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_1",
|
||||
Event: map[string]interface{}{
|
||||
utils.USAGE: time.Duration(10 * time.Second),
|
||||
"AnswerTime": time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
|
||||
@@ -678,8 +678,8 @@ func TestPDDGetStringValue(t *testing.T) {
|
||||
if strVal := pdd.GetStringValue(""); strVal != utils.NOT_AVAILABLE {
|
||||
t.Errorf("wrong pdd value: %s", strVal)
|
||||
}
|
||||
ev2 := &StatEvent{Tenant: "cgrates.org", ID: "EVENT_2"}
|
||||
ev3 := &StatEvent{Tenant: "cgrates.org", ID: "EVENT_3"}
|
||||
ev2 := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_2"}
|
||||
ev3 := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_3"}
|
||||
pdd.AddEvent(ev2)
|
||||
pdd.AddEvent(ev3)
|
||||
if strVal := pdd.GetStringValue(""); strVal != "1.666666666s" {
|
||||
@@ -693,14 +693,14 @@ func TestPDDGetStringValue(t *testing.T) {
|
||||
if strVal := pdd.GetStringValue(""); strVal != utils.NOT_AVAILABLE {
|
||||
t.Errorf("wrong pdd value: %s", strVal)
|
||||
}
|
||||
ev4 := &StatEvent{Tenant: "cgrates.org", ID: "EVENT_4",
|
||||
ev4 := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_4",
|
||||
Event: map[string]interface{}{
|
||||
"Usage": time.Duration(1 * time.Minute),
|
||||
"AnswerTime": time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
|
||||
utils.PDD: time.Duration(10 * time.Second),
|
||||
},
|
||||
}
|
||||
ev5 := &StatEvent{Tenant: "cgrates.org", ID: "EVENT_5",
|
||||
ev5 := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_5",
|
||||
Event: map[string]interface{}{
|
||||
utils.PDD: time.Duration(10 * time.Second),
|
||||
},
|
||||
@@ -727,7 +727,7 @@ func TestPDDGetStringValue(t *testing.T) {
|
||||
|
||||
func TestPDDGetFloat64Value(t *testing.T) {
|
||||
pdd, _ := NewPDD(2)
|
||||
ev := &StatEvent{Tenant: "cgrates.org", ID: "EVENT_1",
|
||||
ev := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_1",
|
||||
Event: map[string]interface{}{
|
||||
"AnswerTime": time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
|
||||
"Usage": time.Duration(10 * time.Second),
|
||||
@@ -736,19 +736,19 @@ func TestPDDGetFloat64Value(t *testing.T) {
|
||||
if v := pdd.GetFloat64Value(); v != -1.0 {
|
||||
t.Errorf("wrong pdd value: %v", v)
|
||||
}
|
||||
ev2 := &StatEvent{Tenant: "cgrates.org", ID: "EVENT_2"}
|
||||
ev2 := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_2"}
|
||||
pdd.AddEvent(ev2)
|
||||
if v := pdd.GetFloat64Value(); v != 2.5 {
|
||||
t.Errorf("wrong pdd value: %v", v)
|
||||
}
|
||||
ev4 := &StatEvent{Tenant: "cgrates.org", ID: "EVENT_4",
|
||||
ev4 := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_4",
|
||||
Event: map[string]interface{}{
|
||||
"Usage": time.Duration(1 * time.Minute),
|
||||
"AnswerTime": time.Date(2015, 7, 14, 14, 25, 0, 0, time.UTC),
|
||||
utils.PDD: time.Duration(10 * time.Second),
|
||||
},
|
||||
}
|
||||
ev5 := &StatEvent{Tenant: "cgrates.org", ID: "EVENT_5",
|
||||
ev5 := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_5",
|
||||
Event: map[string]interface{}{
|
||||
"Usage": time.Duration(1*time.Minute + 30*time.Second),
|
||||
"AnswerTime": time.Date(2015, 7, 14, 14, 25, 0, 0, time.UTC),
|
||||
@@ -782,7 +782,7 @@ func TestPDDGetFloat64Value(t *testing.T) {
|
||||
|
||||
func TestPDDGetValue(t *testing.T) {
|
||||
pdd, _ := NewPDD(2)
|
||||
ev := &StatEvent{Tenant: "cgrates.org", ID: "EVENT_1",
|
||||
ev := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_1",
|
||||
Event: map[string]interface{}{
|
||||
"AnswerTime": time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
|
||||
"Usage": time.Duration(10 * time.Second),
|
||||
@@ -791,12 +791,12 @@ func TestPDDGetValue(t *testing.T) {
|
||||
if v := pdd.GetValue(); v != time.Duration((-1)*time.Nanosecond) {
|
||||
t.Errorf("wrong pdd value: %+v", v)
|
||||
}
|
||||
ev2 := &StatEvent{Tenant: "cgrates.org", ID: "EVENT_2",
|
||||
ev2 := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_2",
|
||||
Event: map[string]interface{}{
|
||||
"AnswerTime": time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
|
||||
"Usage": time.Duration(8 * time.Second),
|
||||
utils.PDD: time.Duration(10 * time.Second)}}
|
||||
ev3 := &StatEvent{Tenant: "cgrates.org", ID: "EVENT_3"}
|
||||
ev3 := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_3"}
|
||||
pdd.AddEvent(ev2)
|
||||
pdd.AddEvent(ev3)
|
||||
if v := pdd.GetValue(); v != time.Duration(6333333333*time.Nanosecond) {
|
||||
@@ -810,14 +810,14 @@ func TestPDDGetValue(t *testing.T) {
|
||||
if v := pdd.GetValue(); v != time.Duration((-1)*time.Nanosecond) {
|
||||
t.Errorf("wrong pdd value: %+v", v)
|
||||
}
|
||||
ev4 := &StatEvent{Tenant: "cgrates.org", ID: "EVENT_4",
|
||||
ev4 := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_4",
|
||||
Event: map[string]interface{}{
|
||||
"Usage": time.Duration(1 * time.Minute),
|
||||
"AnswerTime": time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
|
||||
utils.PDD: time.Duration(8 * time.Second),
|
||||
},
|
||||
}
|
||||
ev5 := &StatEvent{Tenant: "cgrates.org", ID: "EVENT_5",
|
||||
ev5 := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_5",
|
||||
Event: map[string]interface{}{
|
||||
"Usage": time.Duration(4*time.Minute + 30*time.Second),
|
||||
"AnswerTime": time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
|
||||
@@ -841,7 +841,7 @@ func TestPDDGetValue(t *testing.T) {
|
||||
|
||||
func TestDDCGetStringValue(t *testing.T) {
|
||||
ddc, _ := NewDCC(2)
|
||||
ev := &StatEvent{Tenant: "cgrates.org", ID: "EVENT_1",
|
||||
ev := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_1",
|
||||
Event: map[string]interface{}{
|
||||
"AnswerTime": time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
|
||||
utils.DESTINATION: "1002"}}
|
||||
@@ -853,12 +853,12 @@ func TestDDCGetStringValue(t *testing.T) {
|
||||
if strVal := ddc.GetStringValue(""); strVal != utils.NOT_AVAILABLE {
|
||||
t.Errorf("wrong ddc value: %s", strVal)
|
||||
}
|
||||
ev2 := &StatEvent{Tenant: "cgrates.org", ID: "EVENT_2",
|
||||
ev2 := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_2",
|
||||
Event: map[string]interface{}{
|
||||
"AnswerTime": time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
|
||||
utils.DESTINATION: "1002"}}
|
||||
|
||||
ev3 := &StatEvent{Tenant: "cgrates.org", ID: "EVENT_3",
|
||||
ev3 := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_3",
|
||||
Event: map[string]interface{}{
|
||||
"AnswerTime": time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
|
||||
utils.DESTINATION: "1001"}}
|
||||
@@ -883,7 +883,7 @@ func TestDDCGetStringValue(t *testing.T) {
|
||||
|
||||
func TestDDCGetFloat64Value(t *testing.T) {
|
||||
ddc, _ := NewDCC(2)
|
||||
ev := &StatEvent{Tenant: "cgrates.org", ID: "EVENT_1",
|
||||
ev := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_1",
|
||||
Event: map[string]interface{}{
|
||||
"AnswerTime": time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
|
||||
"Usage": time.Duration(10 * time.Second),
|
||||
@@ -893,12 +893,12 @@ func TestDDCGetFloat64Value(t *testing.T) {
|
||||
if v := ddc.GetFloat64Value(); v != -1.0 {
|
||||
t.Errorf("wrong ddc value: %v", v)
|
||||
}
|
||||
ev2 := &StatEvent{Tenant: "cgrates.org", ID: "EVENT_2"}
|
||||
ev2 := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_2"}
|
||||
ddc.AddEvent(ev2)
|
||||
if v := ddc.GetFloat64Value(); v != -1.0 {
|
||||
t.Errorf("wrong ddc value: %v", v)
|
||||
}
|
||||
ev4 := &StatEvent{Tenant: "cgrates.org", ID: "EVENT_4",
|
||||
ev4 := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_4",
|
||||
Event: map[string]interface{}{
|
||||
"Usage": time.Duration(1 * time.Minute),
|
||||
"AnswerTime": time.Date(2015, 7, 14, 14, 25, 0, 0, time.UTC),
|
||||
@@ -906,7 +906,7 @@ func TestDDCGetFloat64Value(t *testing.T) {
|
||||
utils.DESTINATION: "1001",
|
||||
},
|
||||
}
|
||||
ev5 := &StatEvent{Tenant: "cgrates.org", ID: "EVENT_5",
|
||||
ev5 := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_5",
|
||||
Event: map[string]interface{}{
|
||||
"Usage": time.Duration(1*time.Minute + 30*time.Second),
|
||||
"AnswerTime": time.Date(2015, 7, 14, 14, 25, 0, 0, time.UTC),
|
||||
|
||||
@@ -139,7 +139,7 @@ func (sS *StatService) StoreStatQueue(sq *StatQueue) (err error) {
|
||||
}
|
||||
|
||||
// matchingStatQueuesForEvent returns ordered list of matching resources which are active by the time of the call
|
||||
func (sS *StatService) matchingStatQueuesForEvent(ev *StatEvent) (sqs StatQueues, err error) {
|
||||
func (sS *StatService) matchingStatQueuesForEvent(ev *utils.CGREvent) (sqs StatQueues, err error) {
|
||||
matchingSQs := make(map[string]*StatQueue)
|
||||
sqIDs, err := matchingItemIDsForEvent(ev.Event, sS.indexedFields, sS.dm, utils.StatQueuesStringIndex+ev.Tenant)
|
||||
if err != nil {
|
||||
@@ -203,7 +203,7 @@ func (ss *StatService) Call(serviceMethod string, args interface{}, reply interf
|
||||
|
||||
// processEvent processes a new event, dispatching to matching queues
|
||||
// queues matching are also cached to speed up
|
||||
func (sS *StatService) processEvent(ev *StatEvent) (err error) {
|
||||
func (sS *StatService) processEvent(ev *utils.CGREvent) (err error) {
|
||||
matchSQs, err := sS.matchingStatQueuesForEvent(ev)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -255,7 +255,7 @@ func (sS *StatService) processEvent(ev *StatEvent) (err error) {
|
||||
}
|
||||
|
||||
// V1ProcessEvent implements StatV1 method for processing an Event
|
||||
func (sS *StatService) V1ProcessEvent(ev *StatEvent, reply *string) (err error) {
|
||||
func (sS *StatService) V1ProcessEvent(ev *utils.CGREvent, reply *string) (err error) {
|
||||
if missing := utils.MissingStructFields(ev, []string{"Tenant", "ID"}); len(missing) != 0 { //Params missing
|
||||
return utils.NewErrMandatoryIeMissing(missing...)
|
||||
}
|
||||
@@ -266,7 +266,7 @@ func (sS *StatService) V1ProcessEvent(ev *StatEvent, reply *string) (err error)
|
||||
}
|
||||
|
||||
// V1StatQueuesForEvent implements StatV1 method for processing an Event
|
||||
func (sS *StatService) V1GetStatQueuesForEvent(ev *StatEvent, reply *StatQueues) (err error) {
|
||||
func (sS *StatService) V1GetStatQueuesForEvent(ev *utils.CGREvent, reply *StatQueues) (err error) {
|
||||
if missing := utils.MissingStructFields(ev, []string{"Tenant", "ID"}); len(missing) != 0 { //Params missing
|
||||
return utils.NewErrMandatoryIeMissing(missing...)
|
||||
}
|
||||
|
||||
@@ -73,7 +73,7 @@ func (t *Threshold) ProcessEvent(ev *utils.CGREvent, dm *DataManager) (err error
|
||||
if t.Hits < t.tPrfl.MinHits { // number of hits was not met, will not execute actions
|
||||
return
|
||||
}
|
||||
acnt, _ := ev.utils.FieldAsString(utils.ACCOUNT)
|
||||
acnt, _ := ev.FieldAsString(utils.ACCOUNT)
|
||||
var acntID string
|
||||
if acnt != "" {
|
||||
acntID = utils.ConcatenatedKey(ev.Tenant, acnt)
|
||||
|
||||
@@ -21,6 +21,7 @@ package utils
|
||||
import (
|
||||
"fmt"
|
||||
"reflect"
|
||||
"strconv"
|
||||
"time"
|
||||
)
|
||||
|
||||
@@ -40,7 +41,7 @@ func (ev *CGREvent) CheckMandatoryFields(fldNames []string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// AnswerTime returns the AnswerTime of CGREvent
|
||||
// AnswerTime returns a field as string instance
|
||||
func (ev *CGREvent) FieldAsString(fldName string) (val string, err error) {
|
||||
iface, has := ev.Event[fldName]
|
||||
if !has {
|
||||
@@ -53,7 +54,7 @@ func (ev *CGREvent) FieldAsString(fldName string) (val string, err error) {
|
||||
return val, nil
|
||||
}
|
||||
|
||||
// FieldAsTime returns the a field as Time instance
|
||||
// FieldAsTime returns a field as Time instance
|
||||
func (ev *CGREvent) FieldAsTime(fldName string, timezone string) (t time.Time, err error) {
|
||||
iface, has := ev.Event[fldName]
|
||||
if !has {
|
||||
@@ -72,7 +73,7 @@ func (ev *CGREvent) FieldAsTime(fldName string, timezone string) (t time.Time, e
|
||||
return ParseTimeDetectLayout(s, timezone)
|
||||
}
|
||||
|
||||
// FieldAsTime returns the a field as Time instance
|
||||
// FieldAsTime returns a field as Duration instance
|
||||
func (ev *CGREvent) FieldAsDuration(fldName string) (d time.Duration, err error) {
|
||||
iface, has := ev.Event[fldName]
|
||||
if !has {
|
||||
@@ -91,22 +92,39 @@ func (ev *CGREvent) FieldAsDuration(fldName string) (d time.Duration, err error)
|
||||
return ParseDurationWithNanosecs(s)
|
||||
}
|
||||
|
||||
func (te *CGREvent) TenantID() string {
|
||||
return ConcatenatedKey(te.Tenant, te.ID)
|
||||
// FieldAsFloat returns a field as float64 instance
|
||||
func (ev *CGREvent) FieldAsFloat64(fldName string) (f float64, err error) {
|
||||
iface, has := ev.Event[fldName]
|
||||
if !has {
|
||||
return f, ErrNotFound
|
||||
}
|
||||
if val, canCast := iface.(float64); canCast {
|
||||
return val, nil
|
||||
}
|
||||
csStr, canCast := iface.(string)
|
||||
if !canCast {
|
||||
err = fmt.Errorf("cannot cast %s to string", fldName)
|
||||
return
|
||||
}
|
||||
return strconv.ParseFloat(csStr, 64)
|
||||
}
|
||||
|
||||
func (te *CGREvent) FilterableEvent(fltredFields []string) (fEv map[string]interface{}) {
|
||||
func (ev *CGREvent) TenantID() string {
|
||||
return ConcatenatedKey(ev.Tenant, ev.ID)
|
||||
}
|
||||
|
||||
func (ev *CGREvent) FilterableEvent(fltredFields []string) (fEv map[string]interface{}) {
|
||||
fEv = make(map[string]interface{})
|
||||
if len(fltredFields) == 0 {
|
||||
i := 0
|
||||
fltredFields = make([]string, len(te.Event))
|
||||
for k := range te.Event {
|
||||
fltredFields = make([]string, len(ev.Event))
|
||||
for k := range ev.Event {
|
||||
fltredFields[i] = k
|
||||
i++
|
||||
}
|
||||
}
|
||||
for _, fltrFld := range fltredFields {
|
||||
fldVal, has := te.Event[fltrFld]
|
||||
fldVal, has := ev.Event[fltrFld]
|
||||
if !has {
|
||||
continue // the field does not exist in map, ignore it
|
||||
}
|
||||
|
||||
@@ -114,3 +114,5 @@ func TestCGREventFieldAsString(t *testing.T) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", event["Weight"], answ)
|
||||
}
|
||||
}
|
||||
|
||||
//float , float in string time duration
|
||||
|
||||
Reference in New Issue
Block a user