mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-24 16:48:45 +05:00
@@ -75,7 +75,7 @@ func (se StatEvent) AnswerTime(timezone string) (at time.Time, err error) {
|
||||
}
|
||||
|
||||
// Usage returns the Usage of StatEvent
|
||||
func (se StatEvent) Usage(timezone string) (at time.Duration, err error) {
|
||||
func (se StatEvent) Usage() (at time.Duration, err error) {
|
||||
usIf, has := se.Fields[utils.USAGE]
|
||||
if !has {
|
||||
return at, utils.ErrNotFound
|
||||
@@ -94,7 +94,7 @@ func (se StatEvent) Usage(timezone string) (at time.Duration, err error) {
|
||||
}
|
||||
|
||||
// Cost returns the Cost of StatEvent
|
||||
func (se StatEvent) Cost(timezone string) (cs float64, err error) {
|
||||
func (se StatEvent) Cost() (cs float64, err error) {
|
||||
csIf, has := se.Fields[utils.COST]
|
||||
if !has {
|
||||
return cs, utils.ErrNotFound
|
||||
@@ -110,7 +110,7 @@ func (se StatEvent) Cost(timezone string) (cs float64, err error) {
|
||||
}
|
||||
|
||||
// Pdd returns the Pdd of StatEvent
|
||||
func (se StatEvent) Pdd(timezone string) (pdd time.Duration, err error) {
|
||||
func (se StatEvent) Pdd() (pdd time.Duration, err error) {
|
||||
pddIf, has := se.Fields[utils.PDD]
|
||||
if !has {
|
||||
return pdd, utils.ErrNotFound
|
||||
@@ -129,7 +129,7 @@ func (se StatEvent) Pdd(timezone string) (pdd time.Duration, err error) {
|
||||
}
|
||||
|
||||
// Destination returns the Destination of StatEvent
|
||||
func (se StatEvent) Destination(timezone string) (ddc string, err error) {
|
||||
func (se StatEvent) Destination() (ddc string, err error) {
|
||||
ddcIf, has := se.Fields[utils.DESTINATION]
|
||||
if !has {
|
||||
return ddc, utils.ErrNotFound
|
||||
|
||||
@@ -186,7 +186,7 @@ func (acd *StatACD) AddEvent(ev *StatEvent) (err error) {
|
||||
if at, err := ev.AnswerTime(config.CgrConfig().DefaultTimezone); err != nil {
|
||||
return err
|
||||
} else if !at.IsZero() {
|
||||
if duration, err := ev.Usage(config.CgrConfig().DefaultTimezone); err != nil &&
|
||||
if duration, err := ev.Usage(); err != nil &&
|
||||
err != utils.ErrNotFound {
|
||||
return err
|
||||
} else {
|
||||
@@ -268,7 +268,7 @@ func (tcd *StatTCD) AddEvent(ev *StatEvent) (err error) {
|
||||
if at, err := ev.AnswerTime(config.CgrConfig().DefaultTimezone); err != nil {
|
||||
return err
|
||||
} else if !at.IsZero() {
|
||||
if duration, err := ev.Usage(config.CgrConfig().DefaultTimezone); err != nil &&
|
||||
if duration, err := ev.Usage(); err != nil &&
|
||||
err != utils.ErrNotFound {
|
||||
return err
|
||||
} else {
|
||||
@@ -351,7 +351,7 @@ func (acc *StatACC) AddEvent(ev *StatEvent) (err error) {
|
||||
if at, err := ev.AnswerTime(config.CgrConfig().DefaultTimezone); err != nil {
|
||||
return err
|
||||
} else if !at.IsZero() {
|
||||
if cost, err := ev.Cost(config.CgrConfig().DefaultTimezone); err != nil &&
|
||||
if cost, err := ev.Cost(); err != nil &&
|
||||
err != utils.ErrNotFound {
|
||||
return err
|
||||
} else if cost >= 0 {
|
||||
@@ -432,7 +432,7 @@ func (tcc *StatTCC) AddEvent(ev *StatEvent) (err error) {
|
||||
if at, err := ev.AnswerTime(config.CgrConfig().DefaultTimezone); err != nil {
|
||||
return err
|
||||
} else if !at.IsZero() {
|
||||
if cost, err := ev.Cost(config.CgrConfig().DefaultTimezone); err != nil &&
|
||||
if cost, err := ev.Cost(); err != nil &&
|
||||
err != utils.ErrNotFound {
|
||||
return err
|
||||
} else if cost >= 0 {
|
||||
@@ -516,7 +516,7 @@ func (pdd *StatPDD) AddEvent(ev *StatEvent) (err error) {
|
||||
err != utils.ErrNotFound {
|
||||
return err
|
||||
} else if !at.IsZero() {
|
||||
if duration, err := ev.Pdd(config.CgrConfig().DefaultTimezone); err != nil &&
|
||||
if duration, err := ev.Pdd(); err != nil &&
|
||||
err != utils.ErrNotFound {
|
||||
return err
|
||||
} else {
|
||||
@@ -555,6 +555,7 @@ func NewDCC() (StatMetric, error) {
|
||||
return &StatDDC{Destinations: make(map[string]utils.StringMap), EventDestinations: make(map[string]string)}, nil
|
||||
}
|
||||
|
||||
// DDC implements Destination Distinct Count metric
|
||||
type StatDDC struct {
|
||||
Destinations map[string]utils.StringMap
|
||||
EventDestinations map[string]string // map[EventTenantID]Destination
|
||||
@@ -580,20 +581,13 @@ func (ddc *StatDDC) GetFloat64Value() (v float64) {
|
||||
|
||||
func (ddc *StatDDC) AddEvent(ev *StatEvent) (err error) {
|
||||
var dest string
|
||||
if at, err := ev.AnswerTime(config.CgrConfig().DefaultTimezone); err != nil &&
|
||||
err != utils.ErrNotFound {
|
||||
if dest, err = ev.Destination(); err != nil {
|
||||
return err
|
||||
} else if !at.IsZero() {
|
||||
if destination, err := ev.Destination(config.CgrConfig().DefaultTimezone); err != nil {
|
||||
return err
|
||||
} else {
|
||||
dest = destination
|
||||
if _, has := ddc.Destinations[dest]; !has {
|
||||
ddc.Destinations[dest] = make(map[string]bool)
|
||||
}
|
||||
ddc.Destinations[dest][ev.TenantID()] = true
|
||||
}
|
||||
}
|
||||
if _, has := ddc.Destinations[dest]; !has {
|
||||
ddc.Destinations[dest] = make(map[string]bool)
|
||||
}
|
||||
ddc.Destinations[dest][ev.TenantID()] = true
|
||||
ddc.EventDestinations[ev.TenantID()] = dest
|
||||
return
|
||||
}
|
||||
@@ -603,13 +597,12 @@ func (ddc *StatDDC) RemEvent(evTenantID string) (err error) {
|
||||
if !has {
|
||||
return utils.ErrNotFound
|
||||
}
|
||||
delete(ddc.EventDestinations, evTenantID)
|
||||
if len(ddc.Destinations[destination]) == 1 {
|
||||
delete(ddc.Destinations, destination)
|
||||
} else {
|
||||
delete(ddc.Destinations[destination], evTenantID)
|
||||
return
|
||||
}
|
||||
|
||||
delete(ddc.EventDestinations, evTenantID)
|
||||
delete(ddc.Destinations[destination], evTenantID)
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user