From 6a413e1d7d485f506e81c669bc692868c29cefb9 Mon Sep 17 00:00:00 2001
From: sunty <1172534965@qq.com>
Date: 星期四, 18 七月 2019 17:37:25 +0800
Subject: [PATCH] fix sdkcompare

---
 dbpersoninfo.go |  128 ++++++++++++++++++++++++++++--------------
 1 files changed, 85 insertions(+), 43 deletions(-)

diff --git a/dbpersoninfo.go b/dbpersoninfo.go
index b42ab0d..a16d34c 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,87 +18,128 @@
 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 float32) []byte {
 
-func Getdbpersonmsg(teststring string, IsCompare bool) ([]byte) {
+    totalmap := make(map[string]float32)
 
-    var binfos protomsg.Binfos
-
-    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 > 50*0.01 {
+					fmt.Println("map涓�",totalmap[key],sec)
+                    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 > 50*0.01{
+                    if sec > compareThreshold {
+                    	fmt.Println("map涓�",totalmap[key],sec)
+                        totalmap[key] = sec
+                    }
+                }else {
+                    if sec > 50*0.01 {
+						fmt.Println("map涓�",totalmap[key],sec)
+                        totalmap[key] = sec
+                    }
+                }
+
+            }
+
+        }
     }
 
-    fmt.Println()
-    fmt.Println("======鍗庝附鐨勫垎鍓茬嚎============")
-    fmt.Println()
+    fmt.Println(totalmap)
 
-    firsttime := time.Now()
-    Rscore := Cmap.Walk(Printest, teststring)
-    
-    binfos.Infos = append(binfos.Infos, Rscore...)
-    binfosbytes, err := binfos.Marshal()
-    if err != nil  {
-        fmt.Println(err)
-        return nil 
+    buf, err := json.Marshal(totalmap)
+    if err != nil {
+        fmt.Println("map to json error!", err)
+        return nil
     }
-    fmt.Println(time.Since(firsttime))
-    return binfosbytes
+    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([]byte(ci), co_d)
+    sec := gosdk.FaceCompare(ci, co_d)
+    fmt.Println("姣斿寰楀垎涓猴細",sec)
     return sec
 }

--
Gitblit v1.8.0