Adding PddInterval in CdrStats

This commit is contained in:
DanB
2015-06-08 16:16:22 +02:00
parent 05a522a64c
commit aa4cd62a7f
12 changed files with 92 additions and 58 deletions

View File

@@ -198,12 +198,12 @@ vdf,emptyY,*out,TOPUP_EMPTY_AT,
*out,cgrates.org,call,dan,*any,extra1,,,,,,rif2,rif2,,,,,,
`
cdrStats = `
#Id[0],QueueLength[1],TimeWindow[2],Metric[3],SetupInterval[4],TOR[5],CdrHost[6],CdrSource[7],ReqType[8],Direction[9],Tenant[10],Category[11],Account[12],Subject[13],DestinationPrefix[14],UsageInterval[15],Supplier[16],DisconnectCause[17],MediationRunIds[18],RatedAccount[19],RatedSubject[20],CostInterval[21],Triggers[22]
CDRST1,5,60m,ASR,2014-07-29T15:00:00Z;2014-07-29T16:00:00Z,*voice,87.139.12.167,FS_JSON,*rated,*out,cgrates.org,call,dan,dan,49,5m;10m,suppl1,NORMAL_CLEARING,default,rif,rif,0;2,STANDARD_TRIGGERS
CDRST1,,,ACD,,,,,,,,,,,,,,,,,,,STANDARD_TRIGGER
CDRST1,,,ACC,,,,,,,,,,,,,,,,,,,
CDRST2,10,10m,ASR,,,,,,,cgrates.org,call,,,,,,,,,,,
CDRST2,,,ACD,,,,,,,,,,,,,,,,,,,
#Id[0],QueueLength[1],TimeWindow[2],Metric[3],SetupInterval[4],TOR[5],CdrHost[6],CdrSource[7],ReqType[8],Direction[9],Tenant[10],Category[11],Account[12],Subject[13],DestinationPrefix[14],PddInterval[15],UsageInterval[16],Supplier[17],DisconnectCause[18],MediationRunIds[19],RatedAccount[20],RatedSubject[21],CostInterval[22],Triggers[23]CDRST1,5,60m,ASR,2014-07-29T15:00:00Z;2014-07-29T16:00:00Z,*voice,87.139.12.167,FS_JSON,*rated,*out,cgrates.org,call,dan,dan,49,5m;10m,suppl1,NORMAL_CLEARING,default,rif,rif,0;2,STANDARD_TRIGGERS
CDRST1,5,60m,ASR,2014-07-29T15:00:00Z;2014-07-29T16:00:00Z,*voice,87.139.12.167,FS_JSON,*rated,*out,cgrates.org,call,dan,dan,49,3m;7m,5m;10m,suppl1,NORMAL_CLEARING,default,rif,rif,0;2,STANDARD_TRIGGERS
CDRST1,,,ACD,,,,,,,,,,,,,,,,,,,,STANDARD_TRIGGER
CDRST1,,,ACC,,,,,,,,,,,,,,,,,,,,
CDRST2,10,10m,ASR,,,,,,,cgrates.org,call,,,,,,,,,,,,
CDRST2,,,ACD,,,,,,,,,,,,,,,,,,,,
`
)
@@ -1063,6 +1063,7 @@ func TestLoadCdrStats(t *testing.T) {
Account: []string{"dan"},
Subject: []string{"dan"},
DestinationPrefix: []string{"49"},
PddInterval: []time.Duration{3 * time.Minute, 7 * time.Minute},
UsageInterval: []time.Duration{5 * time.Minute, 10 * time.Minute},
Supplier: []string{"suppl1"},
DisconnectCause: []string{"NORMAL_CLEARING"},

View File

@@ -336,6 +336,7 @@ func APItoModelCdrStat(stats *utils.TPCdrStats) (result []TpCdrstat) {
Accounts: st.Accounts,
Subjects: st.Subjects,
DestinationPrefixes: st.DestinationPrefixes,
PddInterval: st.PddInterval,
UsageInterval: st.UsageInterval,
Suppliers: st.Suppliers,
DisconnectCauses: st.DisconnectCauses,

View File

@@ -516,6 +516,7 @@ func (tps TpCdrStats) GetCdrStats() (map[string][]*utils.TPCdrStat, error) {
Accounts: tpCs.Accounts,
Subjects: tpCs.Subjects,
DestinationPrefixes: tpCs.DestinationPrefixes,
PddInterval: tpCs.PddInterval,
UsageInterval: tpCs.UsageInterval,
Suppliers: tpCs.Suppliers,
DisconnectCauses: tpCs.DisconnectCauses,
@@ -602,6 +603,31 @@ func UpdateCdrStats(cs *CdrStats, triggers ActionTriggerPriotityList, tpCs *util
if tpCs.DestinationPrefixes != "" {
cs.DestinationPrefix = append(cs.DestinationPrefix, tpCs.DestinationPrefixes)
}
if tpCs.PddInterval != "" {
pdds := strings.Split(tpCs.PddInterval, utils.INFIELD_SEP)
if len(pdds) > 0 {
if sPdd, err := time.ParseDuration(pdds[0]); err == nil {
if len(cs.PddInterval) < 1 {
cs.PddInterval = append(cs.PddInterval, sPdd)
} else {
cs.PddInterval[0] = sPdd
}
} else {
log.Printf("Error parsing PddInterval %v for cdrs stats %v", tpCs.PddInterval, cs.Id)
}
}
if len(pdds) > 1 {
if ePdd, err := time.ParseDuration(pdds[1]); err == nil {
if len(cs.PddInterval) < 2 {
cs.PddInterval = append(cs.PddInterval, ePdd)
} else {
cs.PddInterval[1] = ePdd
}
} else {
log.Printf("Error parsing UsageInterval %v for cdrs stats %v", tpCs.PddInterval, cs.Id)
}
}
}
if tpCs.UsageInterval != "" {
durations := strings.Split(tpCs.UsageInterval, utils.INFIELD_SEP)
if len(durations) > 0 {

View File

@@ -9,16 +9,16 @@ import (
func TestModelHelperCsvLoad(t *testing.T) {
l, err := csvLoad(TpDestination{}, []string{"TEST_DEST", "+492"})
tpd := l.(TpDestination)
if err != nil || tpd.Tag != "TEST_DEST" || tpd.Prefix != "+492" {
tpd, ok := l.(TpDestination)
if err != nil || !ok || tpd.Tag != "TEST_DEST" || tpd.Prefix != "+492" {
t.Errorf("model load failed: %+v", tpd)
}
}
func TestModelHelperCsvLoadInt(t *testing.T) {
l, err := csvLoad(TpCdrstat{}, []string{"CDRST1", "5", "60m", "ASR", "2014-07-29T15:00:00Z;2014-07-29T16:00:00Z", "*voice", "87.139.12.167", "FS_JSON", "*rated", "*out", "cgrates.org", "call", "dan", "dan", "49", "5m;10m", "suppl1", "NORMAL_CLEARING", "default", "rif", "rif", "0;2", "STANDARD_TRIGGERS"})
tpd := l.(TpCdrstat)
if err != nil || tpd.QueueLength != 5 {
l, err := csvLoad(TpCdrstat{}, []string{"CDRST1", "5", "60m", "ASR", "2014-07-29T15:00:00Z;2014-07-29T16:00:00Z", "*voice", "87.139.12.167", "FS_JSON", "*rated", "*out", "cgrates.org", "call", "dan", "dan", "49", "3m;7m", "5m;10m", "suppl1", "NORMAL_CLEARING", "default", "rif", "rif", "0;2", "STANDARD_TRIGGERS"})
tpd, ok := l.(TpCdrstat)
if err != nil || !ok || tpd.QueueLength != 5 {
t.Errorf("model load failed: %+v", tpd)
}
}
@@ -389,6 +389,7 @@ func TestTPCdrStatsAsExportSlice(t *testing.T) {
Accounts: "dan",
Subjects: "dan",
DestinationPrefixes: "49",
PddInterval: "3m;7m",
UsageInterval: "5m;10m",
Suppliers: "supplier1",
DisconnectCauses: "NORMAL_CLEARNING",
@@ -412,6 +413,7 @@ func TestTPCdrStatsAsExportSlice(t *testing.T) {
Accounts: "dan",
Subjects: "dan",
DestinationPrefixes: "49",
PddInterval: "3m;7m",
UsageInterval: "5m;10m",
Suppliers: "supplier1",
DisconnectCauses: "NORMAL_CLEARNING",
@@ -424,9 +426,9 @@ func TestTPCdrStatsAsExportSlice(t *testing.T) {
}
expectedSlc := [][]string{
[]string{"CDRST1", "5", "60m", "ASR;ACD", "2014-07-29T15:00:00Z;2014-07-29T16:00:00Z", "*voice", "87.139.12.167", "FS_JSON", utils.META_RATED, "*out", "cgrates.org", "call",
"dan", "dan", "49", "5m;10m", "supplier1", "NORMAL_CLEARNING", "default", "rif", "rif", "0;2", "STANDARD_TRIGGERS"},
"dan", "dan", "49", "3m;7m", "5m;10m", "supplier1", "NORMAL_CLEARNING", "default", "rif", "rif", "0;2", "STANDARD_TRIGGERS"},
[]string{"CDRST1", "5", "60m", "ASR", "2014-07-29T15:00:00Z;2014-07-29T16:00:00Z", "*voice", "87.139.12.167", "FS_JSON", utils.META_RATED, "*out", "cgrates.org", "call",
"dan", "dan", "49", "5m;10m", "supplier1", "NORMAL_CLEARNING", "default", "dan", "dan", "0;2", "STANDARD_TRIGGERS"},
"dan", "dan", "49", "3m;7m", "5m;10m", "supplier1", "NORMAL_CLEARNING", "default", "dan", "dan", "0;2", "STANDARD_TRIGGERS"},
}
ms := APItoModelCdrStat(cdrStats)
var slc [][]string

View File

@@ -306,14 +306,15 @@ type TpCdrstat struct {
Accounts string `index:"12" re:""`
Subjects string `index:"13" re:""`
DestinationPrefixes string `index:"14" re:""`
UsageInterval string `index:"15" re:""`
Suppliers string `index:"16" re:""`
DisconnectCauses string `index:"17" re:""`
MediationRunids string `index:"18" re:""`
RatedAccounts string `index:"19" re:""`
RatedSubjects string `index:"20" re:""`
CostInterval string `index:"21" re:""`
ActionTriggers string `index:"22" re:""`
PddInterval string `index:"15" re:""`
UsageInterval string `index:"16" re:""`
Suppliers string `index:"17" re:""`
DisconnectCauses string `index:"18" re:""`
MediationRunids string `index:"19" re:""`
RatedAccounts string `index:"20" re:""`
RatedSubjects string `index:"21" re:""`
CostInterval string `index:"22" re:""`
ActionTriggers string `index:"23" re:""`
CreatedAt time.Time
}

View File

@@ -73,9 +73,9 @@ type StoredCdr struct {
Subject string // rating subject (rating subsystem) this record should be attached to
Destination string // destination to be charged
SetupTime time.Time // set-up time of the event. Supported formats: datetime RFC3339 compatible, SQL datetime (eg: MySQL), unix timestamp.
Pdd time.Duration // PDD value
AnswerTime time.Time // answer time of the event. Supported formats: datetime RFC3339 compatible, SQL datetime (eg: MySQL), unix timestamp.
Usage time.Duration // event usage information (eg: in case of tor=*voice this will represent the total duration of a call)
Pdd time.Duration // PDD value
Supplier string // Supplier information when available
DisconnectCause string // Disconnect cause of the event
ExtraFields map[string]string // Extra fields to be stored in CDR