maxiaoshan 3 years ago
parent
commit
25bfb75229
5 changed files with 103 additions and 121 deletions
  1. 2 2
      src/config.json
  2. 25 9
      src/front/project.go
  3. 20 33
      src/front/quality.go
  4. 55 76
      src/qua/method.go
  5. 1 1
      src/web/templates/project/project_clear.html

+ 2 - 2
src/config.json

@@ -1,8 +1,8 @@
 {
     "port": "7000",
-    "mgodb": "127.0.0.1:27017",
+    "mgodb": "192.168.3.207:27092",
     "dbsize": 10,
-    "dbname": "zhengkun",
+    "dbname": "datavalidation",
     "alltocoll": "marked",
     "bidding":{
         "addr":"192.168.3.207:27092",

+ 25 - 9
src/front/project.go

@@ -221,7 +221,16 @@ func (f *Front) ProjectTaskList() {
 		project, _ := util.Mgo.FindById(util.PROJECTCOLLNAME, projectid, map[string]interface{}{"s_status": 1, "s_sourceinfo": 1})
 		if project != nil && len(*project) > 0 {
 			if status := qu.ObjToString((*project)["s_status"]); status == "未开始" {
-				//TODO:调用数据质量评估接口
+				var fieldsArr []string
+				fields := (*project)["v_fields"].([]interface{})
+				for _, fieldsTmp := range fields {
+					fieldsMap := fieldsTmp.(map[string]interface{})
+					for f, _ := range fieldsMap {
+						fieldsArr = append(fieldsArr, f)
+					}
+				}
+				sourceinfo := qu.ObjToString((*project)["s_sourceinfo"])
+				QuaFieldScore(fieldsArr, sourceinfo) //调用数据质量评估接口
 				//点击清洗更新项目状态为进行中
 				b := util.Mgo.UpdateById(util.PROJECTCOLLNAME, projectid, map[string]interface{}{"$set": map[string]interface{}{"s_status": "进行中", "i_starttime": time.Now().Unix()}})
 				qu.Debug("Update Porject:"+projectid+"	Status Success:", b)
@@ -290,7 +299,7 @@ func (f *Front) ProjectTaskSave() {
 		qu.Debug("GroupInfo Unmarshal Failed:", err)
 		msg = "用户组信息解析失败"
 	} else {
-		qu.Debug("用户组信息:", groupArr)
+		qu.Debug("用户组信息:", groupArr, stype)
 		if stype == "notag" { //如果分发的是达标数据且进行了初步质检,将没有质检记录的字段从v_taginfo标注记录中删除
 			DeleleDataTagInfo(sourceinfo)
 		}
@@ -561,18 +570,25 @@ func DeleleDataTagInfo(sourceinfo string) {
 			update = append(update, map[string]interface{}{"_id": tmp["_id"]})
 			tagInfo, _ := tmp["v_taginfo"].(map[string]interface{})
 			checkInfo, _ := tmp["v_check"].(map[string]interface{})
-			if len(tagInfo) == 0 || len(checkInfo) == 0 {
-				return
+			id := mongodb.BsonIdToSId(tmp["_id"])
+			if id == "60b99c2d72c25c51c492af6a" {
+				qu.Debug(tagInfo, checkInfo)
+			}
+			set := map[string]interface{}{
+				"b_cleartag": true,
 			}
-			for f, _ := range tagInfo {
-				if checkInfo[f] == nil {
-					delete(tagInfo, f)
+			if len(tagInfo) != 0 && len(checkInfo) != 0 {
+				for f, _ := range tagInfo {
+					if checkInfo[f] == nil {
+						delete(tagInfo, f)
+					}
 				}
+				set["v_taginfo"] = tagInfo
 			}
+
 			update = append(update, map[string]interface{}{
 				"$set": map[string]interface{}{
-					"v_taginfo":  tagInfo,
-					"b_cleartag": true,
+					"v_taginfo": tagInfo,
 				},
 			})
 			lock.Lock()

+ 20 - 33
src/front/quality.go

@@ -8,19 +8,8 @@ import (
 	u "util"
 )
 
-func (f *Front) QuaScoreData() {
-	defer qu.Catch()
-	coll_name := f.GetString("coll_name")
-	field_tag := f.GetSlice("field_tag")
-	rep := QuaFieldScore(field_tag,coll_name)
-	f.ServeJson(map[string]interface{}{
-		"rep": rep,
-	})
-}
-
-
-func QuaFieldScore(field_tag []string,coll_name string) bool {
-	if coll_name=="" || len(field_tag)<=0 {
+func QuaFieldScore(field_tag []string, coll_name string) bool {
+	if coll_name == "" || len(field_tag) <= 0 {
 		return false
 	}
 	//查询标注表-临时测试-指定表
@@ -29,12 +18,12 @@ func QuaFieldScore(field_tag []string,coll_name string) bool {
 	sess := u.Mgo.GetMgoConn()
 	defer u.Mgo.DestoryMongoConn(sess)
 	it := sess.DB(u.Mgo.DbName).C(coll_name).Find(&q).Iter()
-	updateFieldScore,total := [][]map[string]interface{}{},0
+	updateFieldScore, total := [][]map[string]interface{}{}, 0
 	for tmp := make(map[string]interface{}); it.Next(&tmp); total++ {
 		if total%1000 == 0 {
 			log.Println("当前数量:", total)
 		}
-		update_dict := calculateFieldScore(tmp,field_tag)
+		update_dict := calculateFieldScore(tmp, field_tag)
 		updateFieldScore = append(updateFieldScore, []map[string]interface{}{
 			map[string]interface{}{"_id": tmp["_id"]},
 			update_dict,
@@ -45,22 +34,22 @@ func QuaFieldScore(field_tag []string,coll_name string) bool {
 		}
 		tmp = make(map[string]interface{})
 	}
-	if len(updateFieldScore) >0 {
+	if len(updateFieldScore) > 0 {
 		u.Mgo.UpSertBulk(coll_name, updateFieldScore...)
 	}
-	log.Printf("处理耗时:%d秒~数量:%d个\n", int(time.Now().Unix())-start,total)
+	log.Printf("处理耗时:%d秒~数量:%d个\n", int(time.Now().Unix())-start, total)
 	return true
 }
 
 //计算字段分
-func calculateFieldScore(tmp map[string]interface{},field_tag []string) (map[string]interface{}) {
+func calculateFieldScore(tmp map[string]interface{}, field_tag []string) map[string]interface{} {
 	source := *qu.ObjToMap(tmp["field_source"])
 	f_s := qua.FieldSourceScore(source) //打初始分
-	update_dict := make(map[string]interface{},0)
-	buyer_s := qua.BuyerFieldScore(tmp,f_s["buyer"])
-	budget_s := qua.BudgetFieldScore(tmp,f_s["budget"])
-	projectname_s := qua.ProjectnameFieldScore(tmp,f_s["projectname"])
-	projectcode_s := qua.ProjectcodeFieldScore(tmp,f_s["projectcode"])
+	update_dict := make(map[string]interface{}, 0)
+	buyer_s := qua.BuyerFieldScore(tmp, f_s["buyer"])
+	budget_s := qua.BudgetFieldScore(tmp, f_s["budget"])
+	projectname_s := qua.ProjectnameFieldScore(tmp, f_s["projectname"])
+	projectcode_s := qua.ProjectcodeFieldScore(tmp, f_s["projectcode"])
 
 	update_dict["buyer"] = buyer_s
 	update_dict["budget"] = budget_s
@@ -68,17 +57,16 @@ func calculateFieldScore(tmp map[string]interface{},field_tag []string) (map[str
 	update_dict["projectcode"] = projectcode_s
 
 	subtype := qu.ObjToString(tmp["subtype"])
-	if subtype=="中标"||subtype=="成交"||subtype=="合同" {
-		s_winner_s := qua.WinnerFieldScore(tmp,f_s["s_winner"])
+	if subtype == "中标" || subtype == "成交" || subtype == "合同" {
+		s_winner_s := qua.WinnerFieldScore(tmp, f_s["s_winner"])
 		update_dict["s_winner"] = s_winner_s
-		bidamount_s := qua.BidamountFieldScore(tmp,f_s["bidamount"])
+		bidamount_s := qua.BidamountFieldScore(tmp, f_s["bidamount"])
 		update_dict["bidamount"] = bidamount_s
 	}
 
-
 	//综合比对是否正确 field_tag
-	isUse ,v_taginfo:= true,make(map[string]interface{},0)
-	for _,key :=range field_tag{
+	isUse, v_taginfo := true, make(map[string]interface{}, 0)
+	for _, key := range field_tag {
 		v_taginfo[key] = int64(1)
 		value := *qu.ObjToMap(update_dict[key])
 		score := qu.Int64All(value["score"])
@@ -92,9 +80,8 @@ func calculateFieldScore(tmp map[string]interface{},field_tag []string) (map[str
 	return map[string]interface{}{
 		"$set": map[string]interface{}{
 			"v_fieldscore": update_dict,
-			"b_cleartag" :false,
-			"b_istagging":b_istagging,
-			"v_taginfo" :v_taginfo,
+			"b_istagging":  b_istagging,
+			"v_taginfo":    v_taginfo,
 		},
 	}
-}
+}

+ 55 - 76
src/qua/method.go

@@ -10,7 +10,6 @@ import (
 	u "util"
 )
 
-
 //单位
 var specHeadReg *regexp.Regexp = regexp.MustCompile("^([a-zA-Z]{1,2}[\u4e00-\u9fa5]{6,}|某部|州|自治区|自治州|街道|名称|省|市|县|区|业绩|资格|中标|项目|预算单位)")
 var unHanHeadReg *regexp.Regexp = regexp.MustCompile("^([\u4e00-\u9fa5])")
@@ -18,46 +17,42 @@ var unConReg *regexp.Regexp = regexp.MustCompile("(园|政府|集团|公司|有
 var unEndReg *regexp.Regexp = regexp.MustCompile("^.*(公司|学(校)?|博物馆|联合社|合作社|监狱|办公厅|电视台|集团|机构|企业|办公室|委员会|实验室|联社|厂|场|院|所|店|小|台|中心|局|站|城|馆|厅|处|行|科|部|队|联合(会|体)|工作室)$")
 var unenableReg1 *regexp.Regexp = regexp.MustCompile("^([\u4e00-\u9fa5]{1,2}(责任|有限|有限股份|有限责任|实业)公司|.*(某部|先生|女士|小姐)|工程技术处)$")
 var unenableReg2 *regexp.Regexp = regexp.MustCompile("(\\?|?|单位|#|xxxx|\\*\\*|%|万元|设计企业|免费|代表|代码标识|盖电子|测试测试|删除|错误|吊销|注销|发起人|待清理|&#|护照号|身份证号|\" +\n\t\"法人|&nbsp|国家拨入|借款|积累资金|认股人|--|、|&|`|美元)")
-//分词
-var GSE *gse.Segmenter  = &gse.Segmenter{}
 
+//分词
+var GSE *gse.Segmenter = &gse.Segmenter{}
 
 //编号
 var codeUnConReg *regexp.Regexp = regexp.MustCompile("(null|勘察|测试|设计|设备|项目|标段|工程|监理|范围|分包|月|日|天)")
 var codeUnLenReg *regexp.Regexp = regexp.MustCompile("([\u4e00-\u9fa5]{9,})")
 
-
-
-
 var classMoneyScope map[string]map[string]interface{}
 
-
-func init()  {
+func init() {
 	GSE.LoadDict("./web/qua_res/dictionary.txt")
 	//t>d>p
 	classMoneyScope = map[string]map[string]interface{}{
-		"建筑工程": {"min":10000,"max":10000000000},
-		"行政办公": {"min":100,"max":100000000},
-		"医疗卫生": {"min":1000,"max":100000000},
-		"服务采购": {"min":10,"max":100000000},
-		"机械设备": {"min":1000,"max":1000000000},
-		"水利水电": {"min":1000,"max":1000000000},
-		"能源化工": {"min":1000,"max":1000000000},
-		"弱电安防": {"min":1000,"max":1000000000},
-		"信息技术": {"min":100,"max":100000000},
-		"交通工程": {"min":1000,"max":10000000000},
-		"市政设施": {"min":1000,"max":10000000000},
-		"农林牧渔": {"min":100,"max":10000000},
+		"建筑工程": {"min": 10000, "max": 10000000000},
+		"行政办公": {"min": 100, "max": 100000000},
+		"医疗卫生": {"min": 1000, "max": 100000000},
+		"服务采购": {"min": 10, "max": 100000000},
+		"机械设备": {"min": 1000, "max": 1000000000},
+		"水利水电": {"min": 1000, "max": 1000000000},
+		"能源化工": {"min": 1000, "max": 1000000000},
+		"弱电安防": {"min": 1000, "max": 1000000000},
+		"信息技术": {"min": 100, "max": 100000000},
+		"交通工程": {"min": 1000, "max": 10000000000},
+		"市政设施": {"min": 1000, "max": 10000000000},
+		"农林牧渔": {"min": 100, "max": 10000000},
 	}
 }
 
 //行业金额校验
-func checkingClassMoney(money float64,class string) bool  {
-	data :=classMoneyScope[class]
-	if data!=nil {
+func checkingClassMoney(money float64, class string) bool {
+	data := classMoneyScope[class]
+	if data != nil {
 		min := qu.Float64All(data["min"])
 		max := qu.Float64All(data["max"])
-		if money>min && money<max {
+		if money > min && money < max {
 			return true
 		}
 	}
@@ -65,19 +60,20 @@ func checkingClassMoney(money float64,class string) bool  {
 }
 
 //企业库检测
-func qyNameIsExistsQYXY(name string) bool{
-	q := map[string]interface{}{"company_name": name,}
-	data,_ := u.Mgo_QY.FindOne("qyxy_std",q)
-	if len(*data)>2 && *data!=nil{
+func qyNameIsExistsQYXY(name string) bool {
+	q := map[string]interface{}{"company_name": name}
+	data, _ := u.Mgo_QY.FindOne("qyxy_std", q)
+	if len(*data) > 2 && *data != nil {
 		return false
 	}
 	return false
 }
+
 //采购单位库
-func buyerNameIsExists(name string) bool{
-	q := map[string]interface{}{"buyer_name": name,}
-	data,_ := u.Mgo_QY.FindOne("buyer_enterprise",q)
-	if len(*data)>2 && *data!=nil{
+func buyerNameIsExists(name string) bool {
+	q := map[string]interface{}{"buyer_name": name}
+	data, _ := u.Mgo_QY.FindOne("buyer_enterprise", q)
+	if len(*data) > 2 && *data != nil {
 		return false
 	}
 	return false
@@ -110,30 +106,30 @@ func isHan(str string) bool {
 //符号数量
 func isCharCount(str string) []int {
 	//中文,英文,数字,其他
-	c1,c2,c3,c4:=0,0,0,0
+	c1, c2, c3, c4 := 0, 0, 0, 0
 	for _, v := range str {
 		if unicode.Is(unicode.Han, v) {
 			c1++
-		}else if unicode.IsLetter(v){
+		} else if unicode.IsLetter(v) {
 			c2++
-		} else if unicode.IsNumber(v){
+		} else if unicode.IsNumber(v) {
 			c3++
-		}else {
+		} else {
 			c4++
 		}
 	}
-	return []int{c1,c2,c3,c4}
+	return []int{c1, c2, c3, c4}
 }
 
 //中文比例-1:3
 func isHanLenToLittle(str string) bool {
 	var count int
 	len := utf8.RuneCountInString(str)
-	min_count := len/3
+	min_count := len / 3
 	for _, v := range str {
 		if unicode.Is(unicode.Han, v) {
 			count++
-			if count>=min_count {
+			if count >= min_count {
 				return true
 			}
 		}
@@ -141,8 +137,6 @@ func isHanLenToLittle(str string) bool {
 	return false
 }
 
-
-
 //是否含字母数字
 func isAlphanumeric(str string) bool {
 	var count int
@@ -157,55 +151,40 @@ func isAlphanumeric(str string) bool {
 
 //连续数字
 func isRegTimeDateCode(str string) bool {
-	reg:=`\d{8}`
-	regx,_ := regexp.Compile(reg)
-	if regx.FindString(str)!="" {
+	reg := `\d{8}`
+	regx, _ := regexp.Compile(reg)
+	if regx.FindString(str) != "" {
 		return false
 	}
-	if utf8.RuneCountInString(str)==8 {
+	if utf8.RuneCountInString(str) == 8 {
 		return true
 	}
 	return false
 }
 
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
 //配置字段初始分
 func FieldSourceScore(source map[string]interface{}) map[string]int64 {
-	fieldArr := []string{"buyer","s_winner","budget","bidamount","projectname","projectcode"}
-	score := make(map[string]int64,0)
-	for _,v := range fieldArr{
+	fieldArr := []string{"buyer", "s_winner", "budget", "bidamount", "projectname", "projectcode"}
+	score := make(map[string]int64, 0)
+	for _, v := range fieldArr {
 		score[v] = int64(100)
 	}
-	for _,key := range fieldArr {
+	for _, key := range fieldArr {
 		ext := *qu.ObjToMap(source[key])
-		if ext!=nil{
-			ext_from:=qu.ObjToString(ext["ext_from"])
-			ext_type:=qu.ObjToString(ext["ext_type"])
+		if ext != nil {
+			ext_from := qu.ObjToString(ext["ext_from"])
+			ext_type := qu.ObjToString(ext["ext_type"])
 			//规范ext_from
 			ext_from = normalizedExtFromName(ext_from)
-			if ext_from=="winnerorder" || ext_from=="package" ||
-				ext_from=="jsondata" || ext_type=="" {
+			if ext_from == "winnerorder" || ext_from == "package" ||
+				ext_from == "jsondata" || ext_type == "" {
 				u.Qy_Lock.Lock()
 				score[key] = qu.Int64All(u.Ext_From[ext_from])
 				u.Qy_Lock.Unlock()
-			}else {
+			} else {
 				u.Qy_Lock.Lock()
-				s := qu.Int64All(u.Ext_From[ext_from])+qu.Int64All(u.Ext_Type[ext_type])
-				score[key] = s/2
+				s := qu.Int64All(u.Ext_From[ext_from]) + qu.Int64All(u.Ext_Type[ext_type])
+				score[key] = s / 2
 				u.Qy_Lock.Unlock()
 			}
 		}
@@ -217,12 +196,12 @@ func FieldSourceScore(source map[string]interface{}) map[string]int64 {
 
 //规范-抽取来源字符串
 func normalizedExtFromName(str string) string {
-	if strings.Contains(str,"order") {
+	if strings.Contains(str, "order") {
 		str = "winnerorder"
-	}else if strings.Contains(str,"JsonData") {
+	} else if strings.Contains(str, "JsonData") {
 		str = "jsondata"
-	}else {
+	} else {
 
 	}
 	return str
-}
+}

+ 1 - 1
src/web/templates/project/project_clear.html

@@ -315,7 +315,7 @@
         })
 
         let arr = []
-        arr.push({"s_groupid": "61a47d76c908d368871f5033", "s_groupname": "ceshi", "s_personname": "111", "i_givenum": 100})
+        arr.push({"s_groupid": "61a47d76c908d368871f5033", "s_groupname": "ceshi", "s_personname": "111", "i_givenum": 30})
         console.log(JSON.stringify(arr))
         $.ajax({
             url: "/front/project/task/save",