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

@@ -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()
}
}
}