From 144a7f5e5ff7296d767f333d63b930107c3bfadf Mon Sep 17 00:00:00 2001
From: sunty <1172534965@qq.com>
Date: 星期四, 18 七月 2019 10:10:19 +0800
Subject: [PATCH] fix init
---
dbpersoninfo.go | 117 +++++++++++++++++++++++++++++++++++++++++-----------------
1 files changed, 82 insertions(+), 35 deletions(-)
diff --git a/dbpersoninfo.go b/dbpersoninfo.go
index 24f1f93..cfaa6c2 100644
--- a/dbpersoninfo.go
+++ b/dbpersoninfo.go
@@ -7,9 +7,10 @@
"sync"
"encoding/base64"
- "basic.com/pubsub/cache.git/esutil"
+ "encoding/json"
+
+ "basic.com/pubsub/cache.git/esutil"
"basic.com/pubsub/cache.git/shardmap"
- "basic.com/pubsub/protomsg.git"
"basic.com/valib/gosdk.git"
)
@@ -17,78 +18,124 @@
var querynum = flag.Int("querynum", 10, "the query number from database")
var threadnum = flag.Int("threadnum",32, "the number of thread to deal data.")
-var Cmap *shardmap.ShardMap
-func Init(){
+type CmapItem struct {
+ sync.Mutex
+ Cam map[string]*shardmap.ShardMap
+}
+
+var Cmap *CmapItem
+
+func Init(indexName string, serverIp string, serverPort string, analyServerId string){
flag.Parse()
gosdk.InitFaceExtractor(16, 0)
- Cmap = shardmap.New(uint8(*threadnum))
+ Cmap = &CmapItem{
+ Cam: make(map[string]*shardmap.ShardMap),
+ }
temptime := time.Now()
var wg sync.WaitGroup
+
for i:=0; i<*threadnum; i++ {
j := i*(*querynum)
wg.Add(1)
go func(qs int){
defer wg.Done()
-
- escache, err := esutil.DbPersoninfos(qs, *querynum)
+ escache, err := esutil.Personinfos(qs, *querynum, indexName, serverIp, serverPort, analyServerId)
if err != nil {
fmt.Println(err)
return
}
- for _, value := range escache {
- Cmap.Set(value.FaceFeature,value)
+ Cmap.Lock()
+
+ var tableidstring string
+ for _, value := range escache{
+
+ // 濡傛灉娌℃湁tableid 鍒� tableidstring = capturetable
+ if value.Tableid == ""{
+ tableidstring="capturetable"
+ }else{
+ tableidstring = value.Tableid
+ }
+
+ if _, ok :=Cmap.Cam[tableidstring]; !ok {
+ Cmap.Cam[tableidstring]=shardmap.New(uint8(*threadnum))
+ }
+
+ Cmap.Cam[tableidstring].Set(value.Id,value.FaceFeature)
}
+
+ Cmap.Unlock()
+
}(j)
}
wg.Wait()
- fmt.Println("get number of es: ", Cmap.GetLen())
fmt.Println("time of get data from es.", time.Since(temptime))
fmt.Println()
}
-//func main(){
-// Init()
-// Getdbpersonmsg("")
-//}
+func GetComparePersonBaseInfo(tableid []string, faceFeature []byte, compareThreshold int) []byte {
-func Getdbpersonmsg(teststring string, IsCompare bool) ([]protomsg.Baseinfo) {
+ totalmap := make(map[string]float32)
- if !IsCompare {
+ if faceFeature == nil {
return nil
}
- if teststring == "" {
- testcache, _:= esutil.DbPersoninfos(0,1)
- teststring = testcache[0].FaceFeature
+ if tableid == nil {
+ //瀵规瘮鍏ㄩ儴
+ for _, val := range Cmap.Cam {
+ tmpmap := val.Walk(Printest, faceFeature)
+ for key, sec := range tmpmap {
+ if sec > 70*0.01 {
+ totalmap[key] = sec
+ }
+ }
+ }
+ } else {
+ for _, tid := range tableid {
+ shardins, ok := Cmap.Cam[tid]
+ fmt.Println(ok)
+ if !ok {
+ fmt.Println("get shad error by id", shardins)
+ continue
+ }
+ tmpmap := shardins.Walk(Printest, faceFeature)
+ for key, sec := range tmpmap {
+ if compareThreshold > 70{
+ if sec > compareThreshold {
+ totalmap[key] = sec
+ }
+ }else {
+ if sec > 70*0.01 {
+ totalmap[key] = sec
+ }
+ }
+
+ }
+
+ }
}
- fmt.Println()
- fmt.Println("======鍗庝附鐨勫垎鍓茬嚎============")
- fmt.Println()
+ fmt.Println(totalmap)
- firsttime := time.Now()
- Rscore := Cmap.Walk(Printest, teststring)
- fmt.Println(time.Since(firsttime))
- return Rscore
+ buf, err := json.Marshal(totalmap)
+ if err != nil {
+ fmt.Println("map to json error!", err)
+ return nil
+ }
+ return buf
}
-func Printest(ci, co string ) (float32){
+func Printest(ci []byte, co string ) (float32){
- ci_d, err := base64.StdEncoding.DecodeString(ci)
- if err != nil {
- fmt.Println("ci_d : error : ", err)
- return -1
- }
-
- co_d, err := base64.StdEncoding.DecodeString(co)
+ co_d, err := base64.StdEncoding.DecodeString(co)
if err != nil {
fmt.Println("co_d : error : ", err)
return -1
}
- sec := gosdk.FaceCompare(ci_d, co_d)
+ sec := gosdk.FaceCompare(ci, co_d)
return sec
}
--
Gitblit v1.8.0