mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
CdrStats name change
# Changes to be committed:
This commit is contained in:
@@ -316,10 +316,10 @@ func APItoModelDerivedCharger(dcs *utils.TPDerivedChargers) (result []TpDerivedC
|
||||
return
|
||||
}
|
||||
|
||||
func APItoModelCdrStat(stats *utils.TPCdrStats) (result []TpCdrStat) {
|
||||
func APItoModelCdrStat(stats *utils.TPCdrStats) (result []TpCdrstat) {
|
||||
for _, st := range stats.CdrStats {
|
||||
ql, _ := strconv.Atoi(st.QueueLength)
|
||||
result = append(result, TpCdrStat{
|
||||
result = append(result, TpCdrstat{
|
||||
Tpid: stats.TPid,
|
||||
Tag: stats.CdrStatsId,
|
||||
QueueLength: ql,
|
||||
@@ -347,7 +347,7 @@ func APItoModelCdrStat(stats *utils.TPCdrStats) (result []TpCdrStat) {
|
||||
})
|
||||
}
|
||||
if len(stats.CdrStats) == 0 {
|
||||
result = append(result, TpCdrStat{
|
||||
result = append(result, TpCdrstat{
|
||||
Tpid: stats.TPid,
|
||||
Tag: stats.CdrStatsId,
|
||||
})
|
||||
|
||||
@@ -496,7 +496,7 @@ func (tps TpDerivedChargers) GetDerivedChargers() (map[string]*utils.TPDerivedCh
|
||||
return dcs, nil
|
||||
}
|
||||
|
||||
type TpCdrStats []TpCdrStat
|
||||
type TpCdrStats []TpCdrstat
|
||||
|
||||
func (tps TpCdrStats) GetCdrStats() (map[string][]*utils.TPCdrStat, error) {
|
||||
css := make(map[string][]*utils.TPCdrStat)
|
||||
|
||||
@@ -16,8 +16,8 @@ func TestModelHelperCsvLoad(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestModelHelperCsvLoadInt(t *testing.T) {
|
||||
l, err := csvLoad(TpCdrStat{}, []string{"CDRST1", "5", "60m", "ASR", "2014-07-29T15:00:00Z;2014-07-29T16:00:00Z", "*voice", "87.139.12.167", "FS_JSON", "*rated", "*out", "cgrates.org", "call", "dan", "dan", "49", "5m;10m", "suppl1", "NORMAL_CLEARING", "default", "rif", "rif", "0;2", "STANDARD_TRIGGERS"})
|
||||
tpd := l.(TpCdrStat)
|
||||
l, err := csvLoad(TpCdrstat{}, []string{"CDRST1", "5", "60m", "ASR", "2014-07-29T15:00:00Z;2014-07-29T16:00:00Z", "*voice", "87.139.12.167", "FS_JSON", "*rated", "*out", "cgrates.org", "call", "dan", "dan", "49", "5m;10m", "suppl1", "NORMAL_CLEARING", "default", "rif", "rif", "0;2", "STANDARD_TRIGGERS"})
|
||||
tpd := l.(TpCdrstat)
|
||||
if err != nil || tpd.QueueLength != 5 {
|
||||
t.Errorf("model load failed: %+v", tpd)
|
||||
}
|
||||
|
||||
@@ -284,7 +284,7 @@ func (tpdc *TpDerivedCharger) SetDerivedChargersId(id string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (tpdc *TpDerivedCharger) GetDerivedChargersId1() string {
|
||||
func (tpdc *TpDerivedCharger) GetDerivedChargersId() string {
|
||||
return utils.ConcatenatedKey(tpdc.Loadid, tpdc.Direction, tpdc.Tenant, tpdc.Category, tpdc.Account, tpdc.Subject)
|
||||
}
|
||||
|
||||
|
||||
@@ -431,8 +431,8 @@ func (csvs *CSVStorage) GetTpDerivedChargers(filter *TpDerivedCharger) ([]TpDeri
|
||||
return tpDerivedChargers, nil
|
||||
}
|
||||
|
||||
func (csvs *CSVStorage) GetTpCdrStats(tpid, tag string) ([]TpCdrStat, error) {
|
||||
csvReader, fp, err := csvs.readerFunc(csvs.cdrStatsFn, csvs.sep, getColumnCount(TpCdrStat{}))
|
||||
func (csvs *CSVStorage) GetTpCdrStats(tpid, tag string) ([]TpCdrstat, error) {
|
||||
csvReader, fp, err := csvs.readerFunc(csvs.cdrStatsFn, csvs.sep, getColumnCount(TpCdrstat{}))
|
||||
if err != nil {
|
||||
log.Print("Could not load cdr stats file: ", err)
|
||||
// allow writing of the other values
|
||||
@@ -441,17 +441,17 @@ func (csvs *CSVStorage) GetTpCdrStats(tpid, tag string) ([]TpCdrStat, error) {
|
||||
if fp != nil {
|
||||
defer fp.Close()
|
||||
}
|
||||
var tpCdrStats []TpCdrStat
|
||||
var tpCdrStats []TpCdrstat
|
||||
for record, err := csvReader.Read(); err != io.EOF; record, err = csvReader.Read() {
|
||||
if err != nil {
|
||||
log.Print("bad line in cdr stats csv: ", err)
|
||||
return nil, err
|
||||
}
|
||||
if tpCdrStat, err := csvLoad(TpCdrStat{}, record); err != nil {
|
||||
if tpCdrStat, err := csvLoad(TpCdrstat{}, record); err != nil {
|
||||
log.Print("error loading cdr stat: ", err)
|
||||
return nil, err
|
||||
} else {
|
||||
cs := tpCdrStat.(TpCdrStat)
|
||||
cs := tpCdrStat.(TpCdrstat)
|
||||
cs.Tpid = tpid
|
||||
tpCdrStats = append(tpCdrStats, cs)
|
||||
}
|
||||
|
||||
@@ -144,7 +144,7 @@ type LoadReader interface {
|
||||
GetTpRatingPlans(string, string, *utils.Paginator) ([]TpRatingPlan, error)
|
||||
GetTpRatingProfiles(*TpRatingProfile) ([]TpRatingProfile, error)
|
||||
GetTpSharedGroups(string, string) ([]TpSharedGroup, error)
|
||||
GetTpCdrStats(string, string) ([]TpCdrStat, error)
|
||||
GetTpCdrStats(string, string) ([]TpCdrstat, error)
|
||||
GetTpDerivedChargers(*TpDerivedCharger) ([]TpDerivedCharger, error)
|
||||
GetTpLCRs(string, string) ([]TpLcrRule, error)
|
||||
GetTpActions(string, string) ([]TpAction, error)
|
||||
@@ -162,7 +162,7 @@ type LoadWriter interface {
|
||||
SetTpRatingPlans([]TpRatingPlan) error
|
||||
SetTpRatingProfiles([]TpRatingProfile) error
|
||||
SetTpSharedGroups([]TpSharedGroup) error
|
||||
SetTpCdrStats([]TpCdrStat) error
|
||||
SetTpCdrStats([]TpCdrstat) error
|
||||
SetTpDerivedChargers([]TpDerivedCharger) error
|
||||
SetTpLCRs([]TpLcrRule) error
|
||||
SetTpActions([]TpAction) error
|
||||
|
||||
@@ -371,48 +371,17 @@ func (self *SQLStorage) SetTpSharedGroups(sgs []TpSharedGroup) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SQLStorage) SetTpCdrStats(css []TpCdrStat) error {
|
||||
func (self *SQLStorage) SetTpCdrStats(css []TpCdrstat) error {
|
||||
if len(css) == 0 {
|
||||
return nil //Nothing to set
|
||||
}
|
||||
m := make(map[string]bool)
|
||||
|
||||
tx := self.db.Begin()
|
||||
for csId, cStats := range css {
|
||||
if err := tx.Where(&TpCdrstat{Tpid: tpid, Tag: csId}).Delete(TpCdrstat{}).Error; err != nil {
|
||||
tx.Rollback()
|
||||
return err
|
||||
}
|
||||
for _, cs := range cStats {
|
||||
ql, _ := strconv.Atoi(cs.QueueLength)
|
||||
saved := tx.Save(&TpCdrstat{
|
||||
Tpid: tpid,
|
||||
Tag: csId,
|
||||
QueueLength: ql,
|
||||
TimeWindow: cs.TimeWindow,
|
||||
Metrics: cs.Metrics,
|
||||
SetupInterval: cs.SetupInterval,
|
||||
Tors: cs.TORs,
|
||||
CdrHosts: cs.CdrHosts,
|
||||
CdrSources: cs.CdrSources,
|
||||
ReqTypes: cs.ReqTypes,
|
||||
Directions: cs.Directions,
|
||||
Tenants: cs.Tenants,
|
||||
Categories: cs.Categories,
|
||||
Accounts: cs.Accounts,
|
||||
Subjects: cs.Subjects,
|
||||
DestinationPrefixes: cs.DestinationPrefixes,
|
||||
UsageInterval: cs.UsageInterval,
|
||||
Suppliers: cs.Suppliers,
|
||||
DisconnectCauses: cs.DisconnectCauses,
|
||||
MediationRunids: cs.MediationRunIds,
|
||||
RatedAccounts: cs.RatedAccounts,
|
||||
RatedSubjects: cs.RatedSubjects,
|
||||
CostInterval: cs.CostInterval,
|
||||
ActionTriggers: cs.ActionTriggers,
|
||||
CreatedAt: time.Now(),
|
||||
})
|
||||
if saved.Error != nil {
|
||||
for _, cStat := range css {
|
||||
if found, _ := m[cStat.Tag]; !found {
|
||||
m[cStat.Tag] = true
|
||||
if err := tx.Where(&TpCdrstat{Tpid: cStat.Tpid, Tag: cStat.Tag}).Delete(TpCdrstat{}).Error; err != nil {
|
||||
tx.Rollback()
|
||||
return err
|
||||
}
|
||||
@@ -1327,7 +1296,7 @@ func (self *SQLStorage) GetTpDerivedChargers(filter *TpDerivedCharger) ([]TpDeri
|
||||
return tpDerivedChargers, nil
|
||||
}
|
||||
|
||||
func (self *SQLStorage) GetTpCdrStats(tpid, tag string) ([]TpCdrStat, error) {
|
||||
func (self *SQLStorage) GetTpCdrStats(tpid, tag string) ([]TpCdrstat, error) {
|
||||
var tpCdrStats []TpCdrstat
|
||||
q := self.db.Where("tpid = ?", tpid)
|
||||
if len(tag) != 0 {
|
||||
|
||||
Reference in New Issue
Block a user