mirror of
https://github.com/carlostrub/sisyphus
synced 2024-10-31 09:20:15 +00:00
move info into the library
This commit is contained in:
parent
944d4c7610
commit
379d9dee1c
50
info.go
Executable file
50
info.go
Executable file
@ -0,0 +1,50 @@
|
|||||||
|
package sisyphus
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/boltdb/bolt"
|
||||||
|
"github.com/retailnext/hllpp"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Info produces statistics
|
||||||
|
func Info(db *bolt.DB) (gTotal, jTotal, gWords, jWords uint64) {
|
||||||
|
|
||||||
|
_ = db.View(func(tx *bolt.Tx) error {
|
||||||
|
p := tx.Bucket([]byte("Statistics"))
|
||||||
|
gRaw := p.Get([]byte("ProcessedGood"))
|
||||||
|
if len(gRaw) > 0 {
|
||||||
|
var gHLL *hllpp.HLLPP
|
||||||
|
gHLL, _ = hllpp.Unmarshal(gRaw)
|
||||||
|
gTotal = gHLL.Count()
|
||||||
|
}
|
||||||
|
jRaw := p.Get([]byte("ProcessedJunk"))
|
||||||
|
if len(jRaw) > 0 {
|
||||||
|
var jHLL *hllpp.HLLPP
|
||||||
|
jHLL, _ = hllpp.Unmarshal(jRaw)
|
||||||
|
jTotal = jHLL.Count()
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
|
||||||
|
_ = db.View(func(tx *bolt.Tx) error {
|
||||||
|
p := tx.Bucket([]byte("Wordlists"))
|
||||||
|
pj := p.Bucket([]byte("Junk"))
|
||||||
|
|
||||||
|
stats := pj.Stats()
|
||||||
|
jWords = uint64(stats.KeyN)
|
||||||
|
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
|
||||||
|
_ = db.View(func(tx *bolt.Tx) error {
|
||||||
|
p := tx.Bucket([]byte("Wordlists"))
|
||||||
|
pg := p.Bucket([]byte("Good"))
|
||||||
|
|
||||||
|
stats := pg.Stats()
|
||||||
|
gWords = uint64(stats.KeyN)
|
||||||
|
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
|
||||||
|
return gTotal, jTotal, gWords, jWords
|
||||||
|
}
|
@ -13,7 +13,6 @@ import (
|
|||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
|
|
||||||
"github.com/carlostrub/sisyphus"
|
"github.com/carlostrub/sisyphus"
|
||||||
"gopkg.in/urfave/cli.v2"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -239,7 +238,7 @@ COPYRIGHT:
|
|||||||
defer sisyphus.CloseDatabases(dbs)
|
defer sisyphus.CloseDatabases(dbs)
|
||||||
|
|
||||||
for _, db := range dbs {
|
for _, db := range dbs {
|
||||||
gTotal, jTotal, gWords, jWords := info(db)
|
gTotal, jTotal, gWords, jWords := sisyphus.Info(db)
|
||||||
log.WithFields(log.Fields{
|
log.WithFields(log.Fields{
|
||||||
"good mails learned": gTotal,
|
"good mails learned": gTotal,
|
||||||
"junk mails learned": jTotal,
|
"junk mails learned": jTotal,
|
||||||
|
Loading…
Reference in New Issue
Block a user