package compare
|
|
import (
|
"fmt"
|
"sdkCompare/util"
|
"strconv"
|
|
"sdkCompare/cache"
|
|
"basic.com/pubsub/protomsg.git"
|
"basic.com/valib/logger.git"
|
"github.com/golang/protobuf/proto"
|
)
|
|
const thresholdLimit = float32(30)
|
|
func GetComparePersonBaseInfo(args protomsg.CompareArgs) []byte {
|
if args.FaceFeature == nil {
|
return nil
|
}
|
|
floatFeat := util.ByteSlice2float32Slice(args.FaceFeature)
|
|
//指定最低分
|
baseScore := thresholdLimit
|
if args.CompareThreshold > thresholdLimit {
|
baseScore = args.CompareThreshold
|
}
|
|
if args.IsCompareAll {
|
baseScore = 0
|
}
|
|
var scResult protomsg.SdkCompareResult
|
|
var walkedArea = make(map[string]struct{}, 0)
|
// 优先比对传入的小区id
|
if args.TreeNodes != nil && len(args.TreeNodes) > 0 {
|
for _, id := range args.TreeNodes {
|
if _, ok := cache.CacheMap.Area[id]; ok {
|
targets := cache.CacheMap.Area[id].Walk(DoSdkCompare, floatFeat, baseScore)
|
if len(targets) > 0 {
|
scResult.CompareResult = append(scResult.CompareResult, targets...)
|
}
|
|
walkedArea[id] = struct{}{}
|
}
|
}
|
|
if len(scResult.CompareResult) > 0 {
|
goto done
|
}
|
}
|
|
// 比对以外的小区
|
if !args.IsCompareAll && len(args.TreeNodes) > 0 {
|
baseScore += 20
|
}
|
|
for key, val := range cache.CacheMap.Area {
|
if _, ok := walkedArea[key]; ok {
|
continue
|
}
|
|
targets := val.Walk(DoSdkCompare, floatFeat, baseScore)
|
if len(targets) > 0 {
|
scResult.CompareResult = append(scResult.CompareResult, targets...)
|
// todo 添加小区外的关联关系, 下次优先比对
|
}
|
}
|
|
done:
|
logger.Debugf("比对结果 %d条, %+v", len(scResult.CompareResult), scResult.CompareResult)
|
if len(scResult.CompareResult) > 0 {
|
logger.Debugf("比对结果%+v", scResult.CompareResult)
|
}
|
|
buf, err := proto.Marshal(&scResult)
|
if err != nil {
|
logger.Error("scResult Marshal error!", err)
|
return nil
|
}
|
|
return buf
|
}
|
|
func DoSdkCompare(ci, co []float32) float32 {
|
sec := DirectCompare(ci, co)
|
//logger.Debug("比对得分为:", sec)
|
|
sec = ParseScore(sec)
|
return sec
|
}
|
|
func ParseScore(compareScore float32) float32 {
|
if compareScore <= 1 {
|
compareScore = compareScore * 100
|
}
|
if compareScore == 100 {
|
return 100
|
}
|
f, _ := strconv.ParseFloat(fmt.Sprintf("%2.2f", compareScore), 32)
|
|
return float32(f)
|
}
|