AccountDigest - AccountSummary for better readability

This commit is contained in:
DanB
2016-08-29 12:57:24 +02:00
parent 534588350d
commit 90069ab05d
9 changed files with 49 additions and 49 deletions

View File

@@ -228,7 +228,7 @@ type CGRConfig struct {
CDRSEnabled bool // Enable CDR Server service
CDRSExtraFields []*utils.RSRField // Extra fields to store in CDRs
CDRSStoreCdrs bool // store cdrs in storDb
CDRScdrAccountDigest bool
CDRScdrAccountSummary bool
CDRSRaterConns []*HaPoolConfig // address where to reach the Rater for cost calculation: <""|internal|x.y.z.y:1234>
CDRSPubSubSConns []*HaPoolConfig // address where to reach the pubsub service: <""|internal|x.y.z.y:1234>
CDRSUserSConns []*HaPoolConfig // address where to reach the users service: <""|internal|x.y.z.y:1234>
@@ -817,8 +817,8 @@ func (self *CGRConfig) loadFromJsonCfg(jsnCfg *CgrJsonCfg) error {
if jsnCdrsCfg.Store_cdrs != nil {
self.CDRSStoreCdrs = *jsnCdrsCfg.Store_cdrs
}
if jsnCdrsCfg.Cdr_account_digest != nil {
self.CDRScdrAccountDigest = *jsnCdrsCfg.Cdr_account_digest
if jsnCdrsCfg.Cdr_account_summary != nil {
self.CDRScdrAccountSummary = *jsnCdrsCfg.Cdr_account_summary
}
if jsnCdrsCfg.Rals_conns != nil {
self.CDRSRaterConns = make([]*HaPoolConfig, len(*jsnCdrsCfg.Rals_conns))

View File

@@ -132,7 +132,7 @@ const CGRATES_CFG_JSON = `
"enabled": false, // start the CDR Server service: <true|false>
"extra_fields": [], // extra fields to store in CDRs for non-generic CDRs
"store_cdrs": true, // store cdrs in storDb
"cdr_account_digest": false, // add account information from dataDB
"cdr_account_summary": false, // add account information from dataDB
"rals_conns": [
{"address": "*internal"} // address where to reach the Rater for cost calculation, empty to disable functionality: <""|*internal|x.y.z.y:1234>
],

View File

@@ -174,10 +174,10 @@ func TestDfSchedulerJsonCfg(t *testing.T) {
func TestDfCdrsJsonCfg(t *testing.T) {
eCfg := &CdrsJsonCfg{
Enabled: utils.BoolPointer(false),
Extra_fields: utils.StringSlicePointer([]string{}),
Store_cdrs: utils.BoolPointer(true),
Cdr_account_digest: utils.BoolPointer(false),
Enabled: utils.BoolPointer(false),
Extra_fields: utils.StringSlicePointer([]string{}),
Store_cdrs: utils.BoolPointer(true),
Cdr_account_summary: utils.BoolPointer(false),
Rals_conns: &[]*HaPoolJsonCfg{
&HaPoolJsonCfg{
Address: utils.StringPointer("*internal"),

View File

@@ -85,16 +85,16 @@ type SchedulerJsonCfg struct {
// Cdrs config section
type CdrsJsonCfg struct {
Enabled *bool
Extra_fields *[]string
Store_cdrs *bool
Cdr_account_digest *bool
Rals_conns *[]*HaPoolJsonCfg
Pubsubs_conns *[]*HaPoolJsonCfg
Users_conns *[]*HaPoolJsonCfg
Aliases_conns *[]*HaPoolJsonCfg
Cdrstats_conns *[]*HaPoolJsonCfg
Cdr_replication *[]*CdrReplicationJsonCfg
Enabled *bool
Extra_fields *[]string
Store_cdrs *bool
Cdr_account_summary *bool
Rals_conns *[]*HaPoolJsonCfg
Pubsubs_conns *[]*HaPoolJsonCfg
Users_conns *[]*HaPoolJsonCfg
Aliases_conns *[]*HaPoolJsonCfg
Cdrstats_conns *[]*HaPoolJsonCfg
Cdr_replication *[]*CdrReplicationJsonCfg
}
type CdrReplicationJsonCfg struct {

View File

@@ -1019,9 +1019,9 @@ func (acc *Account) AsOldStructure() interface{} {
return result
}
func (acc *Account) AsAccountDigest() *AccountDigest {
func (acc *Account) AsAccountSummary() *AccountSummary {
idSplt := strings.Split(acc.ID, utils.CONCATENATED_KEY_SEP)
ad := &AccountDigest{AllowNegative: acc.AllowNegative, Disabled: acc.Disabled}
ad := &AccountSummary{AllowNegative: acc.AllowNegative, Disabled: acc.Disabled}
if len(idSplt) == 1 {
ad.ID = idSplt[0]
} else if len(idSplt) == 2 {
@@ -1030,17 +1030,17 @@ func (acc *Account) AsAccountDigest() *AccountDigest {
}
for balanceType, balances := range acc.BalanceMap {
for _, balance := range balances {
ad.BalanceDigests = append(ad.BalanceDigests, balance.AsBalanceDigest(balanceType))
ad.BalanceSummaries = append(ad.BalanceSummaries, balance.AsBalanceSummary(balanceType))
}
}
return ad
}
// AccountDigest contains compressed information about an Account
type AccountDigest struct {
Tenant string
ID string
BalanceDigests []*BalanceDigest
AllowNegative bool
Disabled bool
type AccountSummary struct {
Tenant string
ID string
BalanceSummaries []*BalanceSummary
AllowNegative bool
Disabled bool
}

View File

@@ -1886,30 +1886,30 @@ func TestAccountAsAccountDigest(t *testing.T) {
},
},
}
expectAcntDigest := &AccountDigest{
expectacntSummary := &AccountSummary{
Tenant: "cgrates.org",
ID: "account1",
BalanceDigests: []*BalanceDigest{
&BalanceDigest{ID: "sms1", Type: utils.SMS, Value: 14, Disabled: false},
&BalanceDigest{ID: "data1", Type: utils.DATA, Value: 1204, Disabled: false},
&BalanceDigest{ID: "voice1", Type: utils.VOICE, Value: 1204, Disabled: false},
&BalanceDigest{ID: "voice2", Type: utils.VOICE, Value: 1200, Disabled: false},
BalanceSummaries: []*BalanceSummary{
&BalanceSummary{ID: "sms1", Type: utils.SMS, Value: 14, Disabled: false},
&BalanceSummary{ID: "data1", Type: utils.DATA, Value: 1204, Disabled: false},
&BalanceSummary{ID: "voice1", Type: utils.VOICE, Value: 1204, Disabled: false},
&BalanceSummary{ID: "voice2", Type: utils.VOICE, Value: 1200, Disabled: false},
},
AllowNegative: true,
Disabled: false,
}
acntDigest := acnt1.AsAccountDigest()
if expectAcntDigest.Tenant != acntDigest.Tenant ||
expectAcntDigest.ID != acntDigest.ID ||
expectAcntDigest.AllowNegative != acntDigest.AllowNegative ||
expectAcntDigest.Disabled != acntDigest.Disabled ||
len(expectAcntDigest.BalanceDigests) != len(acntDigest.BalanceDigests) {
t.Errorf("Expecting: %+v, received: %+v", expectAcntDigest, acntDigest)
acntSummary := acnt1.AsAccountSummary()
if expectacntSummary.Tenant != acntSummary.Tenant ||
expectacntSummary.ID != acntSummary.ID ||
expectacntSummary.AllowNegative != acntSummary.AllowNegative ||
expectacntSummary.Disabled != acntSummary.Disabled ||
len(expectacntSummary.BalanceSummaries) != len(acntSummary.BalanceSummaries) {
t.Errorf("Expecting: %+v, received: %+v", expectacntSummary, acntSummary)
}
// Since maps are unordered, slices will be too so we need to find element to compare
for _, bd := range acntDigest.BalanceDigests {
if bd.ID == "sms1" && !reflect.DeepEqual(expectAcntDigest.BalanceDigests[0], bd) {
t.Errorf("Expecting: %+v, received: %+v", expectAcntDigest, acntDigest)
for _, bd := range acntSummary.BalanceSummaries {
if bd.ID == "sms1" && !reflect.DeepEqual(expectacntSummary.BalanceSummaries[0], bd) {
t.Errorf("Expecting: %+v, received: %+v", expectacntSummary, acntSummary)
}
}
}

View File

@@ -621,8 +621,8 @@ func (b *Balance) debitMoney(cd *CallDescriptor, ub *Account, moneyBalances Bala
}
// Converts the balance towards compressed information to be displayed
func (b *Balance) AsBalanceDigest(typ string) *BalanceDigest {
bd := &BalanceDigest{ID: b.ID, Type: typ, Value: b.Value, Disabled: b.Disabled}
func (b *Balance) AsBalanceSummary(typ string) *BalanceSummary {
bd := &BalanceSummary{ID: b.ID, Type: typ, Value: b.Value, Disabled: b.Disabled}
if bd.ID == "" {
bd.ID = b.Uuid
}
@@ -752,7 +752,7 @@ func (f ValueFactor) GetValue(tor string) float64 {
}
// BalanceDigest represents compressed information about a balance
type BalanceDigest struct {
type BalanceSummary struct {
ID string // ID or UUID if not defined
Type string // *voice, *data, etc
Value float64

View File

@@ -30,7 +30,7 @@ type CallCost struct {
Cost float64
Timespans TimeSpans
RatedUsage float64
AccountDigest *AccountDigest
AccountSummary *AccountSummary
deductConnectFee bool
negativeConnectFee bool // the connect fee went negative on default balance
maxCostDisconect bool

View File

@@ -246,13 +246,13 @@ func (self *CdrServer) deriveRateStoreStatsReplicate(cdr *CDR, store, stats, rep
ratedCDR.CostDetails.UpdateCost()
ratedCDR.CostDetails.UpdateRatedUsage()
if utils.IsSliceMember([]string{utils.META_PREPAID, utils.PREPAID, utils.META_PSEUDOPREPAID, utils.PSEUDOPREPAID,
utils.META_POSTPAID, utils.POSTPAID}, ratedCDR.RequestType) && self.cgrCfg.CDRScdrAccountDigest {
utils.META_POSTPAID, utils.POSTPAID}, ratedCDR.RequestType) && self.cgrCfg.CDRScdrAccountSummary {
acntID := utils.ConcatenatedKey(ratedCDR.Tenant, ratedCDR.Account)
acnt, err := self.dataDB.GetAccount(acntID)
if err != nil {
utils.Logger.Err(fmt.Sprintf("<CDRS> Querying AccountDigest for account: %s got error: %s", acntID, err.Error()))
} else if acnt.ID != "" {
ratedCDR.CostDetails.AccountDigest = acnt.AsAccountDigest()
ratedCDR.CostDetails.AccountSummary = acnt.AsAccountSummary()
}
}
}