diff --git a/cmd/cgr-engine/cgr-engine.go b/cmd/cgr-engine/cgr-engine.go index fac45524f..77e26e915 100644 --- a/cmd/cgr-engine/cgr-engine.go +++ b/cmd/cgr-engine/cgr-engine.go @@ -355,7 +355,7 @@ func main() { loadDb = logDb.(engine.LoadStorage) cdrDb = logDb.(engine.CdrStorage) - engine.SetRoundingMethodAndDecimals(cfg.RoundingMethod, cfg.RoundingDecimals) + engine.SetRoundingDecimals(cfg.RoundingDecimals) if cfg.SMDebitInterval > 0 { if dp, err := time.ParseDuration(fmt.Sprintf("%vs", cfg.SMDebitInterval)); err == nil { engine.SetDebitPeriod(dp) diff --git a/config/config.go b/config/config.go index 213a95753..7e1205b36 100644 --- a/config/config.go +++ b/config/config.go @@ -81,7 +81,6 @@ type CGRConfig struct { DefaultCategory string // set default type of record DefaultTenant string // set default tenant DefaultSubject string // set default rating subject, useful in case of fallback - RoundingMethod string // Rounding method for the end price: <*up|*middle|*down> RoundingDecimals int // Number of decimals to round end prices at XmlCfgDocument *CgrXmlCfgDocument // Load additional configuration inside xml document RaterEnabled bool // start standalone server (no balancer) @@ -159,7 +158,6 @@ func (self *CGRConfig) setDefaults() error { self.DefaultCategory = "call" self.DefaultTenant = "cgrates.org" self.DefaultSubject = "cgrates" - self.RoundingMethod = utils.ROUNDING_MIDDLE self.RoundingDecimals = 4 self.XmlCfgDocument = nil self.RaterEnabled = false @@ -378,9 +376,6 @@ func loadConfig(c *conf.ConfigFile) (*CGRConfig, error) { if hasOpt = c.HasOption("global", "default_subject"); hasOpt { cfg.DefaultSubject, _ = c.GetString("global", "default_subject") } - if hasOpt = c.HasOption("global", "rounding_method"); hasOpt { - cfg.RoundingMethod, _ = c.GetString("global", "rounding_method") - } if hasOpt = c.HasOption("global", "rounding_decimals"); hasOpt { cfg.RoundingDecimals, _ = c.GetInt("global", "rounding_decimals") } diff --git a/config/config_test.go b/config/config_test.go index 7525da522..d9387e52e 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -72,7 +72,6 @@ func TestDefaults(t *testing.T) { eCfg.DefaultCategory = "call" eCfg.DefaultTenant = "cgrates.org" eCfg.DefaultSubject = "cgrates" - eCfg.RoundingMethod = utils.ROUNDING_MIDDLE eCfg.RoundingDecimals = 4 eCfg.XmlCfgDocument = nil eCfg.RaterEnabled = false @@ -217,7 +216,6 @@ func TestConfigFromFile(t *testing.T) { eCfg.DefaultCategory = "test" eCfg.DefaultTenant = "test" eCfg.DefaultSubject = "test" - eCfg.RoundingMethod = "test" eCfg.RoundingDecimals = 99 eCfg.RaterEnabled = true eCfg.RaterBalancer = "test" diff --git a/config/test_data.txt b/config/test_data.txt index 7a0108b80..399c6c766 100644 --- a/config/test_data.txt +++ b/config/test_data.txt @@ -28,7 +28,6 @@ default_reqtype = test # Default request type to consider when missing from re default_category = test # Default Type of Record to consider when missing from requests. default_tenant = test # Default Tenant to consider when missing from requests. default_subject = test # Default rating Subject to consider when missing from requests. -rounding_method = test # Rounding method for floats/costs: rounding_decimals = 99 # Number of decimals to round floats/costs at diff --git a/engine/balances.go b/engine/balances.go index d913333db..53259188d 100644 --- a/engine/balances.go +++ b/engine/balances.go @@ -144,7 +144,7 @@ func (b *Balance) GetCost(cd *CallDescriptor) (*CallCost, error) { func (b *Balance) SubstractAmount(amount float64) { b.Value -= amount - b.Value = utils.Round(b.Value, roundingDecimals, utils.ROUNDING_MIDDLE) + b.Value = utils.Round(b.Value, globalRoundingDecimals, utils.ROUNDING_MIDDLE) b.dirty = true } diff --git a/engine/calldesc.go b/engine/calldesc.go index 7ca5a200c..ae011236d 100644 --- a/engine/calldesc.go +++ b/engine/calldesc.go @@ -57,14 +57,13 @@ const ( ) var ( - Logger utils.LoggerInterface - dataStorage RatingStorage - accountingStorage AccountingStorage - storageLogger LogStorage - debitPeriod = 10 * time.Second - roundingMethod = "*middle" - roundingDecimals = 4 - historyScribe history.Scribe + Logger utils.LoggerInterface + dataStorage RatingStorage + accountingStorage AccountingStorage + storageLogger LogStorage + debitPeriod = 10 * time.Second + globalRoundingDecimals = 10 + historyScribe history.Scribe //historyScribe, _ = history.NewMockScribe() ) @@ -78,9 +77,8 @@ func SetAccountingStorage(ag AccountingStorage) { } // Sets the global rounding method and decimal precision for GetCost method -func SetRoundingMethodAndDecimals(rm string, rd int) { - roundingMethod = rm - roundingDecimals = rd +func SetRoundingDecimals(rd int) { + globalRoundingDecimals = rd } /* @@ -434,7 +432,8 @@ func (cd *CallDescriptor) GetCost() (*CallCost, error) { cost += ts.getCost() } // global rounding - cost = utils.Round(cost, roundingDecimals, roundingMethod) + //TODO: use the longest rounding/method from ts + cost = utils.Round(cost, globalRoundingDecimals, globalRoundingMethod) //startIndex := len(fmt.Sprintf("%s:%s:%s:", cd.Direction, cd.Tenant, cd.Category)) cc := &CallCost{ Direction: cd.Direction, @@ -578,7 +577,7 @@ func (cd *CallDescriptor) debit(account *Account) (cc *CallCost, err error) { } for _, ts := range cc.Timespans { cost += ts.getCost() - cost = utils.Round(cost, roundingDecimals, utils.ROUNDING_MIDDLE) // just get rid of the extra decimals + cost = utils.Round(cost, globalRoundingDecimals, utils.ROUNDING_MIDDLE) // just get rid of the extra decimals } cc.Cost = cost cc.Timespans.Compress() diff --git a/engine/timespans.go b/engine/timespans.go index 96f0daf10..9b710452b 100644 --- a/engine/timespans.go +++ b/engine/timespans.go @@ -284,7 +284,7 @@ func (ts *TimeSpan) createIncrementsSlice() { //incrementCost := rate / rateUnit.Seconds() * rateIncrement.Seconds() nbIncrements := int(ts.GetDuration() / rateIncrement) incrementCost := ts.getCost() / float64(nbIncrements) - incrementCost = utils.Round(incrementCost, roundingDecimals, utils.ROUNDING_MIDDLE) // just get rid of the extra decimals + incrementCost = utils.Round(incrementCost, globalRoundingDecimals, utils.ROUNDING_MIDDLE) // just get rid of the extra decimals for s := 0; s < nbIncrements; s++ { inc := &Increment{ Duration: rateIncrement,