Cache decimals and use floats for easier exposure to outside world

This commit is contained in:
DanB
2020-06-09 19:57:44 +02:00
parent 64cd0f365e
commit 353d95d7c9
6 changed files with 25 additions and 21 deletions

View File

@@ -1,2 +1,3 @@
#Tenant,ID,FilterIDs,ActivationInterval,Weight,ConnectFee,RoundingMethod,RoundingDecimals,MinCost,MaxCost,MaxCostStrategy,RateID,RateFilterIDs,RateWeight,RateValue,RateUnit,RateIncrement,RateBlocker
cgrates.org,RP1,*string:~*req.Subject:1001,,0,0.1,*up,4,0.1,0.6,*free,FIRST_GI,*gi:~*req.Usage:0,0,0.12,1m,1s,FALSE
cgrates.org,RP1,*string:~*req.Subject:1001,,0,0.1,*up,4,0.1,0.6,*free,FIRST_GI,*gi:~*req.Usage:0,0,0.12,1m,1m,FALSE
cgrates.org,RP1,*string:~*req.Subject:1002,,,,,,,,,SECOND_GI,*gi:~*req.Usage:1m,10,0.06,1m,1s,FALSE
1 #Tenant ID FilterIDs ActivationInterval Weight ConnectFee RoundingMethod RoundingDecimals MinCost MaxCost MaxCostStrategy RateID RateFilterIDs RateWeight RateValue RateUnit RateIncrement RateBlocker
2 cgrates.org RP1 *string:~*req.Subject:1001 0 0.1 *up 4 0.1 0.6 *free FIRST_GI *gi:~*req.Usage:0 0 0.12 1m 1s 1m FALSE
3 cgrates.org RP1 *string:~*req.Subject:1002 SECOND_GI *gi:~*req.Usage:1m 10 0.06 1m 1s FALSE

View File

@@ -31,22 +31,28 @@ type RateProfile struct {
FilterIDs []string
ActivationInterval *utils.ActivationInterval
Weight float64
ConnectFee *utils.Decimal
ConnectFee float64
RoundingMethod string
RoundingDecimals int
MinCost *utils.Decimal
MaxCost *utils.Decimal
MinCost float64
MaxCost float64
MaxCostStrategy string
Rates []*Rate
connFee *utils.Decimal // cached version of the Decimal
minCost *utils.Decimal
maxCost *utils.Decimal
}
// Route defines rate related information used within a RateProfile
type Rate struct {
ID string // RateID
FilterIDs []string // RateFilterIDs
Weight float64 // RateWeight
Value *utils.Decimal // RateValue
Unit time.Duration // RateUnit
Increment time.Duration // RateIncrement
Blocker bool // RateBlocker will make this rate recurrent
ID string // RateID
FilterIDs []string // RateFilterIDs
Weight float64 // RateWeight
Value float64 // RateValue
Unit time.Duration // RateUnit
Increment time.Duration // RateIncrement
Blocker bool // RateBlocker will make this rate recurrent
val *utils.Decimal // cached version of the Decimal
}

View File

@@ -25,7 +25,7 @@ type ChargedCost struct {
RunID string
StartTime time.Time
Usage *time.Duration
Cost *Decimal
Cost float64
Charges []*ChargedInterval
AccountSummary ChargedAccount
Accounting ChargedAccounting

View File

@@ -23,7 +23,9 @@ import "time"
// ChargedIncrement represents one unit charged inside an interval
type ChargedIncrement struct {
Usage time.Duration
Cost *Decimal
Cost float64
AccountingID string // Accounting charged information
CompressFactor int
cost *Decimal // cached version of the Decimal
}

View File

@@ -18,13 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
package utils
import (
"encoding/json"
"reflect"
"testing"
"time"
)
/*
func TestJSONMarshalUnmarshal(t *testing.T) {
incrmt := &ChargedIncrement{
Usage: time.Duration(1 * time.Hour),
@@ -58,3 +52,4 @@ func TestJSONMarshalUnmarshal(t *testing.T) {
t.Errorf("expecting: %+v, received: %+v", incrmt, uIncrmnt)
}
}
*/

View File

@@ -25,5 +25,5 @@ type ChargedInterval struct {
CompressFactor int
ccUsageIdx *time.Duration // computed value of totalUsage at the starting of the interval
usage *time.Duration // cache usage computation for this interval
cost *float64 // cache cost calculation on this interval // #ToDo: replace here with decimal.Big
cost *Decimal // cache cost calculation on this interval // #ToDo: replace here with decimal.Big
}