mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-25 09:08:45 +05:00
Adding LastUsed in SMGEvent, SMG logic to follow
This commit is contained in:
@@ -161,6 +161,14 @@ func (self SMGenericEvent) GetUsage(fieldName string) (time.Duration, error) {
|
||||
return utils.ParseDurationWithSecs(result)
|
||||
}
|
||||
|
||||
func (self SMGenericEvent) GetLastUsed(fieldName string) (time.Duration, error) {
|
||||
if fieldName == utils.META_DEFAULT {
|
||||
fieldName = utils.LastUsed
|
||||
}
|
||||
result, _ := utils.ConvertIfaceToString(self[fieldName])
|
||||
return utils.ParseDurationWithSecs(result)
|
||||
}
|
||||
|
||||
func (self SMGenericEvent) GetMaxUsage(fieldName string, cfgMaxUsage time.Duration) (time.Duration, error) {
|
||||
if fieldName == utils.META_DEFAULT {
|
||||
fieldName = utils.USAGE
|
||||
@@ -212,7 +220,7 @@ func (self SMGenericEvent) GetCdrSource() string {
|
||||
func (self SMGenericEvent) GetExtraFields() map[string]string {
|
||||
extraFields := make(map[string]string)
|
||||
for key, val := range self {
|
||||
primaryFields := append(utils.PrimaryCdrFields, utils.EVENT_NAME)
|
||||
primaryFields := append(utils.PrimaryCdrFields, utils.EVENT_NAME, utils.LastUsed)
|
||||
if utils.IsSliceMember(primaryFields, key) {
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -45,6 +45,7 @@ func TestSMGenericEventParseFields(t *testing.T) {
|
||||
smGev[utils.SETUP_TIME] = "2015-11-09 14:21:24"
|
||||
smGev[utils.ANSWER_TIME] = "2015-11-09 14:22:02"
|
||||
smGev[utils.USAGE] = "1m23s"
|
||||
smGev[utils.LastUsed] = "21s"
|
||||
smGev[utils.PDD] = "300ms"
|
||||
smGev[utils.SUPPLIER] = "supplier1"
|
||||
smGev[utils.DISCONNECT_CAUSE] = "NORMAL_DISCONNECT"
|
||||
@@ -107,6 +108,11 @@ func TestSMGenericEventParseFields(t *testing.T) {
|
||||
} else if dur != time.Duration(83)*time.Second {
|
||||
t.Error("Unexpected: ", dur)
|
||||
}
|
||||
if lastUsed, err := smGev.GetLastUsed(utils.META_DEFAULT); err != nil {
|
||||
t.Error(err)
|
||||
} else if lastUsed != time.Duration(21)*time.Second {
|
||||
t.Error("Unexpected: ", lastUsed)
|
||||
}
|
||||
if pdd, err := smGev.GetPdd(utils.META_DEFAULT); err != nil {
|
||||
t.Error(err)
|
||||
} else if pdd != time.Duration(300)*time.Millisecond {
|
||||
|
||||
@@ -124,6 +124,7 @@ const (
|
||||
SETUP_TIME = "SetupTime"
|
||||
ANSWER_TIME = "AnswerTime"
|
||||
USAGE = "Usage"
|
||||
LastUsed = "LastUsed"
|
||||
PDD = "PDD"
|
||||
SUPPLIER = "Supplier"
|
||||
MEDI_RUNID = "RunID"
|
||||
|
||||
Reference in New Issue
Block a user