scoreLogic.go 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. package main
  2. import (
  3. qu "qfw/util"
  4. "strings"
  5. "unicode/utf8"
  6. )
  7. var element_reason map[string]interface{}
  8. func dealWithElementRate(tmp map[string]interface{}) (int,int,int,map[string]interface{}) {
  9. //score_standard 打分标准 要素打分 - 需慎重
  10. element_reason = map[string]interface{}{}
  11. m,n,z :=0,0,0
  12. core_value,other_value,deduct_value :="","",""
  13. //第一次-配置验证
  14. coreArr,otherArr:=filterConfiguration(tmp)
  15. //细节过滤-验证
  16. new_coreArr,new_otherArr:=[]string{},[]string{}
  17. for _,v:=range coreArr{
  18. if v=="projectname"||v=="buyer"||v=="winner" {
  19. if isChinese(qu.ObjToString(tmp[v])) {
  20. new_coreArr = append(new_coreArr,v)
  21. }
  22. }else {
  23. new_coreArr = append(new_coreArr,v)
  24. }
  25. }
  26. for _,v:=range otherArr{
  27. if v=="agencyperson"||v=="buyerperson"||v=="winnerperson" {
  28. if isChinese(qu.ObjToString(tmp[v])) {
  29. new_otherArr = append(new_otherArr,v)
  30. }
  31. }else if v=="agencytel"||v=="buyertel"||v=="winnertel" {
  32. if !isChinese(qu.ObjToString(tmp[v])) {
  33. if isTelephone(qu.ObjToString(tmp[v])) {
  34. new_otherArr = append(new_otherArr,v)
  35. }
  36. }
  37. }else if v=="bidopentime"||v=="signaturedate" {
  38. if isTimestamp(qu.Int64All(tmp[v])) {
  39. new_otherArr = append(new_otherArr,v)
  40. }
  41. }else if v=="bidopenaddress"||v=="winneraddr"||v=="agencyaddr"||
  42. v=="buyeraddr" {
  43. if isPlaceAddr(qu.ObjToString(tmp[v])) {
  44. new_otherArr = append(new_otherArr,v)
  45. }
  46. }else if v=="projectaddr" {
  47. if isChinese(qu.ObjToString(tmp[v])) {
  48. new_otherArr = append(new_otherArr,v)
  49. }
  50. }else {
  51. new_otherArr = append(new_otherArr,v)
  52. }
  53. }
  54. core_value = strings.Join(new_coreArr, ",")
  55. m = len(new_coreArr)
  56. other_value = strings.Join(new_otherArr, ",")
  57. n = len(new_otherArr)
  58. //扣分项
  59. for _,v:=range deduct_element{
  60. if qu.ObjToString(tmp[v])=="" {
  61. z--
  62. if deduct_value == "" {
  63. deduct_value = v
  64. }else {
  65. deduct_value = deduct_value+","+v
  66. }
  67. }
  68. }
  69. total_s,core_s,other_s:=calculateScore(m,n,z)
  70. return total_s,core_s,other_s,map[string]interface{}{
  71. "coreElement":map[string]interface{}{
  72. "key":core_value,
  73. },
  74. "otherElement":map[string]interface{}{
  75. "key":other_value,
  76. },
  77. "deductElement":map[string]interface{}{
  78. "key":deduct_value,
  79. },
  80. }
  81. }
  82. func filterConfiguration(tmp map[string]interface{})([]string,[]string) {
  83. coreArr ,otherArr:= []string{},[]string{}
  84. //核心要素 int - 时间- float-金额区间 string-字符串长度
  85. for _,v:=range core_element{
  86. for k1,v1:=range v{
  87. if tmp[k1]==nil {
  88. continue
  89. }
  90. dict :=*qu.ObjToMap(v1)
  91. element_type := qu.ObjToString(dict["type"])
  92. if element_type=="int" {
  93. min:=qu.IntAll(dict["min"])
  94. if qu.IntAll(tmp[k1])>min {
  95. coreArr = append(coreArr,k1)
  96. }
  97. }else if element_type=="float" {
  98. min:=qu.Float64All(dict["min"])
  99. max:=qu.Float64All(dict["max"])
  100. if qu.Float64All(tmp[k1])>min && qu.Float64All(tmp[k1])<max{
  101. coreArr = append(coreArr,k1)
  102. }
  103. }else if element_type=="string" {
  104. min:=qu.IntAll(dict["min"])
  105. max:=qu.IntAll(dict["max"])
  106. if utf8.RuneCountInString(qu.ObjToString(tmp[k1]))>min &&
  107. utf8.RuneCountInString(qu.ObjToString(tmp[k1]))<max{
  108. coreArr = append(coreArr,k1)
  109. }
  110. }else {
  111. }
  112. }
  113. }
  114. for _,v:=range other_element{
  115. for k1,v1:=range v{
  116. if tmp[k1]==nil {
  117. continue
  118. }
  119. dict :=*qu.ObjToMap(v1)
  120. element_type := qu.ObjToString(dict["type"])
  121. if element_type=="int" {
  122. min:=qu.IntAll(dict["min"])
  123. if qu.IntAll(tmp[k1])>min {
  124. otherArr = append(otherArr,k1)
  125. }
  126. }else if element_type=="float" {
  127. min:=qu.Float64All(dict["min"])
  128. max:=qu.Float64All(dict["max"])
  129. if qu.Float64All(tmp[k1])>min && qu.Float64All(tmp[k1])<max{
  130. otherArr = append(otherArr,k1)
  131. }
  132. }else if element_type=="string" {
  133. min:=qu.IntAll(dict["min"])
  134. max:=qu.IntAll(dict["max"])
  135. if utf8.RuneCountInString(qu.ObjToString(tmp[k1]))>min &&
  136. utf8.RuneCountInString(qu.ObjToString(tmp[k1]))<max{
  137. otherArr = append(otherArr,k1)
  138. }
  139. }else {
  140. }
  141. }
  142. }
  143. return coreArr,otherArr
  144. }
  145. func calculateScore(core_num int,other_num int,deduct_num int) (int,int,int) {
  146. m ,core_s:=core_each*core_num,core_each*core_num
  147. if m>core_max {
  148. m = core_max
  149. }
  150. n ,other_s:=other_each*other_num,other_each*other_num
  151. if n > other_max {
  152. n = other_max
  153. }
  154. z := deduct_each*deduct_num
  155. t :=m+n+z
  156. if t > total_score {
  157. t=total_score
  158. }
  159. return t,core_s,other_s
  160. }