quality.go 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. package front
  2. import (
  3. "go.mongodb.org/mongo-driver/bson/primitive"
  4. "log"
  5. qu "qfw/util"
  6. "qua"
  7. "time"
  8. u "util"
  9. )
  10. func (f *Front) QuaScoreData() {
  11. defer qu.Catch()
  12. coll_name := f.GetString("coll_name")
  13. field_tag := f.GetSlice("field_tag")
  14. rep := QuaFieldScore(field_tag, coll_name)
  15. f.ServeJson(map[string]interface{}{
  16. "rep": rep,
  17. })
  18. }
  19. func QuaFieldScore(field_tag []string, coll_name string) bool {
  20. if coll_name == "" || len(field_tag) <= 0 {
  21. return false
  22. }
  23. //查询标注表-临时测试-指定表
  24. start := int(time.Now().Unix())
  25. q := map[string]interface{}{}
  26. sess := u.Mgo.GetMgoConn()
  27. defer u.Mgo.DestoryMongoConn(sess)
  28. it := sess.DB(u.Mgo.DbName).C(coll_name).Find(&q).Sort("_id").Iter()
  29. updateFieldScore, total := [][]map[string]interface{}{}, 0
  30. for tmp := make(map[string]interface{}); it.Next(&tmp); total++ {
  31. if total%1000 == 0 {
  32. log.Println("当前数量:", total)
  33. }
  34. update_dict := calculateFieldScore(tmp, field_tag)
  35. updateFieldScore = append(updateFieldScore, []map[string]interface{}{
  36. map[string]interface{}{"_id": tmp["_id"]},
  37. update_dict,
  38. })
  39. if len(updateFieldScore) >= 200 {
  40. u.Mgo.UpSertBulk(coll_name, updateFieldScore...)
  41. updateFieldScore = [][]map[string]interface{}{}
  42. }
  43. tmp = make(map[string]interface{})
  44. }
  45. if len(updateFieldScore) > 0 {
  46. u.Mgo.UpSertBulk(coll_name, updateFieldScore...)
  47. }
  48. log.Printf("处理耗时:%d秒~数量:%d个\n", int(time.Now().Unix())-start, total)
  49. if total <= 0 {
  50. return false
  51. }
  52. return true
  53. }
  54. //计算字段分
  55. func calculateFieldScore(tmp map[string]interface{}, field_tag []string) map[string]interface{} {
  56. source := *qu.ObjToMap(tmp["field_source"])
  57. f_s := qua.FieldSourceScore(source) //打初始分
  58. update_dict := make(map[string]interface{}, 0)
  59. buyer_s := qua.BuyerFieldScore(tmp, f_s["buyer"])
  60. budget_s := qua.BudgetFieldScore(tmp, f_s["budget"])
  61. projectname_s := qua.ProjectnameFieldScore(tmp, f_s["projectname"])
  62. projectcode_s := qua.ProjectcodeFieldScore(tmp, f_s["projectcode"])
  63. update_dict["buyer"] = buyer_s
  64. update_dict["budget"] = budget_s
  65. update_dict["projectname"] = projectname_s
  66. update_dict["projectcode"] = projectcode_s
  67. subtype := qu.ObjToString(tmp["subtype"])
  68. if subtype == "中标" || subtype == "成交" || subtype == "合同" {
  69. s_winner_s := qua.WinnerFieldScore(tmp, f_s["s_winner"])
  70. update_dict["s_winner"] = s_winner_s
  71. bidamount_s := qua.BidamountFieldScore(tmp, f_s["bidamount"])
  72. update_dict["bidamount"] = bidamount_s
  73. }
  74. //综合比对是否正确 field_tag - 指定字段
  75. isUse, v_taginfo := true, make(map[string]interface{}, 0)
  76. b_isfield_tag := make(map[string]interface{}, 0)
  77. for _, key := range field_tag {
  78. v_taginfo[key] = int64(1)
  79. value := *qu.ObjToMap(update_dict[key])
  80. score := qu.Int64All(value["score"])
  81. if score < 99 {
  82. isUse = false //需要标注
  83. }
  84. }
  85. for k, v := range update_dict {
  86. data := *qu.ObjToMap(v)
  87. score := qu.Int64All(data["score"])
  88. if score < 99 {
  89. b_isfield_tag[k] = true
  90. } else {
  91. b_isfield_tag[k] = false
  92. }
  93. }
  94. b_istagging := !isUse
  95. //计算标的物-有效状态
  96. b_isprchasing := calculatePrchasinglist(tmp)
  97. return map[string]interface{}{
  98. "$set": map[string]interface{}{
  99. "v_fieldscore": update_dict,
  100. "v_taginfo": v_taginfo,
  101. "b_isfield_tag": b_isfield_tag,
  102. "b_istagging": b_istagging,
  103. "b_isprchasing": b_isprchasing,
  104. },
  105. }
  106. }
  107. //标的物-计算
  108. func calculatePrchasinglist(tmp map[string]interface{}) bool {
  109. b_ispurchasing := true //默认需要标注
  110. if purchasinglist, ok := tmp["purchasinglist"].([]interface{}); ok {
  111. if len(purchasinglist) <= 0 {
  112. return b_ispurchasing
  113. }
  114. isListUserArr := []bool{}
  115. for _, data := range purchasinglist {
  116. isUse := isUsePurchasing(*qu.ObjToMap(data))
  117. isListUserArr = append(isListUserArr, isUse)
  118. }
  119. b_ispurchasing = !isUseAllPurchasing(isListUserArr)
  120. return b_ispurchasing
  121. }
  122. if purchasinglistA, okA := tmp["purchasinglist"].(primitive.A); okA {
  123. if len(purchasinglistA) <= 0 {
  124. return b_ispurchasing
  125. }
  126. isListUserArr := []bool{}
  127. for _, data := range purchasinglistA {
  128. isUse := isUsePurchasing(*qu.ObjToMap(data))
  129. isListUserArr = append(isListUserArr, isUse)
  130. }
  131. b_ispurchasing = !isUseAllPurchasing(isListUserArr)
  132. }
  133. return b_ispurchasing
  134. }
  135. //判断各个标的物是否可用 默认不可用
  136. func isUsePurchasing(data map[string]interface{}) bool {
  137. isUse := false
  138. num := 1
  139. total_score := qu.Float64All(data["score"])
  140. if total_score <= float64(0) {
  141. return isUse
  142. }
  143. ner_data := *qu.ObjToMap(data["ner_data"])
  144. NerGoods := *qu.ObjToMap(ner_data["NerGoods"])
  145. for _, v := range NerGoods {
  146. num++
  147. total_score += qu.Float64All(v)
  148. }
  149. //计算总平均分输
  150. if total_score/float64(num) > float64(0.3) {
  151. isUse = true
  152. }
  153. return isUse
  154. }
  155. //是否整体可用 - 默认不可用
  156. func isUseAllPurchasing(isListUserArr []bool) bool {
  157. isUse := false
  158. total_num := len(isListUserArr)
  159. ok_num := 0
  160. for _, v := range isListUserArr {
  161. if v {
  162. ok_num++
  163. }
  164. }
  165. if ok_num == 0 {
  166. return isUse
  167. }
  168. correct := float64(ok_num) / float64(total_num)
  169. if total_num <= 2 {
  170. if correct >= float64(1) {
  171. isUse = true
  172. }
  173. } else if total_num > 2 && total_num <= 6 {
  174. if correct >= float64(0.6) {
  175. isUse = true
  176. }
  177. } else if total_num > 7 {
  178. if correct >= float64(0.5) {
  179. isUse = true
  180. }
  181. } else {
  182. }
  183. return isUse
  184. }