From eb57017632184d5994de3f46dde8d00dfc830c86 Mon Sep 17 00:00:00 2001 From: Trial97 Date: Tue, 3 Nov 2020 17:11:40 +0200 Subject: [PATCH] Updated stats metrics --- cmd/cgr-engine/cgr-engine.go | 2 +- engine/libstats.go | 17 +- engine/libstats_test.go | 43 +-- engine/statmetrics.go | 253 +++++++------- engine/statmetrics_test.go | 628 +++++++++++++++++------------------ engine/stats.go | 6 +- utils/concureqs.go | 65 +++- utils/consts.go | 1 + 8 files changed, 539 insertions(+), 476 deletions(-) diff --git a/cmd/cgr-engine/cgr-engine.go b/cmd/cgr-engine/cgr-engine.go index 4662c3bf2..b4e7206a9 100644 --- a/cmd/cgr-engine/cgr-engine.go +++ b/cmd/cgr-engine/cgr-engine.go @@ -458,7 +458,7 @@ func main() { if len(utils.ConcurrentReqsStrategy) != 0 { cncReqsStrategy = utils.ConcurrentReqsStrategy } - conReqs := utils.NewConReqs(cncReqsLimit, cncReqsStrategy) + conReqs := utils.NewConReqs(cncReqsLimit, cncReqsStrategy, 0, 0, exitChan) utils.Logger.Info(fmt.Sprintf(" starting version <%s><%s>", vers, goVers)) cfg.LazySanityCheck() diff --git a/engine/libstats.go b/engine/libstats.go index fe5d1059e..1f71f3120 100644 --- a/engine/libstats.go +++ b/engine/libstats.go @@ -68,12 +68,13 @@ type MetricWithFilters struct { // NewStoredStatQueue initiates a StoredStatQueue out of StatQueue func NewStoredStatQueue(sq *StatQueue, ms Marshaler) (sSQ *StoredStatQueue, err error) { sSQ = &StoredStatQueue{ - Tenant: sq.Tenant, - ID: sq.ID, - Compressed: sq.Compress(int64(config.CgrConfig().StatSCfg().StoreUncompressedLimit)), - SQItems: make([]SQItem, len(sq.SQItems)), - SQMetrics: make(map[string][]byte, len(sq.SQMetrics)), - MinItems: sq.MinItems, + Tenant: sq.Tenant, + ID: sq.ID, + Compressed: sq.Compress(int64(config.CgrConfig().StatSCfg().StoreUncompressedLimit), + config.CgrConfig().GeneralCfg().RoundingDecimals), + SQItems: make([]SQItem, len(sq.SQItems)), + SQMetrics: make(map[string][]byte, len(sq.SQMetrics)), + MinItems: sq.MinItems, } for i, sqItm := range sq.SQItems { sSQ.SQItems[i] = sqItm @@ -263,7 +264,7 @@ func (sq *StatQueue) addStatEvent(tnt, evID string, filterS *FilterS, evNm utils return } -func (sq *StatQueue) Compress(maxQL int64) bool { +func (sq *StatQueue) Compress(maxQL int64, roundDec int) bool { if int64(len(sq.SQItems)) < maxQL || maxQL == 0 { return false } @@ -278,7 +279,7 @@ func (sq *StatQueue) Compress(maxQL int64) bool { } for _, m := range sq.SQMetrics { - for _, id := range m.Compress(maxQL, defaultCompressID) { + for _, id := range m.Compress(maxQL, defaultCompressID, roundDec) { idMap[id] = struct{}{} } } diff --git a/engine/libstats_test.go b/engine/libstats_test.go index db4e5af58..d4b4270b9 100644 --- a/engine/libstats_test.go +++ b/engine/libstats_test.go @@ -22,6 +22,7 @@ import ( "testing" "time" + "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/utils" ) @@ -60,29 +61,29 @@ func TestStatRemEventWithID(t *testing.T) { }, } asrMetric := sq.SQMetrics[utils.MetaASR].(*StatASR) - if asr := asrMetric.GetFloat64Value(); asr != 50 { + if asr := asrMetric.GetFloat64Value(config.CgrConfig().GeneralCfg().RoundingDecimals); asr != 50 { t.Errorf("received asrMetric: %v", asrMetric) } sq.remEventWithID("cgrates.org:TestRemEventWithID_1") - if asr := asrMetric.GetFloat64Value(); asr != 0 { + if asr := asrMetric.GetFloat64Value(config.CgrConfig().GeneralCfg().RoundingDecimals); asr != 0 { t.Errorf("received asrMetric: %v", asrMetric) } else if len(asrMetric.Events) != 1 { t.Errorf("unexpected Events in asrMetric: %+v", asrMetric.Events) } sq.remEventWithID("cgrates.org:TestRemEventWithID_5") // non existent - if asr := asrMetric.GetFloat64Value(); asr != 0 { + if asr := asrMetric.GetFloat64Value(config.CgrConfig().GeneralCfg().RoundingDecimals); asr != 0 { t.Errorf("received asrMetric: %v", asrMetric) } else if len(asrMetric.Events) != 1 { t.Errorf("unexpected Events in asrMetric: %+v", asrMetric.Events) } sq.remEventWithID("cgrates.org:TestRemEventWithID_2") - if asr := asrMetric.GetFloat64Value(); asr != -1 { + if asr := asrMetric.GetFloat64Value(config.CgrConfig().GeneralCfg().RoundingDecimals); asr != -1 { t.Errorf("received asrMetric: %v", asrMetric) } else if len(asrMetric.Events) != 0 { t.Errorf("unexpected Events in asrMetric: %+v", asrMetric.Events) } sq.remEventWithID("cgrates.org:TestRemEventWithID_2") - if asr := asrMetric.GetFloat64Value(); asr != -1 { + if asr := asrMetric.GetFloat64Value(config.CgrConfig().GeneralCfg().RoundingDecimals); asr != -1 { t.Errorf("received asrMetric: %v", asrMetric) } else if len(asrMetric.Events) != 0 { t.Errorf("unexpected Events in asrMetric: %+v", asrMetric.Events) @@ -103,31 +104,31 @@ func TestStatRemEventWithID2(t *testing.T) { }, } asrMetric := sq.SQMetrics[utils.MetaASR].(*StatASR) - if asr := asrMetric.GetFloat64Value(); asr != 50 { + if asr := asrMetric.GetFloat64Value(config.CgrConfig().GeneralCfg().RoundingDecimals); asr != 50 { t.Errorf("received asrMetric: %v", asrMetric) } sq.remEventWithID("cgrates.org:TestRemEventWithID_1") sq.remEventWithID("cgrates.org:TestRemEventWithID_2") - if asr := asrMetric.GetFloat64Value(); asr != 50 { + if asr := asrMetric.GetFloat64Value(config.CgrConfig().GeneralCfg().RoundingDecimals); asr != 50 { t.Errorf("received asrMetric: %v", asrMetric) } else if len(asrMetric.Events) != 2 { t.Errorf("unexpected Events in asrMetric: %+v", asrMetric.Events) } sq.remEventWithID("cgrates.org:TestRemEventWithID_5") // non existent - if asr := asrMetric.GetFloat64Value(); asr != 50 { + if asr := asrMetric.GetFloat64Value(config.CgrConfig().GeneralCfg().RoundingDecimals); asr != 50 { t.Errorf("received asrMetric: %v", asrMetric) } else if len(asrMetric.Events) != 2 { t.Errorf("unexpected Events in asrMetric: %+v", asrMetric.Events) } sq.remEventWithID("cgrates.org:TestRemEventWithID_2") sq.remEventWithID("cgrates.org:TestRemEventWithID_1") - if asr := asrMetric.GetFloat64Value(); asr != -1 { + if asr := asrMetric.GetFloat64Value(config.CgrConfig().GeneralCfg().RoundingDecimals); asr != -1 { t.Errorf("received asrMetric: %v", asrMetric) } else if len(asrMetric.Events) != 0 { t.Errorf("unexpected Events in asrMetric: %+v", asrMetric.Events) } sq.remEventWithID("cgrates.org:TestRemEventWithID_2") - if asr := asrMetric.GetFloat64Value(); asr != -1 { + if asr := asrMetric.GetFloat64Value(config.CgrConfig().GeneralCfg().RoundingDecimals); asr != -1 { t.Errorf("received asrMetric: %v", asrMetric) } else if len(asrMetric.Events) != 0 { t.Errorf("unexpected Events in asrMetric: %+v", asrMetric.Events) @@ -154,11 +155,11 @@ func TestStatRemExpired(t *testing.T) { }, } asrMetric := sq.SQMetrics[utils.MetaASR].(*StatASR) - if asr := asrMetric.GetFloat64Value(); asr != 66.66667 { + if asr := asrMetric.GetFloat64Value(config.CgrConfig().GeneralCfg().RoundingDecimals); asr != 66.66667 { t.Errorf("received asrMetric: %v", asrMetric) } sq.remExpired() - if asr := asrMetric.GetFloat64Value(); asr != 100 { + if asr := asrMetric.GetFloat64Value(config.CgrConfig().GeneralCfg().RoundingDecimals); asr != 100 { t.Errorf("received asrMetric: %v", asrMetric) } else if len(asrMetric.Events) != 1 { t.Errorf("unexpected Events in asrMetric: %+v", asrMetric.Events) @@ -216,12 +217,12 @@ func TestStatAddStatEvent(t *testing.T) { }, } asrMetric := sq.SQMetrics[utils.MetaASR].(*StatASR) - if asr := asrMetric.GetFloat64Value(); asr != 100 { + if asr := asrMetric.GetFloat64Value(config.CgrConfig().GeneralCfg().RoundingDecimals); asr != 100 { t.Errorf("received ASR: %v", asr) } ev1 := &utils.CGREvent{Tenant: "cgrates.org", ID: "TestStatAddStatEvent_1"} sq.addStatEvent(ev1.Tenant, ev1.ID, nil, utils.MapStorage{utils.MetaReq: ev1.Event}) - if asr := asrMetric.GetFloat64Value(); asr != 50 { + if asr := asrMetric.GetFloat64Value(config.CgrConfig().GeneralCfg().RoundingDecimals); asr != 50 { t.Errorf("received ASR: %v", asr) } else if asrMetric.Answered != 1 || asrMetric.Count != 2 { t.Errorf("ASR: %v", asrMetric) @@ -229,7 +230,7 @@ func TestStatAddStatEvent(t *testing.T) { ev1.Event = map[string]interface{}{ utils.AnswerTime: time.Now()} sq.addStatEvent(ev1.Tenant, ev1.ID, nil, utils.MapStorage{utils.MetaReq: ev1.Event}) - if asr := asrMetric.GetFloat64Value(); asr != 66.66667 { + if asr := asrMetric.GetFloat64Value(config.CgrConfig().GeneralCfg().RoundingDecimals); asr != 66.66667 { t.Errorf("received ASR: %v", asr) } else if asrMetric.Answered != 2 || asrMetric.Count != 3 { t.Errorf("ASR: %v", asrMetric) @@ -300,10 +301,10 @@ func TestStatCompress(t *testing.T) { utils.MetaASR: asr, }, } - if sq.Compress(int64(100)) { + if sq.Compress(int64(100), config.CgrConfig().GeneralCfg().RoundingDecimals) { t.Errorf("StatQueue compressed: %s", utils.ToJSON(sq)) } - if !sq.Compress(int64(2)) { + if !sq.Compress(int64(2), config.CgrConfig().GeneralCfg().RoundingDecimals) { t.Errorf("StatQueue not compressed: %s", utils.ToJSON(sq)) } if !reflect.DeepEqual(sq.SQItems, expectedSqItems) { @@ -364,10 +365,10 @@ func TestStatCompress2(t *testing.T) { utils.MetaTCD: tcd, }, } - if sq.Compress(int64(100)) { + if sq.Compress(int64(100), config.CgrConfig().GeneralCfg().RoundingDecimals) { t.Errorf("StatQueue compressed: %s", utils.ToJSON(sq)) } - if !sq.Compress(int64(2)) { + if !sq.Compress(int64(2), config.CgrConfig().GeneralCfg().RoundingDecimals) { t.Errorf("StatQueue not compressed: %s", utils.ToJSON(sq)) } if !reflect.DeepEqual(sq.SQItems, expectedSqItems) { @@ -435,10 +436,10 @@ func TestStatCompress3(t *testing.T) { utils.MetaTCD: tcd, }, } - if sq.Compress(int64(100)) { + if sq.Compress(int64(100), config.CgrConfig().GeneralCfg().RoundingDecimals) { t.Errorf("StatQueue compressed: %s", utils.ToJSON(sq)) } - if !sq.Compress(int64(3)) { + if !sq.Compress(int64(3), config.CgrConfig().GeneralCfg().RoundingDecimals) { t.Errorf("StatQueue not compressed: %s", utils.ToJSON(sq)) } if !reflect.DeepEqual(sq.SQItems, expectedSqItems) { diff --git a/engine/statmetrics.go b/engine/statmetrics.go index 082ad62e3..262068ce8 100644 --- a/engine/statmetrics.go +++ b/engine/statmetrics.go @@ -28,9 +28,6 @@ import ( "github.com/cgrates/cgrates/utils" ) -//to be moved in utils -const STATS_NA = -1.0 - // ACDHelper structure type DurationWithCompress struct { Duration time.Duration @@ -73,15 +70,15 @@ func NewStatMetric(metricID string, minItems int, filterIDs []string) (sm StatMe // StatMetric is the interface which a metric should implement type StatMetric interface { - GetValue() interface{} - GetStringValue(fmtOpts string) (val string) - GetFloat64Value() (val float64) + GetValue(roundingDecimal int) interface{} + GetStringValue(roundingDecimal int) (val string) + GetFloat64Value(roundingDecimal int) (val float64) AddEvent(evID string, ev utils.DataProvider) error RemEvent(evTenantID string) error Marshal(ms Marshaler) (marshaled []byte, err error) LoadMarshaled(ms Marshaler, marshaled []byte) (err error) GetFilterIDs() (filterIDs []string) - Compress(queueLen int64, defaultID string) (eventIDs []string) + Compress(queueLen int64, defaultID string, roundingDec int) (eventIDs []string) GetCompressFactor(events map[string]int) map[string]int } @@ -101,35 +98,35 @@ type StatASR struct { } // getValue returns asr.val -func (asr *StatASR) getValue() float64 { +func (asr *StatASR) getValue(roundingDecimal int) float64 { if asr.val == nil { if (asr.MinItems > 0 && asr.Count < int64(asr.MinItems)) || (asr.Count == 0) { - asr.val = utils.Float64Pointer(STATS_NA) + asr.val = utils.Float64Pointer(utils.StatsNA) } else { asr.val = utils.Float64Pointer(utils.Round((asr.Answered / float64(asr.Count) * 100.0), - config.CgrConfig().GeneralCfg().RoundingDecimals, utils.ROUNDING_MIDDLE)) + roundingDecimal, utils.ROUNDING_MIDDLE)) } } return *asr.val } // GetValue returns the ASR value as part of StatMetric interface -func (asr *StatASR) GetValue() (v interface{}) { - return asr.getValue() +func (asr *StatASR) GetValue(roundingDecimal int) (v interface{}) { + return asr.getValue(roundingDecimal) } -func (asr *StatASR) GetStringValue(fmtOpts string) (valStr string) { - if val := asr.getValue(); val == STATS_NA { +func (asr *StatASR) GetStringValue(roundingDecimal int) (valStr string) { + if val := asr.getValue(roundingDecimal); val == utils.StatsNA { valStr = utils.NOT_AVAILABLE } else { - valStr = fmt.Sprintf("%v%%", asr.getValue()) + valStr = fmt.Sprintf("%v%%", asr.getValue(roundingDecimal)) } return } // GetFloat64Value is part of StatMetric interface -func (asr *StatASR) GetFloat64Value() (val float64) { - return asr.getValue() +func (asr *StatASR) GetFloat64Value(roundingDecimal int) (val float64) { + return asr.getValue(roundingDecimal) } // AddEvent is part of StatMetric interface @@ -197,7 +194,7 @@ func (asr *StatASR) GetFilterIDs() []string { } // Compress is part of StatMetric interface -func (asr *StatASR) Compress(queueLen int64, defaultID string) (eventIDs []string) { +func (asr *StatASR) Compress(queueLen int64, defaultID string, roundingDecimal int) (eventIDs []string) { if asr.Count < queueLen { for id := range asr.Events { eventIDs = append(eventIDs, id) @@ -206,7 +203,7 @@ func (asr *StatASR) Compress(queueLen int64, defaultID string) (eventIDs []strin } stat := &StatWithCompress{ Stat: utils.Round(asr.Answered/float64(asr.Count), - config.CgrConfig().GeneralCfg().RoundingDecimals, utils.ROUNDING_MIDDLE), + roundingDecimal, utils.ROUNDING_MIDDLE), CompressFactor: int(asr.Count), } asr.Events = map[string]*StatWithCompress{defaultID: stat} @@ -241,37 +238,37 @@ type StatACD struct { } // getValue returns acd.val -func (acd *StatACD) getValue() time.Duration { +func (acd *StatACD) getValue(roundingDecimal int) time.Duration { if acd.val == nil { if (acd.MinItems > 0 && acd.Count < int64(acd.MinItems)) || (acd.Count == 0) { acd.val = utils.DurationPointer(-time.Nanosecond) } else { acd.val = utils.DurationPointer(utils.RoundStatDuration( time.Duration(acd.Sum.Nanoseconds()/acd.Count), - config.CgrConfig().GeneralCfg().RoundingDecimals)) + roundingDecimal)) } } return *acd.val } -func (acd *StatACD) GetStringValue(fmtOpts string) (valStr string) { - if val := acd.getValue(); val == -time.Nanosecond { +func (acd *StatACD) GetStringValue(roundingDecimal int) (valStr string) { + if val := acd.getValue(roundingDecimal); val == -time.Nanosecond { valStr = utils.NOT_AVAILABLE } else { - valStr = fmt.Sprintf("%+v", acd.getValue()) + valStr = fmt.Sprintf("%+v", acd.getValue(roundingDecimal)) } return } -func (acd *StatACD) GetValue() (v interface{}) { - return acd.getValue() +func (acd *StatACD) GetValue(roundingDecimal int) (v interface{}) { + return acd.getValue(roundingDecimal) } -func (acd *StatACD) GetFloat64Value() (v float64) { - if val := acd.getValue(); val == -time.Nanosecond { - v = -1.0 +func (acd *StatACD) GetFloat64Value(roundingDecimal int) (v float64) { + if val := acd.getValue(roundingDecimal); val == -time.Nanosecond { + v = utils.StatsNA } else { - v = acd.getValue().Seconds() + v = acd.getValue(roundingDecimal).Seconds() } return } @@ -330,7 +327,7 @@ func (acd *StatACD) GetFilterIDs() []string { } // Compress is part of StatMetric interface -func (acd *StatACD) Compress(queueLen int64, defaultID string) (eventIDs []string) { +func (acd *StatACD) Compress(queueLen int64, defaultID string, roundingDecimal int) (eventIDs []string) { if acd.Count < queueLen { for id := range acd.Events { eventIDs = append(eventIDs, id) @@ -339,7 +336,7 @@ func (acd *StatACD) Compress(queueLen int64, defaultID string) (eventIDs []strin } stat := &DurationWithCompress{ Duration: utils.RoundStatDuration(time.Duration(acd.Sum.Nanoseconds()/acd.Count), - config.CgrConfig().GeneralCfg().RoundingDecimals), + roundingDecimal), CompressFactor: int(acd.Count), } acd.Events = map[string]*DurationWithCompress{defaultID: stat} @@ -374,38 +371,38 @@ type StatTCD struct { } // getValue returns tcd.val -func (tcd *StatTCD) getValue() time.Duration { +func (tcd *StatTCD) getValue(roundingDecimal int) time.Duration { if tcd.val == nil { if (tcd.MinItems > 0 && tcd.Count < int64(tcd.MinItems)) || (tcd.Count == 0) { - tcd.val = utils.DurationPointer(time.Duration((-1) * time.Nanosecond)) + tcd.val = utils.DurationPointer(-time.Nanosecond) } else { tcd.val = utils.DurationPointer(utils.RoundStatDuration( time.Duration(tcd.Sum.Nanoseconds()), - config.CgrConfig().GeneralCfg().RoundingDecimals)) + roundingDecimal)) } } return *tcd.val } -func (tcd *StatTCD) GetStringValue(fmtOpts string) (valStr string) { - if val := tcd.getValue(); val == time.Duration((-1)*time.Nanosecond) { +func (tcd *StatTCD) GetStringValue(roundingDecimal int) (valStr string) { + if val := tcd.getValue(roundingDecimal); val == -time.Nanosecond { valStr = utils.NOT_AVAILABLE } else { - valStr = fmt.Sprintf("%+v", tcd.getValue()) + valStr = fmt.Sprintf("%+v", tcd.getValue(roundingDecimal)) } return } -func (tcd *StatTCD) GetValue() (v interface{}) { - return tcd.getValue() +func (tcd *StatTCD) GetValue(roundingDecimal int) (v interface{}) { + return tcd.getValue(roundingDecimal) } -func (tcd *StatTCD) GetFloat64Value() (v float64) { - if val := tcd.getValue(); val == time.Duration((-1)*time.Nanosecond) { - v = -1.0 +func (tcd *StatTCD) GetFloat64Value(roundingDecimal int) (v float64) { + if val := tcd.getValue(roundingDecimal); val == -time.Nanosecond { + v = utils.StatsNA } else { - v = tcd.getValue().Seconds() + v = tcd.getValue(roundingDecimal).Seconds() } return } @@ -465,7 +462,7 @@ func (tcd *StatTCD) GetFilterIDs() []string { } // Compress is part of StatMetric interface -func (tcd *StatTCD) Compress(queueLen int64, defaultID string) (eventIDs []string) { +func (tcd *StatTCD) Compress(queueLen int64, defaultID string, roundingDecimal int) (eventIDs []string) { if tcd.Count < queueLen { for id := range tcd.Events { eventIDs = append(eventIDs, id) @@ -474,7 +471,7 @@ func (tcd *StatTCD) Compress(queueLen int64, defaultID string) (eventIDs []strin } stat := &DurationWithCompress{ Duration: utils.RoundStatDuration(time.Duration(tcd.Sum.Nanoseconds()/tcd.Count), - config.CgrConfig().GeneralCfg().RoundingDecimals), + roundingDecimal), CompressFactor: int(tcd.Count), } tcd.Events = map[string]*DurationWithCompress{defaultID: stat} @@ -509,34 +506,34 @@ type StatACC struct { } // getValue returns tcd.val -func (acc *StatACC) getValue() float64 { +func (acc *StatACC) getValue(roundingDecimal int) float64 { if acc.val == nil { if (acc.MinItems > 0 && acc.Count < int64(acc.MinItems)) || (acc.Count == 0) { - acc.val = utils.Float64Pointer(STATS_NA) + acc.val = utils.Float64Pointer(utils.StatsNA) } else { acc.val = utils.Float64Pointer(utils.Round(acc.Sum/float64(acc.Count), - config.CgrConfig().GeneralCfg().RoundingDecimals, utils.ROUNDING_MIDDLE)) + roundingDecimal, utils.ROUNDING_MIDDLE)) } } return *acc.val } -func (acc *StatACC) GetStringValue(fmtOpts string) (valStr string) { - if val := acc.getValue(); val == STATS_NA { +func (acc *StatACC) GetStringValue(roundingDecimal int) (valStr string) { + if val := acc.getValue(roundingDecimal); val == utils.StatsNA { valStr = utils.NOT_AVAILABLE } else { - valStr = strconv.FormatFloat(acc.getValue(), 'f', -1, 64) + valStr = strconv.FormatFloat(acc.getValue(roundingDecimal), 'f', -1, 64) } return } -func (acc *StatACC) GetValue() (v interface{}) { - return acc.getValue() +func (acc *StatACC) GetValue(roundingDecimal int) (v interface{}) { + return acc.getValue(roundingDecimal) } -func (acc *StatACC) GetFloat64Value() (v float64) { - return acc.getValue() +func (acc *StatACC) GetFloat64Value(roundingDecimal int) (v float64) { + return acc.getValue(roundingDecimal) } func (acc *StatACC) AddEvent(evID string, ev utils.DataProvider) (err error) { @@ -592,7 +589,7 @@ func (acc *StatACC) GetFilterIDs() []string { } // Compress is part of StatMetric interface -func (acc *StatACC) Compress(queueLen int64, defaultID string) (eventIDs []string) { +func (acc *StatACC) Compress(queueLen int64, defaultID string, roundingDecimal int) (eventIDs []string) { if acc.Count < queueLen { for id := range acc.Events { eventIDs = append(eventIDs, id) @@ -601,7 +598,7 @@ func (acc *StatACC) Compress(queueLen int64, defaultID string) (eventIDs []strin } stat := &StatWithCompress{ Stat: utils.Round(acc.Sum/float64(acc.Count), - config.CgrConfig().GeneralCfg().RoundingDecimals, utils.ROUNDING_MIDDLE), + roundingDecimal, utils.ROUNDING_MIDDLE), CompressFactor: int(acc.Count), } acc.Events = map[string]*StatWithCompress{defaultID: stat} @@ -636,34 +633,34 @@ type StatTCC struct { } // getValue returns tcd.val -func (tcc *StatTCC) getValue() float64 { +func (tcc *StatTCC) getValue(roundingDecimal int) float64 { if tcc.val == nil { if (tcc.MinItems > 0 && tcc.Count < int64(tcc.MinItems)) || (tcc.Count == 0) { - tcc.val = utils.Float64Pointer(STATS_NA) + tcc.val = utils.Float64Pointer(utils.StatsNA) } else { tcc.val = utils.Float64Pointer(utils.Round(tcc.Sum, - config.CgrConfig().GeneralCfg().RoundingDecimals, + roundingDecimal, utils.ROUNDING_MIDDLE)) } } return *tcc.val } -func (tcc *StatTCC) GetStringValue(fmtOpts string) (valStr string) { - if val := tcc.getValue(); val == STATS_NA { +func (tcc *StatTCC) GetStringValue(roundingDecimal int) (valStr string) { + if val := tcc.getValue(roundingDecimal); val == utils.StatsNA { valStr = utils.NOT_AVAILABLE } else { - valStr = strconv.FormatFloat(tcc.getValue(), 'f', -1, 64) + valStr = strconv.FormatFloat(tcc.getValue(roundingDecimal), 'f', -1, 64) } return } -func (tcc *StatTCC) GetValue() (v interface{}) { - return tcc.getValue() +func (tcc *StatTCC) GetValue(roundingDecimal int) (v interface{}) { + return tcc.getValue(roundingDecimal) } -func (tcc *StatTCC) GetFloat64Value() (v float64) { - return tcc.getValue() +func (tcc *StatTCC) GetFloat64Value(roundingDecimal int) (v float64) { + return tcc.getValue(roundingDecimal) } func (tcc *StatTCC) AddEvent(evID string, ev utils.DataProvider) (err error) { @@ -721,7 +718,7 @@ func (tcc *StatTCC) GetFilterIDs() []string { } // Compress is part of StatMetric interface -func (tcc *StatTCC) Compress(queueLen int64, defaultID string) (eventIDs []string) { +func (tcc *StatTCC) Compress(queueLen int64, defaultID string, roundingDecimal int) (eventIDs []string) { if tcc.Count < queueLen { for id := range tcc.Events { eventIDs = append(eventIDs, id) @@ -730,7 +727,7 @@ func (tcc *StatTCC) Compress(queueLen int64, defaultID string) (eventIDs []strin } stat := &StatWithCompress{ Stat: utils.Round((tcc.Sum / float64(tcc.Count)), - config.CgrConfig().GeneralCfg().RoundingDecimals, utils.ROUNDING_MIDDLE), + roundingDecimal, utils.ROUNDING_MIDDLE), CompressFactor: int(tcc.Count), } tcc.Events = map[string]*StatWithCompress{defaultID: stat} @@ -765,37 +762,37 @@ type StatPDD struct { } // getValue returns pdd.val -func (pdd *StatPDD) getValue() time.Duration { +func (pdd *StatPDD) getValue(roundingDecimal int) time.Duration { if pdd.val == nil { if (pdd.MinItems > 0 && pdd.Count < int64(pdd.MinItems)) || (pdd.Count == 0) { - pdd.val = utils.DurationPointer(time.Duration((-1) * time.Nanosecond)) + pdd.val = utils.DurationPointer(-time.Nanosecond) } else { pdd.val = utils.DurationPointer(utils.RoundStatDuration( time.Duration(pdd.Sum.Nanoseconds()/pdd.Count), - config.CgrConfig().GeneralCfg().RoundingDecimals)) + roundingDecimal)) } } return *pdd.val } -func (pdd *StatPDD) GetStringValue(fmtOpts string) (valStr string) { - if val := pdd.getValue(); val == time.Duration((-1)*time.Nanosecond) { +func (pdd *StatPDD) GetStringValue(roundingDecimal int) (valStr string) { + if val := pdd.getValue(roundingDecimal); val == -time.Nanosecond { valStr = utils.NOT_AVAILABLE } else { - valStr = fmt.Sprintf("%+v", pdd.getValue()) + valStr = fmt.Sprintf("%+v", pdd.getValue(roundingDecimal)) } return } -func (pdd *StatPDD) GetValue() (v interface{}) { - return pdd.getValue() +func (pdd *StatPDD) GetValue(roundingDecimal int) (v interface{}) { + return pdd.getValue(roundingDecimal) } -func (pdd *StatPDD) GetFloat64Value() (v float64) { - if val := pdd.getValue(); val == time.Duration((-1)*time.Nanosecond) { - v = -1.0 +func (pdd *StatPDD) GetFloat64Value(roundingDecimal int) (v float64) { + if val := pdd.getValue(roundingDecimal); val == -time.Nanosecond { + v = utils.StatsNA } else { - v = pdd.getValue().Seconds() + v = pdd.getValue(roundingDecimal).Seconds() } return } @@ -854,7 +851,7 @@ func (pdd *StatPDD) GetFilterIDs() []string { } // Compress is part of StatMetric interface -func (pdd *StatPDD) Compress(queueLen int64, defaultID string) (eventIDs []string) { +func (pdd *StatPDD) Compress(queueLen int64, defaultID string, roundingDecimal int) (eventIDs []string) { if pdd.Count < queueLen { for id := range pdd.Events { eventIDs = append(eventIDs, id) @@ -863,7 +860,7 @@ func (pdd *StatPDD) Compress(queueLen int64, defaultID string) (eventIDs []strin } stat := &DurationWithCompress{ Duration: utils.RoundStatDuration(time.Duration(pdd.Sum.Nanoseconds()/pdd.Count), - config.CgrConfig().GeneralCfg().RoundingDecimals), + roundingDecimal), CompressFactor: int(pdd.Count), } pdd.Events = map[string]*DurationWithCompress{defaultID: stat} @@ -897,28 +894,28 @@ type StatDDC struct { } // getValue returns tcd.val -func (ddc *StatDDC) getValue() float64 { +func (ddc *StatDDC) getValue(roundingDecimal int) float64 { if ddc.Count == 0 || ddc.Count < int64(ddc.MinItems) { - return STATS_NA + return utils.StatsNA } return float64(len(ddc.FieldValues)) } -func (ddc *StatDDC) GetStringValue(fmtOpts string) (valStr string) { - if val := ddc.getValue(); val == STATS_NA { +func (ddc *StatDDC) GetStringValue(roundingDecimal int) (valStr string) { + if val := ddc.getValue(roundingDecimal); val == utils.StatsNA { valStr = utils.NOT_AVAILABLE } else { - valStr = strconv.FormatFloat(ddc.getValue(), 'f', -1, 64) + valStr = strconv.FormatFloat(ddc.getValue(roundingDecimal), 'f', -1, 64) } return } -func (ddc *StatDDC) GetValue() (v interface{}) { - return ddc.getValue() +func (ddc *StatDDC) GetValue(roundingDecimal int) (v interface{}) { + return ddc.getValue(roundingDecimal) } -func (ddc *StatDDC) GetFloat64Value() (v float64) { - return ddc.getValue() +func (ddc *StatDDC) GetFloat64Value(roundingDecimal int) (v float64) { + return ddc.getValue(roundingDecimal) } func (ddc *StatDDC) AddEvent(evID string, ev utils.DataProvider) (err error) { @@ -996,7 +993,7 @@ func (ddc *StatDDC) GetFilterIDs() []string { return ddc.FilterIDs } -func (ddc *StatDDC) Compress(queueLen int64, defaultID string) (eventIDs []string) { +func (ddc *StatDDC) Compress(queueLen int64, defaultID string, roundingDecimal int) (eventIDs []string) { for id := range ddc.Events { eventIDs = append(eventIDs, id) } @@ -1036,34 +1033,34 @@ type StatSum struct { } // getValue returns tcd.val -func (sum *StatSum) getValue() float64 { +func (sum *StatSum) getValue(roundingDecimal int) float64 { if sum.val == nil { if len(sum.Events) == 0 || sum.Count < int64(sum.MinItems) { - sum.val = utils.Float64Pointer(STATS_NA) + sum.val = utils.Float64Pointer(utils.StatsNA) } else { sum.val = utils.Float64Pointer(utils.Round(sum.Sum, - config.CgrConfig().GeneralCfg().RoundingDecimals, + roundingDecimal, utils.ROUNDING_MIDDLE)) } } return *sum.val } -func (sum *StatSum) GetStringValue(fmtOpts string) (valStr string) { - if val := sum.getValue(); val == STATS_NA { +func (sum *StatSum) GetStringValue(roundingDecimal int) (valStr string) { + if val := sum.getValue(roundingDecimal); val == utils.StatsNA { valStr = utils.NOT_AVAILABLE } else { - valStr = strconv.FormatFloat(sum.getValue(), 'f', -1, 64) + valStr = strconv.FormatFloat(sum.getValue(roundingDecimal), 'f', -1, 64) } return } -func (sum *StatSum) GetValue() (v interface{}) { - return sum.getValue() +func (sum *StatSum) GetValue(roundingDecimal int) (v interface{}) { + return sum.getValue(roundingDecimal) } -func (sum *StatSum) GetFloat64Value() (v float64) { - return sum.getValue() +func (sum *StatSum) GetFloat64Value(roundingDecimal int) (v float64) { + return sum.getValue(roundingDecimal) } func (sum *StatSum) AddEvent(evID string, ev utils.DataProvider) (err error) { @@ -1121,7 +1118,7 @@ func (sum *StatSum) GetFilterIDs() []string { } // Compress is part of StatMetric interface -func (sum *StatSum) Compress(queueLen int64, defaultID string) (eventIDs []string) { +func (sum *StatSum) Compress(queueLen int64, defaultID string, roundingDecimal int) (eventIDs []string) { if sum.Count < queueLen { for id := range sum.Events { eventIDs = append(eventIDs, id) @@ -1130,7 +1127,7 @@ func (sum *StatSum) Compress(queueLen int64, defaultID string) (eventIDs []strin } stat := &StatWithCompress{ Stat: utils.Round((sum.Sum / float64(sum.Count)), - config.CgrConfig().GeneralCfg().RoundingDecimals, utils.ROUNDING_MIDDLE), + roundingDecimal, utils.ROUNDING_MIDDLE), CompressFactor: int(sum.Count), } sum.Events = map[string]*StatWithCompress{defaultID: stat} @@ -1167,34 +1164,34 @@ type StatAverage struct { } // getValue returns tcd.val -func (avg *StatAverage) getValue() float64 { +func (avg *StatAverage) getValue(roundingDecimal int) float64 { if avg.val == nil { if (avg.MinItems > 0 && avg.Count < int64(avg.MinItems)) || (avg.Count == 0) { - avg.val = utils.Float64Pointer(STATS_NA) + avg.val = utils.Float64Pointer(utils.StatsNA) } else { avg.val = utils.Float64Pointer(utils.Round((avg.Sum / float64(avg.Count)), - config.CgrConfig().GeneralCfg().RoundingDecimals, utils.ROUNDING_MIDDLE)) + roundingDecimal, utils.ROUNDING_MIDDLE)) } } return *avg.val } -func (avg *StatAverage) GetStringValue(fmtOpts string) (valStr string) { - if val := avg.getValue(); val == STATS_NA { +func (avg *StatAverage) GetStringValue(roundingDecimal int) (valStr string) { + if val := avg.getValue(roundingDecimal); val == utils.StatsNA { valStr = utils.NOT_AVAILABLE } else { - valStr = strconv.FormatFloat(avg.getValue(), 'f', -1, 64) + valStr = strconv.FormatFloat(avg.getValue(roundingDecimal), 'f', -1, 64) } return } -func (avg *StatAverage) GetValue() (v interface{}) { - return avg.getValue() +func (avg *StatAverage) GetValue(roundingDecimal int) (v interface{}) { + return avg.getValue(roundingDecimal) } -func (avg *StatAverage) GetFloat64Value() (v float64) { - return avg.getValue() +func (avg *StatAverage) GetFloat64Value(roundingDecimal int) (v float64) { + return avg.getValue(roundingDecimal) } func (avg *StatAverage) AddEvent(evID string, ev utils.DataProvider) (err error) { @@ -1252,7 +1249,7 @@ func (avg *StatAverage) GetFilterIDs() []string { } // Compress is part of StatMetric interface -func (avg *StatAverage) Compress(queueLen int64, defaultID string) (eventIDs []string) { +func (avg *StatAverage) Compress(queueLen int64, defaultID string, roundingDecimal int) (eventIDs []string) { if avg.Count < queueLen { for id := range avg.Events { eventIDs = append(eventIDs, id) @@ -1261,7 +1258,7 @@ func (avg *StatAverage) Compress(queueLen int64, defaultID string) (eventIDs []s } stat := &StatWithCompress{ Stat: utils.Round((avg.Sum / float64(avg.Count)), - config.CgrConfig().GeneralCfg().RoundingDecimals, utils.ROUNDING_MIDDLE), + roundingDecimal, utils.ROUNDING_MIDDLE), CompressFactor: int(avg.Count), } avg.Events = map[string]*StatWithCompress{defaultID: stat} @@ -1296,28 +1293,28 @@ type StatDistinct struct { } // getValue returns tcd.val -func (dst *StatDistinct) getValue() float64 { +func (dst *StatDistinct) getValue(roundingDecimal int) float64 { if dst.Count == 0 || dst.Count < int64(dst.MinItems) { - return STATS_NA + return utils.StatsNA } return float64(len(dst.FieldValues)) } -func (dst *StatDistinct) GetStringValue(fmtOpts string) (valStr string) { - if val := dst.getValue(); val == STATS_NA { +func (dst *StatDistinct) GetStringValue(roundingDecimal int) (valStr string) { + if val := dst.getValue(roundingDecimal); val == utils.StatsNA { valStr = utils.NOT_AVAILABLE } else { - valStr = strconv.FormatFloat(dst.getValue(), 'f', -1, 64) + valStr = strconv.FormatFloat(dst.getValue(roundingDecimal), 'f', -1, 64) } return } -func (dst *StatDistinct) GetValue() (v interface{}) { - return dst.getValue() +func (dst *StatDistinct) GetValue(roundingDecimal int) (v interface{}) { + return dst.getValue(roundingDecimal) } -func (dst *StatDistinct) GetFloat64Value() (v float64) { - return dst.getValue() +func (dst *StatDistinct) GetFloat64Value(roundingDecimal int) (v float64) { + return dst.getValue(roundingDecimal) } func (dst *StatDistinct) AddEvent(evID string, ev utils.DataProvider) (err error) { @@ -1400,7 +1397,7 @@ func (dst *StatDistinct) GetFilterIDs() []string { return dst.FilterIDs } -func (dst *StatDistinct) Compress(queueLen int64, defaultID string) (eventIDs []string) { +func (dst *StatDistinct) Compress(queueLen int64, defaultID string, roundingDecimal int) (eventIDs []string) { for id := range dst.Events { eventIDs = append(eventIDs, id) } diff --git a/engine/statmetrics_test.go b/engine/statmetrics_test.go index 0f5183ece..d6084b66c 100644 --- a/engine/statmetrics_test.go +++ b/engine/statmetrics_test.go @@ -33,25 +33,25 @@ func TestASRGetStringValue(t *testing.T) { 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 { + if strVal := asr.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != utils.NOT_AVAILABLE { t.Errorf("wrong asr value: %s", strVal) } asr.AddEvent(ev.ID, utils.MapStorage{utils.MetaReq: ev.Event}) - if strVal := asr.GetStringValue(""); strVal != utils.NOT_AVAILABLE { + if strVal := asr.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != utils.NOT_AVAILABLE { t.Errorf("wrong asr value: %s", strVal) } ev2 := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_2"} ev3 := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_3"} asr.AddEvent(ev2.ID, utils.MapStorage{utils.MetaReq: ev2.Event}) - if strVal := asr.GetStringValue(""); strVal != "50%" { + if strVal := asr.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != "50%" { t.Errorf("wrong asr value: %s", strVal) } asr.AddEvent(ev3.ID, utils.MapStorage{utils.MetaReq: ev3.Event}) - if strVal := asr.GetStringValue(""); strVal != "33.33333%" { + if strVal := asr.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != "33.33333%" { t.Errorf("wrong asr value: %s", strVal) } asr.RemEvent(ev3.ID) - if strVal := asr.GetStringValue(""); strVal != "50%" { + if strVal := asr.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != "50%" { t.Errorf("wrong asr value: %s", strVal) } ev4 := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_4", @@ -63,16 +63,16 @@ func TestASRGetStringValue(t *testing.T) { asr.AddEvent(ev4.ID, utils.MapStorage{utils.MetaReq: ev4.Event}) asr.AddEvent(ev5.ID, utils.MapStorage{utils.MetaReq: ev5.Event}) asr.RemEvent(ev.ID) - if strVal := asr.GetStringValue(""); strVal != "66.66667%" { + if strVal := asr.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != "66.66667%" { t.Errorf("wrong asr value: %s", strVal) } asr.RemEvent(ev2.ID) - if strVal := asr.GetStringValue(""); strVal != "100%" { + if strVal := asr.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != "100%" { t.Errorf("wrong asr value: %s", strVal) } asr.RemEvent(ev4.ID) asr.RemEvent(ev5.ID) - if strVal := asr.GetStringValue(""); strVal != utils.NOT_AVAILABLE { + if strVal := asr.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != utils.NOT_AVAILABLE { t.Errorf("wrong asr value: %s", strVal) } } @@ -86,25 +86,25 @@ func TestASRGetStringValue2(t *testing.T) { ev4 := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_1"} asr.AddEvent(ev.ID, utils.MapStorage{utils.MetaReq: ev.Event}) asr.AddEvent(ev2.ID, utils.MapStorage{utils.MetaReq: ev2.Event}) - if strVal := asr.GetStringValue(""); strVal != "50%" { + if strVal := asr.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != "50%" { t.Errorf("wrong asr value: %s", strVal) } asr.AddEvent(ev2.ID, utils.MapStorage{utils.MetaReq: ev2.Event}) - if strVal := asr.GetStringValue(""); strVal != "33.33333%" { + if strVal := asr.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != "33.33333%" { t.Errorf("wrong asr value: %s", strVal) } asr.AddEvent(ev4.ID, utils.MapStorage{utils.MetaReq: ev4.Event}) - if strVal := asr.GetStringValue(""); strVal != "25%" { + if strVal := asr.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != "25%" { t.Errorf("wrong asr value: %s", strVal) } asr.RemEvent(ev4.ID) asr.RemEvent(ev2.ID) - if strVal := asr.GetStringValue(""); strVal != "50%" { + if strVal := asr.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != "50%" { t.Errorf("wrong asr value: %s", strVal) } asr.RemEvent(ev2.ID) asr.AddEvent(ev.ID, utils.MapStorage{utils.MetaReq: ev.Event}) - if strVal := asr.GetStringValue(""); strVal != "100%" { + if strVal := asr.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != "100%" { t.Errorf("wrong asr value: %s", strVal) } } @@ -122,7 +122,7 @@ func TestASRGetStringValue3(t *testing.T) { Answered: 1, Count: 2, } - expected.GetStringValue("") + expected.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals) 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)}} @@ -130,7 +130,7 @@ func TestASRGetStringValue3(t *testing.T) { ev4 := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_1"} asr.AddEvent(ev.ID, utils.MapStorage{utils.MetaReq: ev.Event}) asr.AddEvent(ev2.ID, utils.MapStorage{utils.MetaReq: ev2.Event}) - if strVal := asr.GetStringValue(""); strVal != "50%" { + if strVal := asr.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != "50%" { t.Errorf("wrong asr value: %s", strVal) } if !reflect.DeepEqual(*expected, *asr) { @@ -146,8 +146,8 @@ func TestASRGetStringValue3(t *testing.T) { v.CompressFactor = 2 expected.Count = 4 expected.val = nil - expected.GetStringValue("") - if strVal := asr.GetStringValue(""); strVal != "25%" { + expected.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals) + if strVal := asr.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != "25%" { t.Errorf("wrong asr value: %s", strVal) } if !reflect.DeepEqual(*expected, *asr) { @@ -163,8 +163,8 @@ func TestASRGetStringValue3(t *testing.T) { v.CompressFactor = 1 expected.Count = 2 expected.val = nil - expected.GetStringValue("") - if strVal := asr.GetStringValue(""); strVal != "50%" { + expected.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals) + if strVal := asr.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != "50%" { t.Errorf("wrong asr value: %s", strVal) } if !reflect.DeepEqual(*expected, *asr) { @@ -178,18 +178,18 @@ func TestASRGetValue(t *testing.T) { Event: map[string]interface{}{ "AnswerTime": time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC)}} asr.AddEvent(ev.ID, utils.MapStorage{utils.MetaReq: ev.Event}) - if v := asr.GetValue(); v != -1.0 { + if v := asr.GetValue(config.CgrConfig().GeneralCfg().RoundingDecimals); v != -1.0 { t.Errorf("wrong asr value: %f", v) } ev2 := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_2"} ev3 := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_3"} asr.AddEvent(ev2.ID, utils.MapStorage{utils.MetaReq: ev2.Event}) asr.AddEvent(ev3.ID, utils.MapStorage{utils.MetaReq: ev3.Event}) - if v := asr.GetValue(); v != 33.33333 { + if v := asr.GetValue(config.CgrConfig().GeneralCfg().RoundingDecimals); v != 33.33333 { t.Errorf("wrong asr value: %f", v) } asr.RemEvent(ev3.ID) - if v := asr.GetValue(); v != 50.0 { + if v := asr.GetValue(config.CgrConfig().GeneralCfg().RoundingDecimals); v != 50.0 { t.Errorf("wrong asr value: %f", v) } ev4 := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_4", @@ -201,19 +201,19 @@ func TestASRGetValue(t *testing.T) { asr.AddEvent(ev4.ID, utils.MapStorage{utils.MetaReq: ev4.Event}) asr.AddEvent(ev5.ID, utils.MapStorage{utils.MetaReq: ev5.Event}) asr.RemEvent(ev.ID) - if v := asr.GetValue(); v != 66.666670 { + if v := asr.GetValue(config.CgrConfig().GeneralCfg().RoundingDecimals); v != 66.666670 { t.Errorf("wrong asr value: %f", v) } asr.RemEvent(ev2.ID) - if v := asr.GetValue(); v != 100.0 { + if v := asr.GetValue(config.CgrConfig().GeneralCfg().RoundingDecimals); v != 100.0 { t.Errorf("wrong asr value: %f", v) } asr.RemEvent(ev4.ID) - if v := asr.GetValue(); v != -1.0 { + if v := asr.GetValue(config.CgrConfig().GeneralCfg().RoundingDecimals); v != -1.0 { t.Errorf("wrong asr value: %f", v) } asr.RemEvent(ev5.ID) - if v := asr.GetValue(); v != -1.0 { + if v := asr.GetValue(config.CgrConfig().GeneralCfg().RoundingDecimals); v != -1.0 { t.Errorf("wrong asr value: %f", v) } } @@ -231,7 +231,7 @@ func TestASRCompress(t *testing.T) { Answered: 1, Count: 2, } - expected.GetStringValue("") + expected.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals) 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)}} @@ -240,12 +240,12 @@ func TestASRCompress(t *testing.T) { asr.AddEvent(ev.ID, utils.MapStorage{utils.MetaReq: ev.Event}) asr.AddEvent(ev2.ID, utils.MapStorage{utils.MetaReq: ev2.Event}) expIDs := []string{"EVENT_1", "EVENT_2"} - rply := asr.Compress(10, "EVENT_3") + rply := asr.Compress(10, "EVENT_3", config.CgrConfig().GeneralCfg().RoundingDecimals) sort.Strings(rply) if !reflect.DeepEqual(expIDs, rply) { t.Errorf("Expected: %s , received: %s", utils.ToJSON(expIDs), utils.ToJSON(rply)) } - if strVal := asr.GetStringValue(""); strVal != "50%" { + if strVal := asr.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != "50%" { t.Errorf("wrong asr value: %s", strVal) } if !reflect.DeepEqual(*expected, *asr) { @@ -260,12 +260,12 @@ func TestASRCompress(t *testing.T) { Answered: 1, Count: 2, } - expected.GetStringValue("") + expected.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals) expIDs = []string{"EVENT_3"} - if rply := asr.Compress(1, "EVENT_3"); !reflect.DeepEqual(expIDs, rply) { + if rply := asr.Compress(1, "EVENT_3", config.CgrConfig().GeneralCfg().RoundingDecimals); !reflect.DeepEqual(expIDs, rply) { t.Errorf("Expected: %s , received: %s", utils.ToJSON(expIDs), utils.ToJSON(rply)) } - if strVal := asr.GetStringValue(""); strVal != "50%" { + if strVal := asr.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != "50%" { t.Errorf("wrong asr value: %s", strVal) } if !reflect.DeepEqual(*expected, *asr) { @@ -278,11 +278,11 @@ func TestASRCompress(t *testing.T) { v.CompressFactor = 4 expected.Count = 4 expected.val = nil - expected.GetStringValue("") - if rply := asr.Compress(1, "EVENT_3"); !reflect.DeepEqual(expIDs, rply) { + expected.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals) + if rply := asr.Compress(1, "EVENT_3", config.CgrConfig().GeneralCfg().RoundingDecimals); !reflect.DeepEqual(expIDs, rply) { t.Errorf("Expected: %s , received: %s", utils.ToJSON(expIDs), utils.ToJSON(rply)) } - if strVal := asr.GetStringValue(""); strVal != "25%" { + if strVal := asr.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != "25%" { t.Errorf("wrong asr value: %s", strVal) } if !reflect.DeepEqual(*expected, *asr) { @@ -328,13 +328,13 @@ func TestACDGetStringValue(t *testing.T) { utils.Usage: 10 * time.Second, "AnswerTime": time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC), }} - if strVal := acd.GetStringValue(""); strVal != utils.NOT_AVAILABLE { + if strVal := acd.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != utils.NOT_AVAILABLE { t.Errorf("wrong acd value: %s", strVal) } if err := acd.AddEvent(ev.ID, utils.MapStorage{utils.MetaReq: ev.Event}); err != nil { t.Error(err) } - if strVal := acd.GetStringValue(""); strVal != utils.NOT_AVAILABLE { + if strVal := acd.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != utils.NOT_AVAILABLE { t.Errorf("wrong acd value: %s", strVal) } ev2 := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_2"} @@ -345,14 +345,14 @@ func TestACDGetStringValue(t *testing.T) { if err := acd.AddEvent(ev3.ID, utils.MapStorage{utils.MetaReq: ev3.Event}); err == nil || err.Error() != "NOT_FOUND:Usage" { t.Error(err) } - if strVal := acd.GetStringValue(""); strVal != utils.NOT_AVAILABLE { + if strVal := acd.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != utils.NOT_AVAILABLE { t.Errorf("wrong acd value: %s", strVal) } - if strVal := acd.GetStringValue(""); strVal != utils.NOT_AVAILABLE { + if strVal := acd.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != utils.NOT_AVAILABLE { t.Errorf("wrong acd value: %s", strVal) } acd.RemEvent(ev.ID) - if strVal := acd.GetStringValue(""); strVal != utils.NOT_AVAILABLE { + if strVal := acd.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != utils.NOT_AVAILABLE { t.Errorf("wrong acd value: %s", strVal) } ev4 := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_4", @@ -368,21 +368,21 @@ func TestACDGetStringValue(t *testing.T) { }, } acd.AddEvent(ev4.ID, utils.MapStorage{utils.MetaReq: ev4.Event}) - if strVal := acd.GetStringValue(""); strVal != utils.NOT_AVAILABLE { + if strVal := acd.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != utils.NOT_AVAILABLE { t.Errorf("wrong acd value: %s", strVal) } acd.AddEvent(ev5.ID, utils.MapStorage{utils.MetaReq: ev5.Event}) - if strVal := acd.GetStringValue(""); strVal != "15.73043s" { + if strVal := acd.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != "15.73043s" { t.Errorf("wrong acd value: %s", strVal) } acd.RemEvent(ev2.ID) - if strVal := acd.GetStringValue(""); strVal != "15.73043s" { + if strVal := acd.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != "15.73043s" { t.Errorf("wrong acd value: %s", strVal) } acd.RemEvent(ev5.ID) acd.RemEvent(ev4.ID) acd.RemEvent(ev5.ID) - if strVal := acd.GetStringValue(""); strVal != utils.NOT_AVAILABLE { + if strVal := acd.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != utils.NOT_AVAILABLE { t.Errorf("wrong acd value: %s", strVal) } } @@ -397,16 +397,16 @@ func TestACDGetStringValue2(t *testing.T) { ev2 := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_2", Event: map[string]interface{}{"Usage": time.Minute}} acd.AddEvent(ev2.ID, utils.MapStorage{utils.MetaReq: ev2.Event}) - if strVal := acd.GetStringValue(""); strVal != "1m30s" { + if strVal := acd.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != "1m30s" { t.Errorf("wrong acd value: %s", strVal) } acd.AddEvent(ev2.ID, utils.MapStorage{utils.MetaReq: ev2.Event}) acd.AddEvent(ev2.ID, utils.MapStorage{utils.MetaReq: ev2.Event}) - if strVal := acd.GetStringValue(""); strVal != "1m15s" { + if strVal := acd.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != "1m15s" { t.Errorf("wrong acd value: %s", strVal) } acd.RemEvent(ev2.ID) - if strVal := acd.GetStringValue(""); strVal != "1m20s" { + if strVal := acd.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != "1m20s" { t.Errorf("wrong acd value: %s", strVal) } } @@ -423,7 +423,7 @@ func TestACDGetStringValue3(t *testing.T) { Count: 3, Sum: 6 * time.Minute, } - expected.GetStringValue("") + expected.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals) ev1 := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_1", Event: map[string]interface{}{utils.Usage: 2 * time.Minute}} ev2 := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_1", @@ -439,7 +439,7 @@ func TestACDGetStringValue3(t *testing.T) { if err := acd.AddEvent(ev3.ID, utils.MapStorage{utils.MetaReq: ev3.Event}); err != nil { t.Error(err) } - acd.GetStringValue("") + acd.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals) if !reflect.DeepEqual(*expected, *acd) { t.Errorf("Expected: %s , received: %s", utils.ToJSON(expected), utils.ToJSON(acd)) } @@ -448,9 +448,9 @@ func TestACDGetStringValue3(t *testing.T) { expected.Count = 2 expected.Sum = 3*time.Minute + 30*time.Second expected.val = nil - expected.GetStringValue("") + expected.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals) acd.RemEvent(ev1.ID) - acd.GetStringValue("") + acd.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals) if !reflect.DeepEqual(*expected, *acd) { t.Errorf("Expected: %s , received: %s", utils.ToJSON(expected), utils.ToJSON(acd)) } @@ -468,7 +468,7 @@ func TestACDCompress(t *testing.T) { Count: 3, Sum: 6 * time.Minute, } - expected.GetStringValue("") + expected.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals) ev1 := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_1", Event: map[string]interface{}{utils.Usage: 2 * time.Minute}} ev2 := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_1", @@ -479,12 +479,12 @@ func TestACDCompress(t *testing.T) { acd.AddEvent(ev2.ID, utils.MapStorage{utils.MetaReq: ev2.Event}) acd.AddEvent(ev3.ID, utils.MapStorage{utils.MetaReq: ev3.Event}) expIDs := []string{"EVENT_1", "EVENT_3"} - rply := acd.Compress(10, "EVENT_3") + rply := acd.Compress(10, "EVENT_3", config.CgrConfig().GeneralCfg().RoundingDecimals) sort.Strings(rply) if !reflect.DeepEqual(expIDs, rply) { t.Errorf("Expected: %s , received: %s", utils.ToJSON(expIDs), utils.ToJSON(rply)) } - acd.GetStringValue("") + acd.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals) if !reflect.DeepEqual(*expected, *acd) { t.Errorf("Expected: %s , received: %s", utils.ToJSON(expected), utils.ToJSON(acd)) } @@ -497,13 +497,13 @@ func TestACDCompress(t *testing.T) { Count: 3, Sum: 6 * time.Minute, } - expected.GetStringValue("") + expected.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals) expIDs = []string{"EVENT_3"} - if rply := acd.Compress(1, "EVENT_3"); !reflect.DeepEqual(expIDs, rply) { + if rply := acd.Compress(1, "EVENT_3", config.CgrConfig().GeneralCfg().RoundingDecimals); !reflect.DeepEqual(expIDs, rply) { t.Errorf("Expected: %s , received: %s", utils.ToJSON(expIDs), utils.ToJSON(rply)) } - acd.GetStringValue("") + acd.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals) if !reflect.DeepEqual(*expected, *acd) { t.Errorf("Expected: %s , received: %s", utils.ToJSON(expected), utils.ToJSON(acd)) } @@ -549,12 +549,12 @@ func TestACDGetFloat64Value(t *testing.T) { "AnswerTime": time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC), "Usage": 10 * time.Second}} acd.AddEvent(ev.ID, utils.MapStorage{utils.MetaReq: ev.Event}) - if v := acd.GetFloat64Value(); v != -1.0 { + if v := acd.GetFloat64Value(config.CgrConfig().GeneralCfg().RoundingDecimals); v != -1.0 { t.Errorf("wrong acd value: %v", v) } ev2 := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_2"} acd.AddEvent(ev2.ID, utils.MapStorage{utils.MetaReq: ev2.Event}) - if v := acd.GetFloat64Value(); v != -1.0 { + if v := acd.GetFloat64Value(config.CgrConfig().GeneralCfg().RoundingDecimals); v != -1.0 { t.Errorf("wrong acd value: %v", v) } ev4 := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_4", @@ -570,52 +570,52 @@ func TestACDGetFloat64Value(t *testing.T) { }, } acd.AddEvent(ev4.ID, utils.MapStorage{utils.MetaReq: ev4.Event}) - if strVal := acd.GetFloat64Value(); strVal != 35.0 { + if strVal := acd.GetFloat64Value(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != 35.0 { t.Errorf("wrong acd value: %v", strVal) } acd.AddEvent(ev5.ID, utils.MapStorage{utils.MetaReq: ev5.Event}) // by default rounding decimal is 5 - if strVal := acd.GetFloat64Value(); strVal != 53.33333 { + if strVal := acd.GetFloat64Value(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != 53.33333 { t.Errorf("wrong acd value: %v", strVal) } // test for other rounding decimals config.CgrConfig().GeneralCfg().RoundingDecimals = 0 acd.(*StatACD).val = nil - if strVal := acd.GetFloat64Value(); strVal != 53 { + if strVal := acd.GetFloat64Value(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != 53 { t.Errorf("wrong acd value: %v", strVal) } config.CgrConfig().GeneralCfg().RoundingDecimals = 1 acd.(*StatACD).val = nil - if strVal := acd.GetFloat64Value(); strVal != 53.3 { + if strVal := acd.GetFloat64Value(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != 53.3 { t.Errorf("wrong acd value: %v", strVal) } config.CgrConfig().GeneralCfg().RoundingDecimals = 9 acd.(*StatACD).val = nil - if strVal := acd.GetFloat64Value(); strVal != 53.333333333 { + if strVal := acd.GetFloat64Value(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != 53.333333333 { t.Errorf("wrong acd value: %v", strVal) } config.CgrConfig().GeneralCfg().RoundingDecimals = -1 acd.(*StatACD).val = nil - if strVal := acd.GetFloat64Value(); strVal != 50 { + if strVal := acd.GetFloat64Value(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != 50 { t.Errorf("wrong acd value: %v", strVal) } //change back the rounding decimals to default value config.CgrConfig().GeneralCfg().RoundingDecimals = 5 acd.(*StatACD).val = nil acd.RemEvent(ev2.ID) - if strVal := acd.GetFloat64Value(); strVal != 53.33333 { + if strVal := acd.GetFloat64Value(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != 53.33333 { t.Errorf("wrong acd value: %v", strVal) } acd.RemEvent(ev4.ID) - if strVal := acd.GetFloat64Value(); strVal != 50.0 { + if strVal := acd.GetFloat64Value(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != 50.0 { t.Errorf("wrong acd value: %v", strVal) } acd.RemEvent(ev.ID) - if strVal := acd.GetFloat64Value(); strVal != -1.0 { + if strVal := acd.GetFloat64Value(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != -1.0 { t.Errorf("wrong acd value: %v", strVal) } acd.RemEvent(ev5.ID) - if strVal := acd.GetFloat64Value(); strVal != -1.0 { + if strVal := acd.GetFloat64Value(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != -1.0 { t.Errorf("wrong acd value: %v", strVal) } } @@ -627,7 +627,7 @@ func TestACDGetValue(t *testing.T) { "AnswerTime": time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC), "Usage": 10 * time.Second}} acd.AddEvent(ev.ID, utils.MapStorage{utils.MetaReq: ev.Event}) - if v := acd.GetValue(); v != -time.Nanosecond { + if v := acd.GetValue(config.CgrConfig().GeneralCfg().RoundingDecimals); v != -time.Nanosecond { t.Errorf("wrong acd value: %+v", v) } ev2 := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_2", @@ -637,15 +637,15 @@ func TestACDGetValue(t *testing.T) { ev3 := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_3"} acd.AddEvent(ev2.ID, utils.MapStorage{utils.MetaReq: ev2.Event}) acd.AddEvent(ev3.ID, utils.MapStorage{utils.MetaReq: ev3.Event}) - if v := acd.GetValue(); v != 9*time.Second { + if v := acd.GetValue(config.CgrConfig().GeneralCfg().RoundingDecimals); v != 9*time.Second { t.Errorf("wrong acd value: %+v", v) } acd.RemEvent(ev.ID) - if v := acd.GetValue(); v != -time.Nanosecond { + if v := acd.GetValue(config.CgrConfig().GeneralCfg().RoundingDecimals); v != -time.Nanosecond { t.Errorf("wrong acd value: %+v", v) } acd.RemEvent(ev2.ID) - if v := acd.GetValue(); v != -time.Nanosecond { + if v := acd.GetValue(config.CgrConfig().GeneralCfg().RoundingDecimals); v != -time.Nanosecond { t.Errorf("wrong acd value: %+v", v) } ev4 := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_4", @@ -662,16 +662,16 @@ func TestACDGetValue(t *testing.T) { } acd.AddEvent(ev4.ID, utils.MapStorage{utils.MetaReq: ev4.Event}) acd.AddEvent(ev5.ID, utils.MapStorage{utils.MetaReq: ev5.Event}) - if v := acd.GetValue(); v != 2*time.Minute+45*time.Second { + if v := acd.GetValue(config.CgrConfig().GeneralCfg().RoundingDecimals); v != 2*time.Minute+45*time.Second { t.Errorf("wrong acd value: %+v", v) } acd.RemEvent(ev5.ID) acd.RemEvent(ev4.ID) - if v := acd.GetValue(); v != -time.Nanosecond { + if v := acd.GetValue(config.CgrConfig().GeneralCfg().RoundingDecimals); v != -time.Nanosecond { t.Errorf("wrong acd value: %+v", v) } acd.RemEvent(ev3.ID) - if v := acd.GetValue(); v != -time.Nanosecond { + if v := acd.GetValue(config.CgrConfig().GeneralCfg().RoundingDecimals); v != -time.Nanosecond { t.Errorf("wrong acd value: %+v", v) } } @@ -683,11 +683,11 @@ func TestTCDGetStringValue(t *testing.T) { "Usage": 10 * time.Second, "AnswerTime": time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC), }} - if strVal := tcd.GetStringValue(""); strVal != utils.NOT_AVAILABLE { + if strVal := tcd.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != utils.NOT_AVAILABLE { t.Errorf("wrong tcd value: %s", strVal) } tcd.AddEvent(ev.ID, utils.MapStorage{utils.MetaReq: ev.Event}) - if strVal := tcd.GetStringValue(""); strVal != utils.NOT_AVAILABLE { + if strVal := tcd.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != utils.NOT_AVAILABLE { t.Errorf("wrong tcd value: %s", strVal) } ev2 := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_2", @@ -698,15 +698,15 @@ func TestTCDGetStringValue(t *testing.T) { ev3 := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_3"} tcd.AddEvent(ev2.ID, utils.MapStorage{utils.MetaReq: ev2.Event}) tcd.AddEvent(ev3.ID, utils.MapStorage{utils.MetaReq: ev3.Event}) - if strVal := tcd.GetStringValue(""); strVal != "20s" { + if strVal := tcd.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != "20s" { t.Errorf("wrong tcd value: %s", strVal) } tcd.RemEvent(ev2.ID) - if strVal := tcd.GetStringValue(""); strVal != utils.NOT_AVAILABLE { + if strVal := tcd.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != utils.NOT_AVAILABLE { t.Errorf("wrong tcd value: %s", strVal) } tcd.RemEvent(ev.ID) - if strVal := tcd.GetStringValue(""); strVal != utils.NOT_AVAILABLE { + if strVal := tcd.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != utils.NOT_AVAILABLE { t.Errorf("wrong tcd value: %s", strVal) } ev4 := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_4", @@ -723,16 +723,16 @@ func TestTCDGetStringValue(t *testing.T) { } tcd.AddEvent(ev4.ID, utils.MapStorage{utils.MetaReq: ev4.Event}) tcd.AddEvent(ev5.ID, utils.MapStorage{utils.MetaReq: ev5.Event}) - if strVal := tcd.GetStringValue(""); strVal != "2m30s" { + if strVal := tcd.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != "2m30s" { t.Errorf("wrong tcd value: %s", strVal) } tcd.RemEvent(ev4.ID) - if strVal := tcd.GetStringValue(""); strVal != utils.NOT_AVAILABLE { + if strVal := tcd.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != utils.NOT_AVAILABLE { t.Errorf("wrong tcd value: %s", strVal) } tcd.RemEvent(ev5.ID) tcd.RemEvent(ev3.ID) - if strVal := tcd.GetStringValue(""); strVal != utils.NOT_AVAILABLE { + if strVal := tcd.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != utils.NOT_AVAILABLE { t.Errorf("wrong tcd value: %s", strVal) } } @@ -747,16 +747,16 @@ func TestTCDGetStringValue2(t *testing.T) { ev2 := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_2", Event: map[string]interface{}{"Usage": time.Minute}} tcd.AddEvent(ev2.ID, utils.MapStorage{utils.MetaReq: ev2.Event}) - if strVal := tcd.GetStringValue(""); strVal != "3m0s" { + if strVal := tcd.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != "3m0s" { t.Errorf("wrong tcd value: %s", strVal) } tcd.AddEvent(ev2.ID, utils.MapStorage{utils.MetaReq: ev2.Event}) tcd.AddEvent(ev2.ID, utils.MapStorage{utils.MetaReq: ev2.Event}) - if strVal := tcd.GetStringValue(""); strVal != "5m0s" { + if strVal := tcd.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != "5m0s" { t.Errorf("wrong tcd value: %s", strVal) } tcd.RemEvent(ev2.ID) - if strVal := tcd.GetStringValue(""); strVal != "4m0s" { + if strVal := tcd.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != "4m0s" { t.Errorf("wrong tcd value: %s", strVal) } } @@ -773,7 +773,7 @@ func TestTCDGetStringValue3(t *testing.T) { Count: 3, Sum: 6 * time.Minute, } - expected.GetStringValue("") + expected.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals) ev1 := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_1", Event: map[string]interface{}{utils.Usage: 2 * time.Minute}} ev2 := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_1", @@ -789,7 +789,7 @@ func TestTCDGetStringValue3(t *testing.T) { if err := tcd.AddEvent(ev3.ID, utils.MapStorage{utils.MetaReq: ev3.Event}); err != nil { t.Error(err) } - tcd.GetStringValue("") + tcd.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals) if !reflect.DeepEqual(*expected, *tcd) { t.Errorf("Expected: %s , received: %s", utils.ToJSON(expected), utils.ToJSON(tcd)) } @@ -798,9 +798,9 @@ func TestTCDGetStringValue3(t *testing.T) { expected.Count = 2 expected.Sum = 3*time.Minute + 30*time.Second expected.val = nil - expected.GetStringValue("") + expected.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals) tcd.RemEvent(ev1.ID) - tcd.GetStringValue("") + tcd.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals) if !reflect.DeepEqual(*expected, *tcd) { t.Errorf("Expected: %s , received: %s", utils.ToJSON(expected), utils.ToJSON(tcd)) } @@ -813,12 +813,12 @@ func TestTCDGetFloat64Value(t *testing.T) { "AnswerTime": time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC), "Usage": 10 * time.Second}} tcd.AddEvent(ev.ID, utils.MapStorage{utils.MetaReq: ev.Event}) - if v := tcd.GetFloat64Value(); v != -1.0 { + if v := tcd.GetFloat64Value(config.CgrConfig().GeneralCfg().RoundingDecimals); v != -1.0 { t.Errorf("wrong tcd value: %f", v) } ev2 := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_2"} tcd.AddEvent(ev2.ID, utils.MapStorage{utils.MetaReq: ev2.Event}) - if v := tcd.GetFloat64Value(); v != -1.0 { + if v := tcd.GetFloat64Value(config.CgrConfig().GeneralCfg().RoundingDecimals); v != -1.0 { t.Errorf("wrong tcd value: %f", v) } ev4 := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_4", @@ -834,27 +834,27 @@ func TestTCDGetFloat64Value(t *testing.T) { }, } tcd.AddEvent(ev4.ID, utils.MapStorage{utils.MetaReq: ev4.Event}) - if strVal := tcd.GetFloat64Value(); strVal != 70.0 { + if strVal := tcd.GetFloat64Value(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != 70.0 { t.Errorf("wrong tcd value: %f", strVal) } tcd.AddEvent(ev5.ID, utils.MapStorage{utils.MetaReq: ev5.Event}) - if strVal := tcd.GetFloat64Value(); strVal != 160.0 { + if strVal := tcd.GetFloat64Value(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != 160.0 { t.Errorf("wrong tcd value: %f", strVal) } tcd.RemEvent(ev2.ID) - if strVal := tcd.GetFloat64Value(); strVal != 160.0 { + if strVal := tcd.GetFloat64Value(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != 160.0 { t.Errorf("wrong tcd value: %f", strVal) } tcd.RemEvent(ev4.ID) - if strVal := tcd.GetFloat64Value(); strVal != 100.0 { + if strVal := tcd.GetFloat64Value(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != 100.0 { t.Errorf("wrong tcd value: %f", strVal) } tcd.RemEvent(ev.ID) - if strVal := tcd.GetFloat64Value(); strVal != -1.0 { + if strVal := tcd.GetFloat64Value(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != -1.0 { t.Errorf("wrong tcd value: %f", strVal) } tcd.RemEvent(ev5.ID) - if strVal := tcd.GetFloat64Value(); strVal != -1.0 { + if strVal := tcd.GetFloat64Value(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != -1.0 { t.Errorf("wrong tcd value: %f", strVal) } } @@ -866,7 +866,7 @@ func TestTCDGetValue(t *testing.T) { "AnswerTime": time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC), "Usage": 10 * time.Second}} tcd.AddEvent(ev.ID, utils.MapStorage{utils.MetaReq: ev.Event}) - if v := tcd.GetValue(); v != -time.Nanosecond { + if v := tcd.GetValue(config.CgrConfig().GeneralCfg().RoundingDecimals); v != -time.Nanosecond { t.Errorf("wrong tcd value: %+v", v) } ev2 := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_2", @@ -876,15 +876,15 @@ func TestTCDGetValue(t *testing.T) { ev3 := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_3"} tcd.AddEvent(ev2.ID, utils.MapStorage{utils.MetaReq: ev2.Event}) tcd.AddEvent(ev3.ID, utils.MapStorage{utils.MetaReq: ev3.Event}) - if v := tcd.GetValue(); v != 15*time.Second { + if v := tcd.GetValue(config.CgrConfig().GeneralCfg().RoundingDecimals); v != 15*time.Second { t.Errorf("wrong tcd value: %+v", v) } tcd.RemEvent(ev.ID) - if v := tcd.GetValue(); v != -time.Nanosecond { + if v := tcd.GetValue(config.CgrConfig().GeneralCfg().RoundingDecimals); v != -time.Nanosecond { t.Errorf("wrong tcd value: %+v", v) } tcd.RemEvent(ev2.ID) - if v := tcd.GetValue(); v != -time.Nanosecond { + if v := tcd.GetValue(config.CgrConfig().GeneralCfg().RoundingDecimals); v != -time.Nanosecond { t.Errorf("wrong tcd value: %+v", v) } ev4 := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_4", @@ -901,16 +901,16 @@ func TestTCDGetValue(t *testing.T) { } tcd.AddEvent(ev4.ID, utils.MapStorage{utils.MetaReq: ev4.Event}) tcd.AddEvent(ev5.ID, utils.MapStorage{utils.MetaReq: ev5.Event}) - if v := tcd.GetValue(); v != 2*time.Minute+30*time.Second { + if v := tcd.GetValue(config.CgrConfig().GeneralCfg().RoundingDecimals); v != 2*time.Minute+30*time.Second { t.Errorf("wrong tcd value: %+v", v) } tcd.RemEvent(ev5.ID) tcd.RemEvent(ev4.ID) - if v := tcd.GetValue(); v != -time.Nanosecond { + if v := tcd.GetValue(config.CgrConfig().GeneralCfg().RoundingDecimals); v != -time.Nanosecond { t.Errorf("wrong tcd value: %+v", v) } tcd.RemEvent(ev3.ID) - if v := tcd.GetValue(); v != -time.Nanosecond { + if v := tcd.GetValue(config.CgrConfig().GeneralCfg().RoundingDecimals); v != -time.Nanosecond { t.Errorf("wrong tcd value: %+v", v) } } @@ -927,7 +927,7 @@ func TestTCDCompress(t *testing.T) { Count: 3, Sum: 6 * time.Minute, } - expected.GetStringValue("") + expected.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals) ev1 := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_1", Event: map[string]interface{}{utils.Usage: 2 * time.Minute}} ev2 := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_1", @@ -938,12 +938,12 @@ func TestTCDCompress(t *testing.T) { tcd.AddEvent(ev2.ID, utils.MapStorage{utils.MetaReq: ev2.Event}) tcd.AddEvent(ev3.ID, utils.MapStorage{utils.MetaReq: ev3.Event}) expIDs := []string{"EVENT_1", "EVENT_3"} - rply := tcd.Compress(10, "EVENT_3") + rply := tcd.Compress(10, "EVENT_3", config.CgrConfig().GeneralCfg().RoundingDecimals) sort.Strings(rply) if !reflect.DeepEqual(expIDs, rply) { t.Errorf("Expected: %s , received: %s", utils.ToJSON(expIDs), utils.ToJSON(rply)) } - tcd.GetStringValue("") + tcd.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals) if !reflect.DeepEqual(*expected, *tcd) { t.Errorf("Expected: %s , received: %s", utils.ToJSON(expected), utils.ToJSON(tcd)) } @@ -956,13 +956,13 @@ func TestTCDCompress(t *testing.T) { Count: 3, Sum: 6 * time.Minute, } - expected.GetStringValue("") + expected.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals) expIDs = []string{"EVENT_3"} - if rply := tcd.Compress(1, "EVENT_3"); !reflect.DeepEqual(expIDs, rply) { + if rply := tcd.Compress(1, "EVENT_3", config.CgrConfig().GeneralCfg().RoundingDecimals); !reflect.DeepEqual(expIDs, rply) { t.Errorf("Expected: %s , received: %s", utils.ToJSON(expIDs), utils.ToJSON(rply)) } - tcd.GetStringValue("") + tcd.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals) if !reflect.DeepEqual(*expected, *tcd) { t.Errorf("Expected: %s , received: %s", utils.ToJSON(expected), utils.ToJSON(tcd)) } @@ -1007,11 +1007,11 @@ func TestACCGetStringValue(t *testing.T) { Event: map[string]interface{}{ "AnswerTime": time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC), "Cost": 12.3}} - if strVal := acc.GetStringValue(""); strVal != utils.NOT_AVAILABLE { + if strVal := acc.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != utils.NOT_AVAILABLE { t.Errorf("wrong acc value: %s", strVal) } acc.AddEvent(ev.ID, utils.MapStorage{utils.MetaReq: ev.Event}) - if strVal := acc.GetStringValue(""); strVal != utils.NOT_AVAILABLE { + if strVal := acc.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != utils.NOT_AVAILABLE { t.Errorf("wrong acc value: %s", strVal) } ev2 := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_2"} @@ -1021,11 +1021,11 @@ func TestACCGetStringValue(t *testing.T) { "Cost": 12.3}} acc.AddEvent(ev2.ID, utils.MapStorage{utils.MetaReq: ev2.Event}) acc.AddEvent(ev3.ID, utils.MapStorage{utils.MetaReq: ev3.Event}) - if strVal := acc.GetStringValue(""); strVal != "12.3" { + if strVal := acc.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != "12.3" { t.Errorf("wrong acc value: %s", strVal) } acc.RemEvent(ev3.ID) - if strVal := acc.GetStringValue(""); strVal != utils.NOT_AVAILABLE { + if strVal := acc.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != utils.NOT_AVAILABLE { t.Errorf("wrong acc value: %s", strVal) } ev4 := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_4", @@ -1039,16 +1039,16 @@ func TestACCGetStringValue(t *testing.T) { acc.AddEvent(ev4.ID, utils.MapStorage{utils.MetaReq: ev4.Event}) acc.AddEvent(ev5.ID, utils.MapStorage{utils.MetaReq: ev5.Event}) acc.RemEvent(ev.ID) - if strVal := acc.GetStringValue(""); strVal != "3.4" { + if strVal := acc.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != "3.4" { t.Errorf("wrong acc value: %s", strVal) } acc.RemEvent(ev2.ID) - if strVal := acc.GetStringValue(""); strVal != "3.4" { + if strVal := acc.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != "3.4" { t.Errorf("wrong acc value: %s", strVal) } acc.RemEvent(ev4.ID) acc.RemEvent(ev5.ID) - if strVal := acc.GetStringValue(""); strVal != utils.NOT_AVAILABLE { + if strVal := acc.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != utils.NOT_AVAILABLE { t.Errorf("wrong acc value: %s", strVal) } } @@ -1063,16 +1063,16 @@ func TestACCGetStringValue2(t *testing.T) { ev2 := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_2", Event: map[string]interface{}{"Cost": 18.3}} acc.AddEvent(ev2.ID, utils.MapStorage{utils.MetaReq: ev2.Event}) - if strVal := acc.GetStringValue(""); strVal != "15.3" { + if strVal := acc.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != "15.3" { t.Errorf("wrong acc value: %s", strVal) } acc.AddEvent(ev2.ID, utils.MapStorage{utils.MetaReq: ev2.Event}) acc.AddEvent(ev2.ID, utils.MapStorage{utils.MetaReq: ev2.Event}) - if strVal := acc.GetStringValue(""); strVal != "16.8" { + if strVal := acc.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != "16.8" { t.Errorf("wrong acc value: %s", strVal) } acc.RemEvent(ev2.ID) - if strVal := acc.GetStringValue(""); strVal != "16.3" { + if strVal := acc.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != "16.3" { t.Errorf("wrong acc value: %s", strVal) } } @@ -1089,7 +1089,7 @@ func TestACCGetStringValue3(t *testing.T) { Count: 3, Sum: 42.7, } - expected.GetStringValue("") + expected.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals) ev1 := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_1", Event: map[string]interface{}{"Cost": 18.2}} ev2 := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_1", @@ -1105,7 +1105,7 @@ func TestACCGetStringValue3(t *testing.T) { if err := acc.AddEvent(ev3.ID, utils.MapStorage{utils.MetaReq: ev3.Event}); err != nil { t.Error(err) } - acc.GetStringValue("") + acc.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals) if !reflect.DeepEqual(*expected, *acc) { t.Errorf("Expected: %s , received: %s", utils.ToJSON(expected), utils.ToJSON(acc)) } @@ -1114,9 +1114,9 @@ func TestACCGetStringValue3(t *testing.T) { expected.Count = 2 expected.Sum = expected.Sum - 12.2 expected.val = nil - expected.GetStringValue("") + expected.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals) acc.RemEvent(ev1.ID) - acc.GetStringValue("") + acc.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals) if !reflect.DeepEqual(*expected, *acc) { t.Errorf("Expected: %s , received: %s", utils.ToJSON(expected), utils.ToJSON(acc)) } @@ -1128,22 +1128,22 @@ func TestACCGetValue(t *testing.T) { Event: map[string]interface{}{ "AnswerTime": time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC), "Cost": "12.3"}} - if strVal := acc.GetValue(); strVal != -1.0 { + if strVal := acc.GetValue(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != -1.0 { t.Errorf("wrong acc value: %v", strVal) } acc.AddEvent(ev.ID, utils.MapStorage{utils.MetaReq: ev.Event}) - if strVal := acc.GetValue(); strVal != -1.0 { + if strVal := acc.GetValue(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != -1.0 { t.Errorf("wrong acc value: %v", strVal) } ev2 := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_2"} ev3 := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_3"} acc.AddEvent(ev2.ID, utils.MapStorage{utils.MetaReq: ev2.Event}) acc.AddEvent(ev3.ID, utils.MapStorage{utils.MetaReq: ev3.Event}) - if strVal := acc.GetValue(); strVal != -1.0 { + if strVal := acc.GetValue(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != -1.0 { t.Errorf("wrong acc value: %v", strVal) } acc.RemEvent(ev3.ID) - if strVal := acc.GetValue(); strVal != -1.0 { + if strVal := acc.GetValue(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != -1.0 { t.Errorf("wrong acc value: %v", strVal) } ev4 := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_4", @@ -1157,16 +1157,16 @@ func TestACCGetValue(t *testing.T) { acc.AddEvent(ev4.ID, utils.MapStorage{utils.MetaReq: ev4.Event}) acc.AddEvent(ev5.ID, utils.MapStorage{utils.MetaReq: ev5.Event}) acc.RemEvent(ev.ID) - if strVal := acc.GetValue(); strVal != 3.4 { + if strVal := acc.GetValue(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != 3.4 { t.Errorf("wrong acc value: %v", strVal) } acc.RemEvent(ev2.ID) - if strVal := acc.GetValue(); strVal != 3.4 { + if strVal := acc.GetValue(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != 3.4 { t.Errorf("wrong acc value: %v", strVal) } acc.RemEvent(ev4.ID) acc.RemEvent(ev5.ID) - if strVal := acc.GetValue(); strVal != -1.0 { + if strVal := acc.GetValue(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != -1.0 { t.Errorf("wrong acc value: %v", strVal) } } @@ -1184,7 +1184,7 @@ func TestACCCompress(t *testing.T) { Sum: 24.4, Count: 2, } - expected.GetStringValue("") + expected.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals) ev := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_1", Event: map[string]interface{}{"Cost": 18.2}} ev2 := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_2", @@ -1194,12 +1194,12 @@ func TestACCCompress(t *testing.T) { acc.AddEvent(ev.ID, utils.MapStorage{utils.MetaReq: ev.Event}) acc.AddEvent(ev2.ID, utils.MapStorage{utils.MetaReq: ev2.Event}) expIDs := []string{"EVENT_1", "EVENT_2"} - rply := acc.Compress(10, "EVENT_3") + rply := acc.Compress(10, "EVENT_3", config.CgrConfig().GeneralCfg().RoundingDecimals) sort.Strings(rply) if !reflect.DeepEqual(expIDs, rply) { t.Errorf("Expected: %s , received: %s", utils.ToJSON(expIDs), utils.ToJSON(rply)) } - acc.GetStringValue("") + acc.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals) if !reflect.DeepEqual(*expected, *acc) { t.Errorf("Expected: %s , received: %s", utils.ToJSON(expected), utils.ToJSON(acc)) } @@ -1212,12 +1212,12 @@ func TestACCCompress(t *testing.T) { Sum: 24.4, Count: 2, } - expected.GetStringValue("") + expected.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals) expIDs = []string{"EVENT_3"} - if rply := acc.Compress(1, "EVENT_3"); !reflect.DeepEqual(expIDs, rply) { + if rply := acc.Compress(1, "EVENT_3", config.CgrConfig().GeneralCfg().RoundingDecimals); !reflect.DeepEqual(expIDs, rply) { t.Errorf("Expected: %s , received: %s", utils.ToJSON(expIDs), utils.ToJSON(rply)) } - acc.GetStringValue("") + acc.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals) if !reflect.DeepEqual(*expected, *acc) { t.Errorf("Expected: %s , received: %s", utils.ToJSON(expected), utils.ToJSON(acc)) } @@ -1229,11 +1229,11 @@ func TestACCCompress(t *testing.T) { expected.Count = 4 expected.Sum = 48.9 expected.val = nil - expected.GetStringValue("") - if rply := acc.Compress(1, "EVENT_3"); !reflect.DeepEqual(expIDs, rply) { + expected.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals) + if rply := acc.Compress(1, "EVENT_3", config.CgrConfig().GeneralCfg().RoundingDecimals); !reflect.DeepEqual(expIDs, rply) { t.Errorf("Expected: %s , received: %s", utils.ToJSON(expIDs), utils.ToJSON(rply)) } - acc.GetStringValue("") + acc.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals) if !reflect.DeepEqual(*expected, *acc) { t.Errorf("Expected: %s , received: %s", utils.ToJSON(expected), utils.ToJSON(acc)) } @@ -1277,11 +1277,11 @@ func TestTCCGetStringValue(t *testing.T) { Event: map[string]interface{}{ "AnswerTime": time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC), "Cost": 12.3}} - if strVal := tcc.GetStringValue(""); strVal != utils.NOT_AVAILABLE { + if strVal := tcc.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != utils.NOT_AVAILABLE { t.Errorf("wrong tcc value: %s", strVal) } tcc.AddEvent(ev.ID, utils.MapStorage{utils.MetaReq: ev.Event}) - if strVal := tcc.GetStringValue(""); strVal != utils.NOT_AVAILABLE { + if strVal := tcc.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != utils.NOT_AVAILABLE { t.Errorf("wrong tcc value: %s", strVal) } ev2 := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_2"} @@ -1291,11 +1291,11 @@ func TestTCCGetStringValue(t *testing.T) { "Cost": 5.7}} tcc.AddEvent(ev2.ID, utils.MapStorage{utils.MetaReq: ev2.Event}) tcc.AddEvent(ev3.ID, utils.MapStorage{utils.MetaReq: ev3.Event}) - if strVal := tcc.GetStringValue(""); strVal != "18" { + if strVal := tcc.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != "18" { t.Errorf("wrong tcc value: %s", strVal) } tcc.RemEvent(ev3.ID) - if strVal := tcc.GetStringValue(""); strVal != utils.NOT_AVAILABLE { + if strVal := tcc.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != utils.NOT_AVAILABLE { t.Errorf("wrong tcc value: %s", strVal) } ev4 := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_4", @@ -1309,16 +1309,16 @@ func TestTCCGetStringValue(t *testing.T) { tcc.AddEvent(ev4.ID, utils.MapStorage{utils.MetaReq: ev4.Event}) tcc.AddEvent(ev5.ID, utils.MapStorage{utils.MetaReq: ev5.Event}) tcc.RemEvent(ev.ID) - if strVal := tcc.GetStringValue(""); strVal != "6.8" { + if strVal := tcc.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != "6.8" { t.Errorf("wrong tcc value: %s", strVal) } tcc.RemEvent(ev2.ID) - if strVal := tcc.GetStringValue(""); strVal != "6.8" { + if strVal := tcc.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != "6.8" { t.Errorf("wrong tcc value: %s", strVal) } tcc.RemEvent(ev4.ID) tcc.RemEvent(ev5.ID) - if strVal := tcc.GetStringValue(""); strVal != utils.NOT_AVAILABLE { + if strVal := tcc.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != utils.NOT_AVAILABLE { t.Errorf("wrong tcc value: %s", strVal) } } @@ -1333,16 +1333,16 @@ func TestTCCGetStringValue2(t *testing.T) { ev2 := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_2", Event: map[string]interface{}{"Cost": 18.3}} tcc.AddEvent(ev2.ID, utils.MapStorage{utils.MetaReq: ev2.Event}) - if strVal := tcc.GetStringValue(""); strVal != "30.6" { + if strVal := tcc.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != "30.6" { t.Errorf("wrong tcc value: %s", strVal) } tcc.AddEvent(ev2.ID, utils.MapStorage{utils.MetaReq: ev2.Event}) tcc.AddEvent(ev2.ID, utils.MapStorage{utils.MetaReq: ev2.Event}) - if strVal := tcc.GetStringValue(""); strVal != "67.2" { + if strVal := tcc.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != "67.2" { t.Errorf("wrong tcc value: %s", strVal) } tcc.RemEvent(ev2.ID) - if strVal := tcc.GetStringValue(""); strVal != "48.9" { + if strVal := tcc.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != "48.9" { t.Errorf("wrong tcc value: %s", strVal) } } @@ -1359,7 +1359,7 @@ func TestTCCGetStringValue3(t *testing.T) { Count: 3, Sum: 42.7, } - expected.GetStringValue("") + expected.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals) ev1 := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_1", Event: map[string]interface{}{"Cost": 18.2}} ev2 := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_1", @@ -1375,7 +1375,7 @@ func TestTCCGetStringValue3(t *testing.T) { if err := tcc.AddEvent(ev3.ID, utils.MapStorage{utils.MetaReq: ev3.Event}); err != nil { t.Error(err) } - tcc.GetStringValue("") + tcc.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals) if !reflect.DeepEqual(*expected, *tcc) { t.Errorf("Expected: %s , received: %s", utils.ToJSON(expected), utils.ToJSON(tcc)) } @@ -1384,9 +1384,9 @@ func TestTCCGetStringValue3(t *testing.T) { expected.Count = 2 expected.Sum = expected.Sum - 12.2 expected.val = nil - expected.GetStringValue("") + expected.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals) tcc.RemEvent(ev1.ID) - tcc.GetStringValue("") + tcc.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals) if !reflect.DeepEqual(*expected, *tcc) { t.Errorf("Expected: %s , received: %s", utils.ToJSON(expected), utils.ToJSON(tcc)) } @@ -1398,11 +1398,11 @@ func TestTCCGetValue(t *testing.T) { Event: map[string]interface{}{ "AnswerTime": time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC), "Cost": "12.3"}} - if strVal := tcc.GetValue(); strVal != -1.0 { + if strVal := tcc.GetValue(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != -1.0 { t.Errorf("wrong tcc value: %v", strVal) } tcc.AddEvent(ev.ID, utils.MapStorage{utils.MetaReq: ev.Event}) - if strVal := tcc.GetValue(); strVal != -1.0 { + if strVal := tcc.GetValue(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != -1.0 { t.Errorf("wrong tcc value: %v", strVal) } ev2 := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_2"} @@ -1412,11 +1412,11 @@ func TestTCCGetValue(t *testing.T) { "Cost": 1.2}} tcc.AddEvent(ev2.ID, utils.MapStorage{utils.MetaReq: ev2.Event}) tcc.AddEvent(ev3.ID, utils.MapStorage{utils.MetaReq: ev3.Event}) - if strVal := tcc.GetValue(); strVal != 13.5 { + if strVal := tcc.GetValue(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != 13.5 { t.Errorf("wrong tcc value: %v", strVal) } tcc.RemEvent(ev3.ID) - if strVal := tcc.GetValue(); strVal != -1.0 { + if strVal := tcc.GetValue(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != -1.0 { t.Errorf("wrong tcc value: %v", strVal) } ev4 := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_4", @@ -1430,16 +1430,16 @@ func TestTCCGetValue(t *testing.T) { tcc.AddEvent(ev4.ID, utils.MapStorage{utils.MetaReq: ev4.Event}) tcc.AddEvent(ev5.ID, utils.MapStorage{utils.MetaReq: ev5.Event}) tcc.RemEvent(ev.ID) - if strVal := tcc.GetValue(); strVal != 6.8 { + if strVal := tcc.GetValue(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != 6.8 { t.Errorf("wrong tcc value: %v", strVal) } tcc.RemEvent(ev2.ID) - if strVal := tcc.GetValue(); strVal != 6.8 { + if strVal := tcc.GetValue(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != 6.8 { t.Errorf("wrong tcc value: %v", strVal) } tcc.RemEvent(ev4.ID) tcc.RemEvent(ev5.ID) - if strVal := tcc.GetValue(); strVal != -1.0 { + if strVal := tcc.GetValue(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != -1.0 { t.Errorf("wrong tcc value: %v", strVal) } } @@ -1457,7 +1457,7 @@ func TestTCCCompress(t *testing.T) { Sum: 24.4, Count: 2, } - expected.GetStringValue("") + expected.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals) ev := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_1", Event: map[string]interface{}{"Cost": 18.2}} ev2 := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_2", @@ -1467,12 +1467,12 @@ func TestTCCCompress(t *testing.T) { tcc.AddEvent(ev.ID, utils.MapStorage{utils.MetaReq: ev.Event}) tcc.AddEvent(ev2.ID, utils.MapStorage{utils.MetaReq: ev2.Event}) expIDs := []string{"EVENT_1", "EVENT_2"} - rply := tcc.Compress(10, "EVENT_3") + rply := tcc.Compress(10, "EVENT_3", config.CgrConfig().GeneralCfg().RoundingDecimals) sort.Strings(rply) if !reflect.DeepEqual(expIDs, rply) { t.Errorf("Expected: %s , received: %s", utils.ToJSON(expIDs), utils.ToJSON(rply)) } - tcc.GetStringValue("") + tcc.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals) if !reflect.DeepEqual(*expected, *tcc) { t.Errorf("Expected: %s , received: %s", utils.ToJSON(expected), utils.ToJSON(tcc)) } @@ -1485,12 +1485,12 @@ func TestTCCCompress(t *testing.T) { Sum: 24.4, Count: 2, } - expected.GetStringValue("") + expected.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals) expIDs = []string{"EVENT_3"} - if rply := tcc.Compress(1, "EVENT_3"); !reflect.DeepEqual(expIDs, rply) { + if rply := tcc.Compress(1, "EVENT_3", config.CgrConfig().GeneralCfg().RoundingDecimals); !reflect.DeepEqual(expIDs, rply) { t.Errorf("Expected: %s , received: %s", utils.ToJSON(expIDs), utils.ToJSON(rply)) } - tcc.GetStringValue("") + tcc.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals) if !reflect.DeepEqual(*expected, *tcc) { t.Errorf("Expected: %s , received: %s", utils.ToJSON(expected), utils.ToJSON(tcc)) } @@ -1502,11 +1502,11 @@ func TestTCCCompress(t *testing.T) { expected.Count = 4 expected.Sum = 48.9 expected.val = nil - expected.GetStringValue("") - if rply := tcc.Compress(1, "EVENT_3"); !reflect.DeepEqual(expIDs, rply) { + expected.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals) + if rply := tcc.Compress(1, "EVENT_3", config.CgrConfig().GeneralCfg().RoundingDecimals); !reflect.DeepEqual(expIDs, rply) { t.Errorf("Expected: %s , received: %s", utils.ToJSON(expIDs), utils.ToJSON(rply)) } - tcc.GetStringValue("") + tcc.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals) if !reflect.DeepEqual(*expected, *tcc) { t.Errorf("Expected: %s , received: %s", utils.ToJSON(expected), utils.ToJSON(tcc)) } @@ -1552,26 +1552,26 @@ func TestPDDGetStringValue(t *testing.T) { "AnswerTime": time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC), utils.PDD: 5 * time.Second, }} - if strVal := pdd.GetStringValue(""); strVal != utils.NOT_AVAILABLE { + if strVal := pdd.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != utils.NOT_AVAILABLE { t.Errorf("wrong pdd value: %s", strVal) } pdd.AddEvent(ev.ID, utils.MapStorage{utils.MetaReq: ev.Event}) - if strVal := pdd.GetStringValue(""); strVal != utils.NOT_AVAILABLE { + if strVal := pdd.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != utils.NOT_AVAILABLE { t.Errorf("wrong pdd value: %s", strVal) } ev2 := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_2"} ev3 := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_3"} pdd.AddEvent(ev2.ID, utils.MapStorage{utils.MetaReq: ev2.Event}) pdd.AddEvent(ev3.ID, utils.MapStorage{utils.MetaReq: ev3.Event}) - if strVal := pdd.GetStringValue(""); strVal != utils.NOT_AVAILABLE { + if strVal := pdd.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != utils.NOT_AVAILABLE { t.Errorf("wrong pdd value: %s", strVal) } pdd.RemEvent(ev3.ID) - if strVal := pdd.GetStringValue(""); strVal != utils.NOT_AVAILABLE { + if strVal := pdd.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != utils.NOT_AVAILABLE { t.Errorf("wrong pdd value: %s", strVal) } pdd.RemEvent(ev.ID) - if strVal := pdd.GetStringValue(""); strVal != utils.NOT_AVAILABLE { + if strVal := pdd.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != utils.NOT_AVAILABLE { t.Errorf("wrong pdd value: %s", strVal) } ev4 := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_4", @@ -1587,21 +1587,21 @@ func TestPDDGetStringValue(t *testing.T) { }, } pdd.AddEvent(ev4.ID, utils.MapStorage{utils.MetaReq: ev4.Event}) - if strVal := pdd.GetStringValue(""); strVal != utils.NOT_AVAILABLE { + if strVal := pdd.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != utils.NOT_AVAILABLE { t.Errorf("wrong pdd value: %s", strVal) } pdd.AddEvent(ev5.ID, utils.MapStorage{utils.MetaReq: ev5.Event}) - if strVal := pdd.GetStringValue(""); strVal != "10s" { + if strVal := pdd.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != "10s" { t.Errorf("wrong pdd value: %s", strVal) } pdd.RemEvent(ev2.ID) - if strVal := pdd.GetStringValue(""); strVal != "10s" { + if strVal := pdd.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != "10s" { t.Errorf("wrong pdd value: %s", strVal) } pdd.RemEvent(ev5.ID) pdd.RemEvent(ev4.ID) pdd.RemEvent(ev5.ID) - if strVal := pdd.GetStringValue(""); strVal != utils.NOT_AVAILABLE { + if strVal := pdd.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != utils.NOT_AVAILABLE { t.Errorf("wrong pdd value: %s", strVal) } } @@ -1616,16 +1616,16 @@ func TestPDDGetStringValue2(t *testing.T) { ev2 := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_2", Event: map[string]interface{}{utils.PDD: time.Minute}} pdd.AddEvent(ev2.ID, utils.MapStorage{utils.MetaReq: ev2.Event}) - if strVal := pdd.GetStringValue(""); strVal != "1m30s" { + if strVal := pdd.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != "1m30s" { t.Errorf("wrong pdd value: %s", strVal) } pdd.AddEvent(ev2.ID, utils.MapStorage{utils.MetaReq: ev2.Event}) pdd.AddEvent(ev2.ID, utils.MapStorage{utils.MetaReq: ev2.Event}) - if strVal := pdd.GetStringValue(""); strVal != "1m15s" { + if strVal := pdd.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != "1m15s" { t.Errorf("wrong pdd value: %s", strVal) } pdd.RemEvent(ev2.ID) - if strVal := pdd.GetStringValue(""); strVal != "1m20s" { + if strVal := pdd.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != "1m20s" { t.Errorf("wrong pdd value: %s", strVal) } } @@ -1642,7 +1642,7 @@ func TestPDDGetStringValue3(t *testing.T) { Count: 3, Sum: 6 * time.Minute, } - expected.GetStringValue("") + expected.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals) ev1 := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_1", Event: map[string]interface{}{utils.PDD: 2 * time.Minute}} ev2 := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_1", @@ -1658,7 +1658,7 @@ func TestPDDGetStringValue3(t *testing.T) { if err := pdd.AddEvent(ev3.ID, utils.MapStorage{utils.MetaReq: ev3.Event}); err != nil { t.Error(err) } - pdd.GetStringValue("") + pdd.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals) if !reflect.DeepEqual(*expected, *pdd) { t.Errorf("Expected: %s , received: %s", utils.ToJSON(expected), utils.ToJSON(pdd)) } @@ -1667,9 +1667,9 @@ func TestPDDGetStringValue3(t *testing.T) { expected.Count = 2 expected.Sum = 3*time.Minute + 30*time.Second expected.val = nil - expected.GetStringValue("") + expected.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals) pdd.RemEvent(ev1.ID) - pdd.GetStringValue("") + pdd.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals) if !reflect.DeepEqual(*expected, *pdd) { t.Errorf("Expected: %s , received: %s", utils.ToJSON(expected), utils.ToJSON(pdd)) } @@ -1683,12 +1683,12 @@ func TestPDDGetFloat64Value(t *testing.T) { "Usage": 10 * time.Second, utils.PDD: 5 * time.Second}} pdd.AddEvent(ev.ID, utils.MapStorage{utils.MetaReq: ev.Event}) - if v := pdd.GetFloat64Value(); v != -1.0 { + if v := pdd.GetFloat64Value(config.CgrConfig().GeneralCfg().RoundingDecimals); v != -1.0 { t.Errorf("wrong pdd value: %v", v) } ev2 := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_2"} pdd.AddEvent(ev2.ID, utils.MapStorage{utils.MetaReq: ev2.Event}) - if v := pdd.GetFloat64Value(); v != -1.0 { + if v := pdd.GetFloat64Value(config.CgrConfig().GeneralCfg().RoundingDecimals); v != -1.0 { t.Errorf("wrong pdd value: %v", v) } ev4 := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_4", @@ -1705,27 +1705,27 @@ func TestPDDGetFloat64Value(t *testing.T) { }, } pdd.AddEvent(ev4.ID, utils.MapStorage{utils.MetaReq: ev4.Event}) - if strVal := pdd.GetFloat64Value(); strVal != 7.5 { + if strVal := pdd.GetFloat64Value(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != 7.5 { t.Errorf("wrong pdd value: %v", strVal) } pdd.AddEvent(ev5.ID, utils.MapStorage{utils.MetaReq: ev5.Event}) - if strVal := pdd.GetFloat64Value(); strVal != 7.5 { + if strVal := pdd.GetFloat64Value(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != 7.5 { t.Errorf("wrong pdd value: %v", strVal) } pdd.RemEvent(ev2.ID) - if strVal := pdd.GetFloat64Value(); strVal != 7.5 { + if strVal := pdd.GetFloat64Value(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != 7.5 { t.Errorf("wrong pdd value: %v", strVal) } pdd.RemEvent(ev4.ID) - if strVal := pdd.GetFloat64Value(); strVal != -1.0 { + if strVal := pdd.GetFloat64Value(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != -1.0 { t.Errorf("wrong pdd value: %v", strVal) } pdd.RemEvent(ev.ID) - if strVal := pdd.GetFloat64Value(); strVal != -1.0 { + if strVal := pdd.GetFloat64Value(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != -1.0 { t.Errorf("wrong pdd value: %v", strVal) } pdd.RemEvent(ev5.ID) - if strVal := pdd.GetFloat64Value(); strVal != -1.0 { + if strVal := pdd.GetFloat64Value(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != -1.0 { t.Errorf("wrong pdd value: %v", strVal) } } @@ -1738,7 +1738,7 @@ func TestPDDGetValue(t *testing.T) { "Usage": 10 * time.Second, utils.PDD: 9 * time.Second}} pdd.AddEvent(ev.ID, utils.MapStorage{utils.MetaReq: ev.Event}) - if v := pdd.GetValue(); v != -time.Nanosecond { + if v := pdd.GetValue(config.CgrConfig().GeneralCfg().RoundingDecimals); v != -time.Nanosecond { t.Errorf("wrong pdd value: %+v", v) } ev2 := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_2", @@ -1753,19 +1753,19 @@ func TestPDDGetValue(t *testing.T) { if err := pdd.AddEvent(ev3.ID, utils.MapStorage{utils.MetaReq: ev3.Event}); err == nil || err.Error() != "NOT_FOUND:PDD" { t.Error(err) } - if v := pdd.GetValue(); v != 9*time.Second+500*time.Millisecond { + if v := pdd.GetValue(config.CgrConfig().GeneralCfg().RoundingDecimals); v != 9*time.Second+500*time.Millisecond { t.Errorf("wrong pdd value: %+v", v) } if err := pdd.RemEvent(ev.ID); err != nil { t.Error(err) } - if v := pdd.GetValue(); v != -time.Nanosecond { + if v := pdd.GetValue(config.CgrConfig().GeneralCfg().RoundingDecimals); v != -time.Nanosecond { t.Errorf("wrong pdd value: %+v", v) } if err := pdd.RemEvent(ev2.ID); err != nil { t.Error(err) } - if v := pdd.GetValue(); v != -time.Nanosecond { + if v := pdd.GetValue(config.CgrConfig().GeneralCfg().RoundingDecimals); v != -time.Nanosecond { t.Errorf("wrong pdd value: %+v", v) } ev4 := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_4", @@ -1787,7 +1787,7 @@ func TestPDDGetValue(t *testing.T) { if err := pdd.AddEvent(ev5.ID, utils.MapStorage{utils.MetaReq: ev5.Event}); err == nil || err.Error() != "NOT_FOUND:PDD" { t.Error(err) } - if v := pdd.GetValue(); v != -time.Nanosecond { + if v := pdd.GetValue(config.CgrConfig().GeneralCfg().RoundingDecimals); v != -time.Nanosecond { t.Errorf("wrong pdd value: %+v", v) } if err := pdd.RemEvent(ev5.ID); err == nil || err.Error() != "NOT_FOUND" { @@ -1796,7 +1796,7 @@ func TestPDDGetValue(t *testing.T) { if err := pdd.RemEvent(ev4.ID); err != nil { t.Error(err) } - if v := pdd.GetValue(); v != -time.Nanosecond { + if v := pdd.GetValue(config.CgrConfig().GeneralCfg().RoundingDecimals); v != -time.Nanosecond { t.Errorf("wrong pdd value: %+v", v) } } @@ -1813,7 +1813,7 @@ func TestPDDCompress(t *testing.T) { Count: 3, Sum: 6 * time.Minute, } - expected.GetStringValue("") + expected.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals) ev1 := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_1", Event: map[string]interface{}{utils.PDD: 2 * time.Minute}} ev2 := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_1", @@ -1824,12 +1824,12 @@ func TestPDDCompress(t *testing.T) { pdd.AddEvent(ev2.ID, utils.MapStorage{utils.MetaReq: ev2.Event}) pdd.AddEvent(ev3.ID, utils.MapStorage{utils.MetaReq: ev3.Event}) expIDs := []string{"EVENT_1", "EVENT_3"} - rply := pdd.Compress(10, "EVENT_3") + rply := pdd.Compress(10, "EVENT_3", config.CgrConfig().GeneralCfg().RoundingDecimals) sort.Strings(rply) if !reflect.DeepEqual(expIDs, rply) { t.Errorf("Expected: %s , received: %s", utils.ToJSON(expIDs), utils.ToJSON(rply)) } - pdd.GetStringValue("") + pdd.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals) if !reflect.DeepEqual(*expected, *pdd) { t.Errorf("Expected: %s , received: %s", utils.ToJSON(expected), utils.ToJSON(pdd)) } @@ -1842,13 +1842,13 @@ func TestPDDCompress(t *testing.T) { Count: 3, Sum: 6 * time.Minute, } - expected.GetStringValue("") + expected.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals) expIDs = []string{"EVENT_3"} - if rply := pdd.Compress(1, "EVENT_3"); !reflect.DeepEqual(expIDs, rply) { + if rply := pdd.Compress(1, "EVENT_3", config.CgrConfig().GeneralCfg().RoundingDecimals); !reflect.DeepEqual(expIDs, rply) { t.Errorf("Expected: %s , received: %s", utils.ToJSON(expIDs), utils.ToJSON(rply)) } - pdd.GetStringValue("") + pdd.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals) if !reflect.DeepEqual(*expected, *pdd) { t.Errorf("Expected: %s , received: %s", utils.ToJSON(expected), utils.ToJSON(pdd)) } @@ -1893,12 +1893,12 @@ func TestDDCGetStringValue(t *testing.T) { Event: map[string]interface{}{ "AnswerTime": time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC), utils.Destination: "1002"}} - if strVal := ddc.GetStringValue(""); strVal != utils.NOT_AVAILABLE { + if strVal := ddc.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != utils.NOT_AVAILABLE { t.Errorf("wrong ddc value: %s", strVal) } ddc.AddEvent(ev.ID, utils.MapStorage{utils.MetaReq: ev.Event}) - if strVal := ddc.GetStringValue(""); strVal != utils.NOT_AVAILABLE { + if strVal := ddc.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != utils.NOT_AVAILABLE { t.Errorf("wrong ddc value: %s", strVal) } ev2 := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_2", @@ -1912,19 +1912,19 @@ func TestDDCGetStringValue(t *testing.T) { utils.Destination: "1001"}} ddc.AddEvent(ev2.ID, utils.MapStorage{utils.MetaReq: ev2.Event}) ddc.AddEvent(ev3.ID, utils.MapStorage{utils.MetaReq: ev3.Event}) - if strVal := ddc.GetStringValue(""); strVal != "2" { + if strVal := ddc.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != "2" { t.Errorf("wrong ddc value: %s", strVal) } ddc.RemEvent(ev.ID) - if strVal := ddc.GetStringValue(""); strVal != "2" { + if strVal := ddc.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != "2" { t.Errorf("wrong ddc value: %s", strVal) } ddc.RemEvent(ev2.ID) - if strVal := ddc.GetStringValue(""); strVal != utils.NOT_AVAILABLE { + if strVal := ddc.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != utils.NOT_AVAILABLE { t.Errorf("wrong ddc value: %s", strVal) } ddc.RemEvent(ev3.ID) - if strVal := ddc.GetStringValue(""); strVal != utils.NOT_AVAILABLE { + if strVal := ddc.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != utils.NOT_AVAILABLE { t.Errorf("wrong ddc value: %s", strVal) } } @@ -1938,12 +1938,12 @@ func TestDDCGetFloat64Value(t *testing.T) { utils.PDD: 5 * time.Second, utils.Destination: "1002"}} ddc.AddEvent(ev.ID, utils.MapStorage{utils.MetaReq: ev.Event}) - if v := ddc.GetFloat64Value(); v != -1.0 { + if v := ddc.GetFloat64Value(config.CgrConfig().GeneralCfg().RoundingDecimals); v != -1.0 { t.Errorf("wrong ddc value: %v", v) } ev2 := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_2"} ddc.AddEvent(ev2.ID, utils.MapStorage{utils.MetaReq: ev2.Event}) - if v := ddc.GetFloat64Value(); v != -1.0 { + if v := ddc.GetFloat64Value(config.CgrConfig().GeneralCfg().RoundingDecimals); v != -1.0 { t.Errorf("wrong ddc value: %v", v) } ev4 := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_4", @@ -1962,27 +1962,27 @@ func TestDDCGetFloat64Value(t *testing.T) { }, } ddc.AddEvent(ev4.ID, utils.MapStorage{utils.MetaReq: ev4.Event}) - if strVal := ddc.GetFloat64Value(); strVal != 2 { + if strVal := ddc.GetFloat64Value(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != 2 { t.Errorf("wrong ddc value: %v", strVal) } ddc.AddEvent(ev5.ID, utils.MapStorage{utils.MetaReq: ev5.Event}) - if strVal := ddc.GetFloat64Value(); strVal != 3 { + if strVal := ddc.GetFloat64Value(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != 3 { t.Errorf("wrong ddc value: %v", strVal) } ddc.RemEvent(ev2.ID) - if strVal := ddc.GetFloat64Value(); strVal != 3 { + if strVal := ddc.GetFloat64Value(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != 3 { t.Errorf("wrong pdd value: %v", strVal) } ddc.RemEvent(ev4.ID) - if strVal := ddc.GetFloat64Value(); strVal != 2 { + if strVal := ddc.GetFloat64Value(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != 2 { t.Errorf("wrong ddc value: %v", strVal) } ddc.RemEvent(ev.ID) - if strVal := ddc.GetFloat64Value(); strVal != -1.0 { + if strVal := ddc.GetFloat64Value(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != -1.0 { t.Errorf("wrong ddc value: %v", strVal) } ddc.RemEvent(ev5.ID) - if strVal := ddc.GetFloat64Value(); strVal != -1.0 { + if strVal := ddc.GetFloat64Value(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != -1.0 { t.Errorf("wrong ddc value: %v", strVal) } } @@ -1991,22 +1991,22 @@ func TestDDCGetStringValue2(t *testing.T) { statDistinct, _ := NewDDC(2, "", []string{}) ev := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_1", Event: map[string]interface{}{utils.Destination: "1001"}} - if strVal := statDistinct.GetStringValue(""); strVal != utils.NOT_AVAILABLE { + if strVal := statDistinct.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != utils.NOT_AVAILABLE { t.Errorf("wrong statDistinct value: %s", strVal) } statDistinct.AddEvent(ev.ID, utils.MapStorage{utils.MetaReq: ev.Event}) - if strVal := statDistinct.GetStringValue(""); strVal != utils.NOT_AVAILABLE { + if strVal := statDistinct.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != utils.NOT_AVAILABLE { t.Errorf("wrong statDistinct value: %s", strVal) } ev2 := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_1", Event: map[string]interface{}{utils.Destination: "1002"}} statDistinct.AddEvent(ev2.ID, utils.MapStorage{utils.MetaReq: ev2.Event}) - if strVal := statDistinct.GetStringValue(""); strVal != "2" { + if strVal := statDistinct.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != "2" { t.Errorf("wrong statDistinct value: %s", strVal) } statDistinct.RemEvent(ev.ID) - if strVal := statDistinct.GetStringValue(""); strVal != utils.NOT_AVAILABLE { + if strVal := statDistinct.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != utils.NOT_AVAILABLE { t.Errorf("wrong statDistinct value: %s", strVal) } } @@ -2039,7 +2039,7 @@ func TestDDCCompress(t *testing.T) { FilterIDs: []string{}, Count: 3, } - expected.GetStringValue("") + expected.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals) ev1 := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_1", Event: map[string]interface{}{utils.Destination: "1001"}} ev2 := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_1", @@ -2050,21 +2050,21 @@ func TestDDCCompress(t *testing.T) { ddc.AddEvent(ev2.ID, utils.MapStorage{utils.MetaReq: ev2.Event}) ddc.AddEvent(ev3.ID, utils.MapStorage{utils.MetaReq: ev3.Event}) expIDs := []string{"EVENT_1", "EVENT_3"} - rply := ddc.Compress(10, "EVENT_3") + rply := ddc.Compress(10, "EVENT_3", config.CgrConfig().GeneralCfg().RoundingDecimals) sort.Strings(rply) if !reflect.DeepEqual(expIDs, rply) { t.Errorf("Expected: %s , received: %s", utils.ToJSON(expIDs), utils.ToJSON(rply)) } - ddc.GetStringValue("") + ddc.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals) if !reflect.DeepEqual(*expected, *ddc) { t.Errorf("Expected: %s , received: %s", utils.ToJSON(expected), utils.ToJSON(ddc)) } - rply = ddc.Compress(10, "EVENT_3") + rply = ddc.Compress(10, "EVENT_3", config.CgrConfig().GeneralCfg().RoundingDecimals) sort.Strings(rply) if !reflect.DeepEqual(expIDs, rply) { t.Errorf("Expected: %s , received: %s", utils.ToJSON(expIDs), utils.ToJSON(rply)) } - ddc.GetStringValue("") + ddc.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals) if !reflect.DeepEqual(*expected, *ddc) { t.Errorf("Expected: %s , received: %s", utils.ToJSON(expected), utils.ToJSON(ddc)) } @@ -2113,14 +2113,14 @@ func TestStatSumGetFloat64Value(t *testing.T) { utils.PDD: 5 * time.Second, utils.Destination: "1002"}} statSum.AddEvent(ev.ID, utils.MapStorage{utils.MetaReq: ev.Event}) - if v := statSum.GetFloat64Value(); v != -1.0 { + if v := statSum.GetFloat64Value(config.CgrConfig().GeneralCfg().RoundingDecimals); v != -1.0 { t.Errorf("wrong statSum value: %v", v) } ev2 := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_2"} if err := statSum.AddEvent(ev2.ID, utils.MapStorage{utils.MetaReq: ev2.Event}); err == nil || err.Error() != "NOT_FOUND:~*req.Cost" { t.Error(err) } - if v := statSum.GetFloat64Value(); v != -1.0 { + if v := statSum.GetFloat64Value(config.CgrConfig().GeneralCfg().RoundingDecimals); v != -1.0 { t.Errorf("wrong statSum value: %v", v) } ev4 := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_4", @@ -2141,27 +2141,27 @@ func TestStatSumGetFloat64Value(t *testing.T) { }, } statSum.AddEvent(ev4.ID, utils.MapStorage{utils.MetaReq: ev4.Event}) - if strVal := statSum.GetFloat64Value(); strVal != 40 { + if strVal := statSum.GetFloat64Value(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != 40 { t.Errorf("wrong statSum value: %v", strVal) } statSum.AddEvent(ev5.ID, utils.MapStorage{utils.MetaReq: ev5.Event}) - if strVal := statSum.GetFloat64Value(); strVal != 60 { + if strVal := statSum.GetFloat64Value(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != 60 { t.Errorf("wrong statSum value: %v", strVal) } statSum.RemEvent(ev2.ID) - if strVal := statSum.GetFloat64Value(); strVal != 60 { + if strVal := statSum.GetFloat64Value(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != 60 { t.Errorf("wrong statSum value: %v", strVal) } statSum.RemEvent(ev4.ID) - if strVal := statSum.GetFloat64Value(); strVal != 40 { + if strVal := statSum.GetFloat64Value(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != 40 { t.Errorf("wrong statSum value: %v", strVal) } statSum.RemEvent(ev.ID) - if strVal := statSum.GetFloat64Value(); strVal != -1.0 { + if strVal := statSum.GetFloat64Value(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != -1.0 { t.Errorf("wrong statSum value: %v", strVal) } statSum.RemEvent(ev5.ID) - if strVal := statSum.GetFloat64Value(); strVal != -1.0 { + if strVal := statSum.GetFloat64Value(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != -1.0 { t.Errorf("wrong statSum value: %v", strVal) } } @@ -2173,12 +2173,12 @@ func TestStatSumGetStringValue(t *testing.T) { "Cost": "20", "AnswerTime": time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC), utils.Destination: "1002"}} - if strVal := statSum.GetStringValue(""); strVal != utils.NOT_AVAILABLE { + if strVal := statSum.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != utils.NOT_AVAILABLE { t.Errorf("wrong ddc value: %s", strVal) } statSum.AddEvent(ev.ID, utils.MapStorage{utils.MetaReq: ev.Event}) - if strVal := statSum.GetStringValue(""); strVal != utils.NOT_AVAILABLE { + if strVal := statSum.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != utils.NOT_AVAILABLE { t.Errorf("wrong statSum value: %s", strVal) } ev2 := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_2", @@ -2194,19 +2194,19 @@ func TestStatSumGetStringValue(t *testing.T) { utils.Destination: "1001"}} statSum.AddEvent(ev2.ID, utils.MapStorage{utils.MetaReq: ev2.Event}) statSum.AddEvent(ev3.ID, utils.MapStorage{utils.MetaReq: ev3.Event}) - if strVal := statSum.GetStringValue(""); strVal != "60" { + if strVal := statSum.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != "60" { t.Errorf("wrong statSum value: %s", strVal) } statSum.RemEvent(ev.ID) - if strVal := statSum.GetStringValue(""); strVal != "40" { + if strVal := statSum.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != "40" { t.Errorf("wrong statSum value: %s", strVal) } statSum.RemEvent(ev2.ID) - if strVal := statSum.GetStringValue(""); strVal != utils.NOT_AVAILABLE { + if strVal := statSum.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != utils.NOT_AVAILABLE { t.Errorf("wrong statSum value: %s", strVal) } statSum.RemEvent(ev3.ID) - if strVal := statSum.GetStringValue(""); strVal != utils.NOT_AVAILABLE { + if strVal := statSum.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != utils.NOT_AVAILABLE { t.Errorf("wrong statSum value: %s", strVal) } } @@ -2221,16 +2221,16 @@ func TestStatSumGetStringValue2(t *testing.T) { ev2 := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_2", Event: map[string]interface{}{"Cost": 18.3}} statSum.AddEvent(ev2.ID, utils.MapStorage{utils.MetaReq: ev2.Event}) - if strVal := statSum.GetStringValue(""); strVal != "30.6" { + if strVal := statSum.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != "30.6" { t.Errorf("wrong statSum value: %s", strVal) } statSum.AddEvent(ev2.ID, utils.MapStorage{utils.MetaReq: ev2.Event}) statSum.AddEvent(ev2.ID, utils.MapStorage{utils.MetaReq: ev2.Event}) - if strVal := statSum.GetStringValue(""); strVal != "67.2" { + if strVal := statSum.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != "67.2" { t.Errorf("wrong statSum value: %s", strVal) } statSum.RemEvent(ev2.ID) - if strVal := statSum.GetStringValue(""); strVal != "48.9" { + if strVal := statSum.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != "48.9" { t.Errorf("wrong statSum value: %s", strVal) } } @@ -2248,7 +2248,7 @@ func TestStatSumGetStringValue3(t *testing.T) { Count: 3, Sum: 42.7, } - expected.GetStringValue("") + expected.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals) ev1 := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_1", Event: map[string]interface{}{"Cost": 18.2}} ev2 := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_1", @@ -2264,7 +2264,7 @@ func TestStatSumGetStringValue3(t *testing.T) { if err := statSum.AddEvent(ev3.ID, utils.MapStorage{utils.MetaReq: ev3.Event}); err != nil { t.Error(err) } - statSum.GetStringValue("") + statSum.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals) if !reflect.DeepEqual(*expected, *statSum) { t.Errorf("Expected: %s , received: %s", utils.ToJSON(expected), utils.ToJSON(statSum)) } @@ -2273,9 +2273,9 @@ func TestStatSumGetStringValue3(t *testing.T) { expected.Count = 2 expected.Sum = expected.Sum - 12.2 expected.val = nil - expected.GetStringValue("") + expected.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals) statSum.RemEvent(ev1.ID) - statSum.GetStringValue("") + statSum.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals) if !reflect.DeepEqual(*expected, *statSum) { t.Errorf("Expected: %s , received: %s", utils.ToJSON(expected), utils.ToJSON(statSum)) } @@ -2295,7 +2295,7 @@ func TestStatSumCompress(t *testing.T) { FieldName: "~*req.Cost", Count: 2, } - expected.GetStringValue("") + expected.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals) ev := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_1", Event: map[string]interface{}{"Cost": 18.2}} ev2 := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_2", @@ -2305,12 +2305,12 @@ func TestStatSumCompress(t *testing.T) { sum.AddEvent(ev.ID, utils.MapStorage{utils.MetaReq: ev.Event}) sum.AddEvent(ev2.ID, utils.MapStorage{utils.MetaReq: ev2.Event}) expIDs := []string{"EVENT_1", "EVENT_2"} - rply := sum.Compress(10, "EVENT_3") + rply := sum.Compress(10, "EVENT_3", config.CgrConfig().GeneralCfg().RoundingDecimals) sort.Strings(rply) if !reflect.DeepEqual(expIDs, rply) { t.Errorf("Expected: %s , received: %s", utils.ToJSON(expIDs), utils.ToJSON(rply)) } - sum.GetStringValue("") + sum.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals) if !reflect.DeepEqual(*expected, *sum) { t.Errorf("Expected: %s , received: %s", utils.ToJSON(expected), utils.ToJSON(sum)) } @@ -2324,12 +2324,12 @@ func TestStatSumCompress(t *testing.T) { Sum: 24.4, Count: 2, } - expected.GetStringValue("") + expected.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals) expIDs = []string{"EVENT_3"} - if rply := sum.Compress(1, "EVENT_3"); !reflect.DeepEqual(expIDs, rply) { + if rply := sum.Compress(1, "EVENT_3", config.CgrConfig().GeneralCfg().RoundingDecimals); !reflect.DeepEqual(expIDs, rply) { t.Errorf("Expected: %s , received: %s", utils.ToJSON(expIDs), utils.ToJSON(rply)) } - sum.GetStringValue("") + sum.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals) if !reflect.DeepEqual(*expected, *sum) { t.Errorf("Expected: %s , received: %s", utils.ToJSON(expected), utils.ToJSON(sum)) } @@ -2341,11 +2341,11 @@ func TestStatSumCompress(t *testing.T) { expected.Count = 4 expected.Sum = 48.9 expected.val = nil - expected.GetStringValue("") - if rply := sum.Compress(1, "EVENT_3"); !reflect.DeepEqual(expIDs, rply) { + expected.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals) + if rply := sum.Compress(1, "EVENT_3", config.CgrConfig().GeneralCfg().RoundingDecimals); !reflect.DeepEqual(expIDs, rply) { t.Errorf("Expected: %s , received: %s", utils.ToJSON(expIDs), utils.ToJSON(rply)) } - sum.GetStringValue("") + sum.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals) if !reflect.DeepEqual(*expected, *sum) { t.Errorf("Expected: %s , received: %s", utils.ToJSON(expected), utils.ToJSON(sum)) } @@ -2393,12 +2393,12 @@ func TestStatAverageGetFloat64Value(t *testing.T) { utils.PDD: 5 * time.Second, utils.Destination: "1002"}} statAvg.AddEvent(ev.ID, utils.MapStorage{utils.MetaReq: ev.Event}) - if v := statAvg.GetFloat64Value(); v != -1.0 { + if v := statAvg.GetFloat64Value(config.CgrConfig().GeneralCfg().RoundingDecimals); v != -1.0 { t.Errorf("wrong statAvg value: %v", v) } ev2 := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_2"} statAvg.AddEvent(ev2.ID, utils.MapStorage{utils.MetaReq: ev2.Event}) - if v := statAvg.GetFloat64Value(); v != -1.0 { + if v := statAvg.GetFloat64Value(config.CgrConfig().GeneralCfg().RoundingDecimals); v != -1.0 { t.Errorf("wrong statAvg value: %v", v) } ev4 := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_4", @@ -2419,27 +2419,27 @@ func TestStatAverageGetFloat64Value(t *testing.T) { }, } statAvg.AddEvent(ev4.ID, utils.MapStorage{utils.MetaReq: ev4.Event}) - if strVal := statAvg.GetFloat64Value(); strVal != 25 { + if strVal := statAvg.GetFloat64Value(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != 25 { t.Errorf("wrong statAvg value: %v", strVal) } statAvg.AddEvent(ev5.ID, utils.MapStorage{utils.MetaReq: ev5.Event}) - if strVal := statAvg.GetFloat64Value(); strVal != 23.33333 { + if strVal := statAvg.GetFloat64Value(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != 23.33333 { t.Errorf("wrong statAvg value: %v", strVal) } statAvg.RemEvent(ev2.ID) - if strVal := statAvg.GetFloat64Value(); strVal != 23.33333 { + if strVal := statAvg.GetFloat64Value(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != 23.33333 { t.Errorf("wrong statAvg value: %v", strVal) } statAvg.RemEvent(ev4.ID) - if strVal := statAvg.GetFloat64Value(); strVal != 20 { + if strVal := statAvg.GetFloat64Value(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != 20 { t.Errorf("wrong statAvg value: %v", strVal) } statAvg.RemEvent(ev.ID) - if strVal := statAvg.GetFloat64Value(); strVal != -1.0 { + if strVal := statAvg.GetFloat64Value(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != -1.0 { t.Errorf("wrong statAvg value: %v", strVal) } statAvg.RemEvent(ev5.ID) - if strVal := statAvg.GetFloat64Value(); strVal != -1.0 { + if strVal := statAvg.GetFloat64Value(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != -1.0 { t.Errorf("wrong statAvg value: %v", strVal) } } @@ -2451,12 +2451,12 @@ func TestStatAverageGetStringValue(t *testing.T) { "Cost": "20", "AnswerTime": time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC), utils.Destination: "1002"}} - if strVal := statAvg.GetStringValue(""); strVal != utils.NOT_AVAILABLE { + if strVal := statAvg.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != utils.NOT_AVAILABLE { t.Errorf("wrong ddc value: %s", strVal) } statAvg.AddEvent(ev.ID, utils.MapStorage{utils.MetaReq: ev.Event}) - if strVal := statAvg.GetStringValue(""); strVal != utils.NOT_AVAILABLE { + if strVal := statAvg.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != utils.NOT_AVAILABLE { t.Errorf("wrong statAvg value: %s", strVal) } ev2 := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_2", @@ -2472,19 +2472,19 @@ func TestStatAverageGetStringValue(t *testing.T) { utils.Destination: "1001"}} statAvg.AddEvent(ev2.ID, utils.MapStorage{utils.MetaReq: ev2.Event}) statAvg.AddEvent(ev3.ID, utils.MapStorage{utils.MetaReq: ev3.Event}) - if strVal := statAvg.GetStringValue(""); strVal != "20" { + if strVal := statAvg.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != "20" { t.Errorf("wrong statAvg value: %s", strVal) } statAvg.RemEvent(ev.ID) - if strVal := statAvg.GetStringValue(""); strVal != "20" { + if strVal := statAvg.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != "20" { t.Errorf("wrong statAvg value: %s", strVal) } statAvg.RemEvent(ev2.ID) - if strVal := statAvg.GetStringValue(""); strVal != utils.NOT_AVAILABLE { + if strVal := statAvg.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != utils.NOT_AVAILABLE { t.Errorf("wrong statAvg value: %s", strVal) } statAvg.RemEvent(ev3.ID) - if strVal := statAvg.GetStringValue(""); strVal != utils.NOT_AVAILABLE { + if strVal := statAvg.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != utils.NOT_AVAILABLE { t.Errorf("wrong statAvg value: %s", strVal) } } @@ -2499,16 +2499,16 @@ func TestStatAverageGetStringValue2(t *testing.T) { ev2 := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_2", Event: map[string]interface{}{"Cost": 18.3}} statAvg.AddEvent(ev2.ID, utils.MapStorage{utils.MetaReq: ev2.Event}) - if strVal := statAvg.GetStringValue(""); strVal != "15.3" { + if strVal := statAvg.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != "15.3" { t.Errorf("wrong statAvg value: %s", strVal) } statAvg.AddEvent(ev2.ID, utils.MapStorage{utils.MetaReq: ev2.Event}) statAvg.AddEvent(ev2.ID, utils.MapStorage{utils.MetaReq: ev2.Event}) - if strVal := statAvg.GetStringValue(""); strVal != "16.8" { + if strVal := statAvg.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != "16.8" { t.Errorf("wrong statAvg value: %s", strVal) } statAvg.RemEvent(ev2.ID) - if strVal := statAvg.GetStringValue(""); strVal != "16.3" { + if strVal := statAvg.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != "16.3" { t.Errorf("wrong statAvg value: %s", strVal) } } @@ -2527,7 +2527,7 @@ func TestStatAverageGetStringValue3(t *testing.T) { Count: 3, Sum: 42.7, } - expected.GetStringValue("") + expected.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals) ev1 := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_1", Event: map[string]interface{}{"Cost": 18.2}} ev2 := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_1", @@ -2543,7 +2543,7 @@ func TestStatAverageGetStringValue3(t *testing.T) { if err := statAvg.AddEvent(ev3.ID, utils.MapStorage{utils.MetaReq: ev3.Event}); err != nil { t.Error(err) } - statAvg.GetStringValue("") + statAvg.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals) if !reflect.DeepEqual(*expected, *statAvg) { t.Errorf("Expected: %s , received: %s", utils.ToJSON(expected), utils.ToJSON(statAvg)) } @@ -2552,9 +2552,9 @@ func TestStatAverageGetStringValue3(t *testing.T) { expected.Count = 2 expected.Sum = expected.Sum - 12.2 expected.val = nil - expected.GetStringValue("") + expected.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals) statAvg.RemEvent(ev1.ID) - statAvg.GetStringValue("") + statAvg.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals) if !reflect.DeepEqual(*expected, *statAvg) { t.Errorf("Expected: %s , received: %s", utils.ToJSON(expected), utils.ToJSON(statAvg)) } @@ -2574,7 +2574,7 @@ func TestStatAverageCompress(t *testing.T) { FieldName: "~*req.Cost", Count: 2, } - expected.GetStringValue("") + expected.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals) ev := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_1", Event: map[string]interface{}{"Cost": 18.2}} ev2 := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_2", @@ -2584,12 +2584,12 @@ func TestStatAverageCompress(t *testing.T) { avg.AddEvent(ev.ID, utils.MapStorage{utils.MetaReq: ev.Event}) avg.AddEvent(ev2.ID, utils.MapStorage{utils.MetaReq: ev2.Event}) expIDs := []string{"EVENT_1", "EVENT_2"} - rply := avg.Compress(10, "EVENT_3") + rply := avg.Compress(10, "EVENT_3", config.CgrConfig().GeneralCfg().RoundingDecimals) sort.Strings(rply) if !reflect.DeepEqual(expIDs, rply) { t.Errorf("Expected: %s , received: %s", utils.ToJSON(expIDs), utils.ToJSON(rply)) } - avg.GetStringValue("") + avg.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals) if !reflect.DeepEqual(*expected, *avg) { t.Errorf("Expected: %s , received: %s", utils.ToJSON(expected), utils.ToJSON(avg)) } @@ -2603,12 +2603,12 @@ func TestStatAverageCompress(t *testing.T) { Sum: 24.4, Count: 2, } - expected.GetStringValue("") + expected.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals) expIDs = []string{"EVENT_3"} - if rply := avg.Compress(1, "EVENT_3"); !reflect.DeepEqual(expIDs, rply) { + if rply := avg.Compress(1, "EVENT_3", config.CgrConfig().GeneralCfg().RoundingDecimals); !reflect.DeepEqual(expIDs, rply) { t.Errorf("Expected: %s , received: %s", utils.ToJSON(expIDs), utils.ToJSON(rply)) } - avg.GetStringValue("") + avg.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals) if !reflect.DeepEqual(*expected, *avg) { t.Errorf("Expected: %s , received: %s", utils.ToJSON(expected), utils.ToJSON(avg)) } @@ -2620,11 +2620,11 @@ func TestStatAverageCompress(t *testing.T) { expected.Count = 4 expected.Sum = 48.9 expected.val = nil - expected.GetStringValue("") - if rply := avg.Compress(1, "EVENT_3"); !reflect.DeepEqual(expIDs, rply) { + expected.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals) + if rply := avg.Compress(1, "EVENT_3", config.CgrConfig().GeneralCfg().RoundingDecimals); !reflect.DeepEqual(expIDs, rply) { t.Errorf("Expected: %s , received: %s", utils.ToJSON(expIDs), utils.ToJSON(rply)) } - avg.GetStringValue("") + avg.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals) if !reflect.DeepEqual(*expected, *avg) { t.Errorf("Expected: %s , received: %s", utils.ToJSON(expected), utils.ToJSON(avg)) } @@ -2667,12 +2667,12 @@ func TestStatDistinctGetFloat64Value(t *testing.T) { ev := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_1", Event: map[string]interface{}{"Usage": 10 * time.Second}} statDistinct.AddEvent(ev.ID, utils.MapStorage{utils.MetaReq: ev.Event}) - if v := statDistinct.GetFloat64Value(); v != -1.0 { + if v := statDistinct.GetFloat64Value(config.CgrConfig().GeneralCfg().RoundingDecimals); v != -1.0 { t.Errorf("wrong statDistinct value: %v", v) } ev2 := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_2"} statDistinct.AddEvent(ev2.ID, utils.MapStorage{utils.MetaReq: ev2.Event}) - if v := statDistinct.GetFloat64Value(); v != -1.0 { + if v := statDistinct.GetFloat64Value(config.CgrConfig().GeneralCfg().RoundingDecimals); v != -1.0 { t.Errorf("wrong statDistinct value: %v", v) } ev4 := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_4", @@ -2688,27 +2688,27 @@ func TestStatDistinctGetFloat64Value(t *testing.T) { if err := statDistinct.AddEvent(ev4.ID, utils.MapStorage{utils.MetaReq: ev4.Event}); err != nil { t.Error(err) } - if strVal := statDistinct.GetFloat64Value(); strVal != 2 { + if strVal := statDistinct.GetFloat64Value(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != 2 { t.Errorf("wrong statDistinct value: %v", strVal) } statDistinct.AddEvent(ev5.ID, utils.MapStorage{utils.MetaReq: ev5.Event}) - if strVal := statDistinct.GetFloat64Value(); strVal != 3 { + if strVal := statDistinct.GetFloat64Value(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != 3 { t.Errorf("wrong statDistinct value: %v", strVal) } statDistinct.RemEvent(ev2.ID) - if strVal := statDistinct.GetFloat64Value(); strVal != 3 { + if strVal := statDistinct.GetFloat64Value(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != 3 { t.Errorf("wrong statDistinct value: %v", strVal) } statDistinct.RemEvent(ev4.ID) - if strVal := statDistinct.GetFloat64Value(); strVal != 2 { + if strVal := statDistinct.GetFloat64Value(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != 2 { t.Errorf("wrong statDistinct value: %v", strVal) } statDistinct.RemEvent(ev.ID) - if strVal := statDistinct.GetFloat64Value(); strVal != -1 { + if strVal := statDistinct.GetFloat64Value(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != -1 { t.Errorf("wrong statDistinct value: %v", strVal) } statDistinct.RemEvent(ev5.ID) - if strVal := statDistinct.GetFloat64Value(); strVal != -1 { + if strVal := statDistinct.GetFloat64Value(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != -1 { t.Errorf("wrong statDistinct value: %v", strVal) } } @@ -2717,12 +2717,12 @@ func TestStatDistinctGetStringValue(t *testing.T) { statDistinct, _ := NewStatDistinct(2, "~*req.Cost", []string{}) ev := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_1", Event: map[string]interface{}{"Cost": "20"}} - if strVal := statDistinct.GetStringValue(""); strVal != utils.NOT_AVAILABLE { + if strVal := statDistinct.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != utils.NOT_AVAILABLE { t.Errorf("wrong statDistinct value: %s", strVal) } statDistinct.AddEvent(ev.ID, utils.MapStorage{utils.MetaReq: ev.Event}) - if strVal := statDistinct.GetStringValue(""); strVal != utils.NOT_AVAILABLE { + if strVal := statDistinct.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != utils.NOT_AVAILABLE { t.Errorf("wrong statDistinct value: %s", strVal) } ev2 := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_2", @@ -2731,19 +2731,19 @@ func TestStatDistinctGetStringValue(t *testing.T) { Event: map[string]interface{}{"Cost": "40"}} statDistinct.AddEvent(ev2.ID, utils.MapStorage{utils.MetaReq: ev2.Event}) statDistinct.AddEvent(ev3.ID, utils.MapStorage{utils.MetaReq: ev3.Event}) - if strVal := statDistinct.GetStringValue(""); strVal != "2" { + if strVal := statDistinct.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != "2" { t.Errorf("wrong statDistinct value: %s", strVal) } statDistinct.RemEvent(ev.ID) - if strVal := statDistinct.GetStringValue(""); strVal != "2" { + if strVal := statDistinct.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != "2" { t.Errorf("wrong statDistinct value: %s", strVal) } statDistinct.RemEvent(ev2.ID) - if strVal := statDistinct.GetStringValue(""); strVal != utils.NOT_AVAILABLE { + if strVal := statDistinct.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != utils.NOT_AVAILABLE { t.Errorf("wrong statDistinct value: %s", strVal) } statDistinct.RemEvent(ev3.ID) - if strVal := statDistinct.GetStringValue(""); strVal != utils.NOT_AVAILABLE { + if strVal := statDistinct.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != utils.NOT_AVAILABLE { t.Errorf("wrong statDistinct value: %s", strVal) } } @@ -2752,22 +2752,22 @@ func TestStatDistinctGetStringValue2(t *testing.T) { statDistinct, _ := NewStatDistinct(2, "~*req.Cost", []string{}) ev := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_1", Event: map[string]interface{}{"Cost": "20"}} - if strVal := statDistinct.GetStringValue(""); strVal != utils.NOT_AVAILABLE { + if strVal := statDistinct.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != utils.NOT_AVAILABLE { t.Errorf("wrong statDistinct value: %s", strVal) } statDistinct.AddEvent(ev.ID, utils.MapStorage{utils.MetaReq: ev.Event}) - if strVal := statDistinct.GetStringValue(""); strVal != utils.NOT_AVAILABLE { + if strVal := statDistinct.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != utils.NOT_AVAILABLE { t.Errorf("wrong statDistinct value: %s", strVal) } ev2 := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_1", Event: map[string]interface{}{"Cost": "40"}} statDistinct.AddEvent(ev2.ID, utils.MapStorage{utils.MetaReq: ev2.Event}) - if strVal := statDistinct.GetStringValue(""); strVal != "2" { + if strVal := statDistinct.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != "2" { t.Errorf("wrong statDistinct value: %s", strVal) } statDistinct.RemEvent(ev.ID) - if strVal := statDistinct.GetStringValue(""); strVal != utils.NOT_AVAILABLE { + if strVal := statDistinct.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals); strVal != utils.NOT_AVAILABLE { t.Errorf("wrong statDistinct value: %s", strVal) } } @@ -2802,7 +2802,7 @@ func TestStatDistinctCompress(t *testing.T) { FieldName: utils.DynamicDataPrefix + utils.MetaReq + utils.NestingSep + utils.Destination, Count: 3, } - expected.GetStringValue("") + expected.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals) ev1 := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_1", Event: map[string]interface{}{utils.Destination: "1001"}} ev2 := &utils.CGREvent{Tenant: "cgrates.org", ID: "EVENT_1", @@ -2813,21 +2813,21 @@ func TestStatDistinctCompress(t *testing.T) { ddc.AddEvent(ev2.ID, utils.MapStorage{utils.MetaReq: ev2.Event}) ddc.AddEvent(ev3.ID, utils.MapStorage{utils.MetaReq: ev3.Event}) expIDs := []string{"EVENT_1", "EVENT_3"} - rply := ddc.Compress(10, "EVENT_3") + rply := ddc.Compress(10, "EVENT_3", config.CgrConfig().GeneralCfg().RoundingDecimals) sort.Strings(rply) if !reflect.DeepEqual(expIDs, rply) { t.Errorf("Expected: %s , received: %s", utils.ToJSON(expIDs), utils.ToJSON(rply)) } - ddc.GetStringValue("") + ddc.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals) if !reflect.DeepEqual(*expected, *ddc) { t.Errorf("Expected: %s , received: %s", utils.ToJSON(expected), utils.ToJSON(ddc)) } - rply = ddc.Compress(10, "EVENT_3") + rply = ddc.Compress(10, "EVENT_3", config.CgrConfig().GeneralCfg().RoundingDecimals) sort.Strings(rply) if !reflect.DeepEqual(expIDs, rply) { t.Errorf("Expected: %s , received: %s", utils.ToJSON(expIDs), utils.ToJSON(rply)) } - ddc.GetStringValue("") + ddc.GetStringValue(config.CgrConfig().GeneralCfg().RoundingDecimals) if !reflect.DeepEqual(*expected, *ddc) { t.Errorf("Expected: %s , received: %s", utils.ToJSON(expected), utils.ToJSON(ddc)) } diff --git a/engine/stats.go b/engine/stats.go index bf345ec20..798ff5386 100644 --- a/engine/stats.go +++ b/engine/stats.go @@ -341,7 +341,7 @@ func (sS *StatService) processEvent(tnt string, args *StatsArgsProcessEvent) (st }, } for metricID, metric := range sq.SQMetrics { - thEv.Event[metricID] = metric.GetValue() + thEv.Event[metricID] = metric.GetValue(sS.cgrcfg.GeneralCfg().RoundingDecimals) } var tIDs []string if err := sS.connMgr.Call(sS.cgrcfg.StatSCfg().ThresholdSConns, nil, @@ -457,7 +457,7 @@ func (sS *StatService) V1GetQueueStringMetrics(args *utils.TenantID, reply *map[ sq.RLock() metrics := make(map[string]string, len(sq.SQMetrics)) for metricID, metric := range sq.SQMetrics { - metrics[metricID] = metric.GetStringValue("") + metrics[metricID] = metric.GetStringValue(sS.cgrcfg.GeneralCfg().RoundingDecimals) } sq.RUnlock() *reply = metrics @@ -486,7 +486,7 @@ func (sS *StatService) V1GetQueueFloatMetrics(args *utils.TenantID, reply *map[s sq.RLock() metrics := make(map[string]float64, len(sq.SQMetrics)) for metricID, metric := range sq.SQMetrics { - metrics[metricID] = metric.GetFloat64Value() + metrics[metricID] = metric.GetFloat64Value(sS.cgrcfg.GeneralCfg().RoundingDecimals) } sq.RUnlock() *reply = metrics diff --git a/utils/concureqs.go b/utils/concureqs.go index 66eb06388..64b8e8524 100644 --- a/utils/concureqs.go +++ b/utils/concureqs.go @@ -22,20 +22,26 @@ import ( "net" "net/rpc" "net/rpc/jsonrpc" + "time" ) // ConcReqs the structure that allocs requests for API type ConcReqs struct { strategy string aReqs chan struct{} + // st *concReqStats } // NewConReqs creates a new ConcReqs -func NewConReqs(reqs int, strategy string) *ConcReqs { +func NewConReqs(reqs int, strategy string, ttl, sampleinterval time.Duration, exitChan chan bool) *ConcReqs { cR := &ConcReqs{ strategy: strategy, aReqs: make(chan struct{}, reqs), } + /* + if ttl != 0 { + cR.st = newConcReqStatS(ttl, sampleinterval, exitChan, cR.aReqs) + }*/ return cR } @@ -119,3 +125,60 @@ func (c *concReqsServerCodec) WriteResponse(r *rpc.Response, x interface{}) erro return c.sc.WriteResponse(r, x) } func (c *concReqsServerCodec) Close() error { return c.sc.Close() } + +/* +func newConcReqStatS(ttl, sampleinterval time.Duration, exitChan chan bool, concReq chan struct{}) (cs *concReqStats) { + cs = &concReqStats{ + st: NewStatAverage(2), + } + cs.cache = ltcache.NewCache(-1, ttl, true, cs.onEvict) + go cs.loop(sampleinterval, exitChan, concReq) + return +} + +type concReqStats struct { + sync.RWMutex + cache *ltcache.Cache + st *StatAverage + peak int +} + +func (cs *concReqStats) onEvict(itmID string, value interface{}) { + cs.st.RemEvent(itmID) +} + +func (cs *concReqStats) loop(intr time.Duration, exitChan chan bool, concReq chan struct{}) { + for { + select { + case v := <-exitChan: + exitChan <- v + return + case <-time.After(intr): + evID := time.Now().String() + val := len(concReq) + + cs.Lock() + cs.cache.Set(evID, val, nil) + cs.st.AddStat(evID, float64(val)) + if val > cs.peak { + cs.peak = val + } + cs.Unlock() + } + } +} + +func (cs *concReqStats) GetPeak() (peak int) { + cs.RLock() + peak = cs.peak + cs.RUnlock() + return +} + +func (cs *concReqStats) GetAverage(roundingDecimals int) (avg float64) { + cs.RLock() + avg = cs.st.GetFloat64Value(roundingDecimals) + cs.RUnlock() + return +} +*/ diff --git a/utils/consts.go b/utils/consts.go index 95fa50cbd..3a583d966 100755 --- a/utils/consts.go +++ b/utils/consts.go @@ -873,6 +873,7 @@ const ( ProcessRuns = "ProcessRuns" HashtagSep = "#" MetaRounding = "*rounding" + StatsNA = -1.0 ) // Migrator Action