quality.go 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  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 := true
  76. b_isfield_tag := make(map[string]interface{}, 0)
  77. for _, key := range field_tag {
  78. value := *qu.ObjToMap(update_dict[key])
  79. score := qu.Int64All(value["score"])
  80. if score < 99 {
  81. isUse = false //需要标注
  82. }
  83. }
  84. for k, v := range update_dict {
  85. data := *qu.ObjToMap(v)
  86. score := qu.Int64All(data["score"])
  87. if score < 99 {
  88. b_isfield_tag[k] = true
  89. } else {
  90. b_isfield_tag[k] = false
  91. }
  92. }
  93. b_istagging := !isUse
  94. ckdata := 0
  95. if isUse { //达标数据ck_data默认未2,未达标为0
  96. ckdata = 2
  97. }
  98. //计算标的物-有效状态
  99. b_isprchasing := calculatePrchasinglist(tmp)
  100. return map[string]interface{}{
  101. "$set": map[string]interface{}{
  102. "v_fieldscore": update_dict,
  103. "b_isfield_tag": b_isfield_tag,
  104. "b_istagging": b_istagging,
  105. "b_isprchasing": b_isprchasing,
  106. "i_ckdata": ckdata,
  107. "b_istag": !b_istagging,
  108. "b_isgivegroup": !b_istagging,
  109. "b_isgiveuser": !b_istagging,
  110. },
  111. }
  112. }
  113. //标的物-计算
  114. func calculatePrchasinglist(tmp map[string]interface{}) bool {
  115. b_ispurchasing := true //默认需要标注
  116. if purchasinglist, ok := tmp["purchasinglist"].([]interface{}); ok {
  117. if len(purchasinglist) <= 0 {
  118. return b_ispurchasing
  119. }
  120. isListUserArr := []bool{}
  121. for _, data := range purchasinglist {
  122. isUse := isUsePurchasing(*qu.ObjToMap(data))
  123. isListUserArr = append(isListUserArr, isUse)
  124. }
  125. b_ispurchasing = !isUseAllPurchasing(isListUserArr)
  126. return b_ispurchasing
  127. }
  128. if purchasinglistA, okA := tmp["purchasinglist"].(primitive.A); okA {
  129. if len(purchasinglistA) <= 0 {
  130. return b_ispurchasing
  131. }
  132. isListUserArr := []bool{}
  133. for _, data := range purchasinglistA {
  134. isUse := isUsePurchasing(*qu.ObjToMap(data))
  135. isListUserArr = append(isListUserArr, isUse)
  136. }
  137. b_ispurchasing = !isUseAllPurchasing(isListUserArr)
  138. }
  139. return b_ispurchasing
  140. }
  141. //判断各个标的物是否可用 默认不可用
  142. func isUsePurchasing(data map[string]interface{}) bool {
  143. isUse := false
  144. num := 1
  145. total_score := qu.Float64All(data["score"])
  146. if total_score <= float64(0) {
  147. return isUse
  148. }
  149. ner_data := *qu.ObjToMap(data["ner_data"])
  150. NerGoods := *qu.ObjToMap(ner_data["NerGoods"])
  151. for _, v := range NerGoods {
  152. num++
  153. total_score += qu.Float64All(v)
  154. }
  155. //计算总平均分输
  156. if total_score/float64(num) > float64(0.3) {
  157. isUse = true
  158. }
  159. return isUse
  160. }
  161. //是否整体可用 - 默认不可用
  162. func isUseAllPurchasing(isListUserArr []bool) bool {
  163. isUse := false
  164. total_num := len(isListUserArr)
  165. ok_num := 0
  166. for _, v := range isListUserArr {
  167. if v {
  168. ok_num++
  169. }
  170. }
  171. if ok_num == 0 {
  172. return isUse
  173. }
  174. correct := float64(ok_num) / float64(total_num)
  175. if total_num <= 2 {
  176. if correct >= float64(1) {
  177. isUse = true
  178. }
  179. } else if total_num > 2 && total_num <= 6 {
  180. if correct >= float64(0.6) {
  181. isUse = true
  182. }
  183. } else if total_num > 7 {
  184. if correct >= float64(0.5) {
  185. isUse = true
  186. }
  187. } else {
  188. }
  189. return isUse
  190. }