started statistics

This commit is contained in:
Radu Ioan Fericean
2013-12-17 16:42:16 +02:00
parent dbe8bde7bf
commit 3e4067b4b0
5 changed files with 29 additions and 3 deletions

View File

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

View File

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

View File

@@ -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 {

View File

@@ -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 {

View File

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