scoreLogic.go 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. package main
  2. import (
  3. qu "qfw/util"
  4. )
  5. var element_reason map[string]interface{}
  6. func dealWithElementRate(tmp map[string]interface{}) (int,map[string]interface{}) {
  7. //score_standard 打分标准
  8. element_reason = map[string]interface{}{}
  9. m,n,z :=0,0,0
  10. core_value,other_value,deduct_value :="","",""
  11. //要素打分 - 需慎重 core_element other_element deduct_element
  12. for _,v:=range core_element{
  13. for k1,v1:=range v{
  14. if tmp[k1]==nil {
  15. continue
  16. }
  17. dict :=*qu.ObjToMap(v1)
  18. element_type := qu.ObjToString(dict["type"])
  19. if element_type=="int" {
  20. temp_num:=qu.IntAll(dict["large"])
  21. if qu.IntAll(tmp[k1])>temp_num {
  22. m++
  23. core_value = core_value+k1+"-"
  24. }
  25. }else if element_type=="float" {
  26. temp_num:=qu.Float64All(dict["large"])
  27. if qu.Float64All(tmp[k1])>temp_num {
  28. m++
  29. core_value = core_value+k1+"-"
  30. }
  31. }else if element_type=="string" {
  32. temp_length:=qu.IntAll(dict["length"])
  33. if len(qu.ObjToString(tmp[k1]))>temp_length {
  34. m++
  35. core_value = core_value+k1+"-"
  36. }
  37. }else {
  38. }
  39. }
  40. }
  41. for _,v:=range other_element{
  42. for k1,v1:=range v{
  43. if tmp[k1]==nil {
  44. continue
  45. }
  46. dict :=*qu.ObjToMap(v1)
  47. element_type := qu.ObjToString(dict["type"])
  48. if element_type=="int" {
  49. temp_num:=qu.IntAll(dict["large"])
  50. if qu.IntAll(tmp[k1])>temp_num {
  51. n++
  52. other_value = other_value+k1+"-"
  53. }
  54. }else if element_type=="float" {
  55. temp_num:=qu.Float64All(dict["large"])
  56. if qu.Float64All(tmp[k1])>temp_num {
  57. n++
  58. other_value = other_value+k1+"-"
  59. }
  60. }else if element_type=="string" {
  61. temp_length:=qu.IntAll(dict["length"])
  62. if len(qu.ObjToString(tmp[k1]))>temp_length {
  63. n++
  64. other_value = other_value+k1+"-"
  65. }
  66. }else {
  67. }
  68. }
  69. }
  70. for _,v:=range deduct_element{
  71. if qu.ObjToString(tmp[v])=="" {
  72. z--
  73. deduct_value = deduct_value+v+"-"
  74. }
  75. }
  76. total,core_s,other_s,deduct_s:=calculateScore(m,n,z)
  77. return total,map[string]interface{}{
  78. "coreElement":map[string]interface{}{
  79. "key":core_value,
  80. "core_score":core_s,
  81. },
  82. "otherElement":map[string]interface{}{
  83. "key":other_value,
  84. "other_score":other_s,
  85. },
  86. "deductElement":map[string]interface{}{
  87. "key":deduct_value,
  88. "deduct_score":deduct_s,
  89. },
  90. }
  91. }
  92. func calculateScore(core_num int,other_num int,deduct_num int) (int,int,int,int) {
  93. m :=core_each*core_num
  94. if m>core_max {
  95. m = core_max
  96. }
  97. n :=other_each*other_num
  98. if n > other_max {
  99. n = other_max
  100. }
  101. z := deduct_each*deduct_num
  102. t :=m+n+z
  103. if t > total_score {
  104. t=total_score
  105. }
  106. return t,m,n,z
  107. }