diff --git a/cmd/cgr-loader/cgr-loader.go b/cmd/cgr-loader/cgr-loader.go index 664f28c48..78f0dff89 100644 --- a/cmd/cgr-loader/cgr-loader.go +++ b/cmd/cgr-loader/cgr-loader.go @@ -58,6 +58,7 @@ var ( version = flag.Bool("version", false, "Prints the application version.") verbose = flag.Bool("verbose", false, "Enable detailed verbose logging output") dryRun = flag.Bool("dry_run", false, "When true will not save loaded data to dataDb but just parse it for consistency and errors.") + stats = flag.Bool("stats", false, "Generates statsistics about given data.") fromStorDb = flag.Bool("from_stordb", false, "Load the tariff plan from storDb to dataDb") toStorDb = flag.Bool("to_stordb", false, "Import the tariff plan from files to storDb") historyServer = flag.String("history_server", cgrConfig.HistoryServer, "The history server address:port, empty to disable automaticautomatic history archiving") @@ -125,6 +126,9 @@ func main() { if err != nil { log.Fatal(err) } + if *stats { + loader.ShowStatistics() + } if *dryRun { // We were just asked to parse the data, not saving it return } diff --git a/engine/destinations.go b/engine/destinations.go index 68941e28b..5835347c9 100644 --- a/engine/destinations.go +++ b/engine/destinations.go @@ -38,7 +38,7 @@ type Destination struct { } // returns prefix precision -func (d *Destination) containsPrefix(prefix string) int { +func (d *Destination) containsPrefix1(prefix string) int { if d == nil { return 0 } diff --git a/engine/loader_csv.go b/engine/loader_csv.go index 7717cbdee..004ed7906 100644 --- a/engine/loader_csv.go +++ b/engine/loader_csv.go @@ -96,6 +96,22 @@ func openStringCSVReader(data string, comma rune, nrFields int) (csvReader *csv. return } +func (csvr *CSVReader) ShowStatistics() { + destCount := len(csvr.destinations) + log.Print("Destinations: ", destCount) + prefixDist := make(map[int]int, 50) + prefixCount := 0 + for _, d := range csvr.destinations { + prefixDist[len(d.Prefixes)] += 1 + prefixCount += len(d.Prefixes) + } + log.Print("Avg Prefixes: ", prefixCount/destCount) + log.Print("Prefixes distribution:") + for k, v := range prefixDist { + log.Printf("%d: %d", k, v) + } +} + func (csvr *CSVReader) WriteToDatabase(flush, verbose bool) (err error) { storage := csvr.storage if storage == nil { diff --git a/engine/loader_db.go b/engine/loader_db.go index cf7bacd6a..23dbbdb54 100644 --- a/engine/loader_db.go +++ b/engine/loader_db.go @@ -21,8 +21,9 @@ package engine import ( "errors" "fmt" - "github.com/cgrates/cgrates/utils" "log" + + "github.com/cgrates/cgrates/utils" ) type DbReader struct { @@ -54,6 +55,9 @@ func NewDbReader(storDB LoadStorage, storage DataStorage, tpid string) *DbReader return c } +func (dbr *DbReader) ShowStatistics() { +} + func (dbr *DbReader) WriteToDatabase(flush, verbose bool) (err error) { storage := dbr.dataDb if flush { diff --git a/engine/loader_helpers.go b/engine/loader_helpers.go index b991b82a1..d189734f2 100644 --- a/engine/loader_helpers.go +++ b/engine/loader_helpers.go @@ -22,7 +22,6 @@ import ( "bufio" "errors" "fmt" - "github.com/cgrates/cgrates/utils" "log" "math" "os" @@ -30,6 +29,8 @@ import ( "regexp" "strconv" "strings" + + "github.com/cgrates/cgrates/utils" ) type TPLoader interface { @@ -45,6 +46,7 @@ type TPLoader interface { LoadAccountActions() error LoadAll() error GetLoadedIds(string) ([]string, error) + ShowStatistics() WriteToDatabase(bool, bool) error }