package main import ( qu "qfw/util" ) var element_reason map[string]interface{} func dealWithElementRate(tmp map[string]interface{}) (int,map[string]interface{}) { //score_standard 打分标准 element_reason = map[string]interface{}{} m,n,z :=0,0,0 core_value,other_value,deduct_value :="","","" //要素打分 - 需慎重 core_element other_element deduct_element for _,v:=range core_element{ for k1,v1:=range v{ if tmp[k1]==nil { continue } dict :=*qu.ObjToMap(v1) element_type := qu.ObjToString(dict["type"]) if element_type=="int" { temp_num:=qu.IntAll(dict["large"]) if qu.IntAll(tmp[k1])>temp_num { m++ core_value = core_value+k1+"-" } }else if element_type=="float" { temp_num:=qu.Float64All(dict["large"]) if qu.Float64All(tmp[k1])>temp_num { m++ core_value = core_value+k1+"-" } }else if element_type=="string" { temp_length:=qu.IntAll(dict["length"]) if len(qu.ObjToString(tmp[k1]))>temp_length { m++ core_value = core_value+k1+"-" } }else { } } } for _,v:=range other_element{ for k1,v1:=range v{ if tmp[k1]==nil { continue } dict :=*qu.ObjToMap(v1) element_type := qu.ObjToString(dict["type"]) if element_type=="int" { temp_num:=qu.IntAll(dict["large"]) if qu.IntAll(tmp[k1])>temp_num { n++ other_value = other_value+k1+"-" } }else if element_type=="float" { temp_num:=qu.Float64All(dict["large"]) if qu.Float64All(tmp[k1])>temp_num { n++ other_value = other_value+k1+"-" } }else if element_type=="string" { temp_length:=qu.IntAll(dict["length"]) if len(qu.ObjToString(tmp[k1]))>temp_length { n++ other_value = other_value+k1+"-" } }else { } } } for _,v:=range deduct_element{ if qu.ObjToString(tmp[v])=="" { z-- deduct_value = deduct_value+v+"-" } } total,core_s,other_s,deduct_s:=calculateScore(m,n,z) return total,map[string]interface{}{ "coreElement":map[string]interface{}{ "key":core_value, "core_score":core_s, }, "otherElement":map[string]interface{}{ "key":other_value, "other_score":other_s, }, "deductElement":map[string]interface{}{ "key":deduct_value, "deduct_score":deduct_s, }, } } func calculateScore(core_num int,other_num int,deduct_num int) (int,int,int,int) { m :=core_each*core_num if m>core_max { m = core_max } n :=other_each*other_num if n > other_max { n = other_max } z := deduct_each*deduct_num t :=m+n+z if t > total_score { t=total_score } return t,m,n,z }