mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-21 07:08:45 +05:00
no more global rounding method
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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")
|
||||
}
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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: <up|middle|down>
|
||||
rounding_decimals = 99 # Number of decimals to round floats/costs at
|
||||
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user