554325746@qq.com
2019-07-12 e73efb4afc3bc91ddc49ac63f0f3db463d1f8cc1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
package cache
 
import (
    "flag"
    "fmt"
    "time"
    "sync"
    "encoding/base64"
 
    "encoding/json"
 
    "basic.com/pubsub/cache.git/esutil"
    "basic.com/pubsub/cache.git/shardmap"
 
    "basic.com/valib/gosdk.git"
)
 
var querynum = flag.Int("querynum", 10, "the query number from database")
var threadnum = flag.Int("threadnum",32, "the number of thread to deal data.")
 
type CmapItem struct {
    sync.Mutex
    Cam map[string]*shardmap.ShardMap
}
 
var Cmap *CmapItem
 
func Init(){
    flag.Parse()
    gosdk.InitFaceExtractor(16, 0)
 
    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) 
            if err != nil {
                fmt.Println(err)
                return
            }
 
            Cmap.Lock()           
 
            for _, value := range escache{
                if _, ok :=Cmap.Cam[value.Tableid]; !ok {
                   Cmap.Cam[value.Tableid]=shardmap.New(uint8(*threadnum))        
                }
                
                Cmap.Cam[value.Tableid].Set(value.Id,value.FaceFeature) 
            }
 
            Cmap.Unlock()
 
        }(j)
    }
    wg.Wait()
    fmt.Println("time of get data from es.", time.Since(temptime))
    fmt.Println()
}
 
func Getdbpersonmsg(tableid string, teststring []byte, IsCompare bool) ([]byte) {
 
    totalmap := make(map[string]float32)
 
    if !IsCompare {
        return nil
    }
 
    if teststring == nil {
        return nil 
    }
 
    if tableid == "" {
        for id, val := range Cmap.Cam{
            fmt.Println("the id is: ", id)
            tmpmap := val.Walk(Printest, teststring)
            for key, sec := range tmpmap {
                totalmap[key] = sec
            }
        }
    }else{
       for id, value := range Cmap.Cam{
            if id == tableid{
                fmt.Println("the id is: ", id)
                tmpmap :=value.Walk(Printest, teststring)
                for key, sec := range tmpmap {
                    totalmap[key]= sec
                }
                break
            }
       }
    }
 
 
    firsttime := time.Now()
    fmt.Println(time.Since(firsttime))
 
    buf, err := json.Marshal(totalmap)
    if err != nil {
        fmt.Println("map to json error!", err)
         return nil  
    }
    return  buf 
}
 
func Printest(ci []byte, co string ) (float32){
 
   co_d, err := base64.StdEncoding.DecodeString(co)
    if err != nil {
        fmt.Println("co_d : error : ", err)
        return -1
    }
 
    sec := gosdk.FaceCompare(ci, co_d)
    return sec
}