瀏覽代碼

折扣率方法转换

zhengkun 8 月之前
父節點
當前提交
681b03c458
共有 2 個文件被更改,包括 47 次插入9 次删除
  1. 7 7
      clean/c_time.go
  2. 40 2
      main.go

+ 7 - 7
clean/c_time.go

@@ -10,10 +10,11 @@ import (
 )
 
 var numReg = regexp.MustCompile("[0-9.]+")
+var symbolReg = regexp.MustCompile("[%%﹪!!]")
 
 // 清洗时间
 func CleanTime(st string) int64 {
-	if st == "" {
+	if st == "" || st == "无" {
 		return 0
 	}
 	//YYYY-MM-DD HH:MM:SS
@@ -23,11 +24,10 @@ func CleanTime(st string) int64 {
 
 // 清洗折扣率
 func CleanDiscount(str string) float64 {
-	/*
-		上浮率:20%
-		下浮率:20%
-		折扣率:20%
-	*/
+	str = fieldReg1.ReplaceAllString(str, "")
+	if str == "" || str == "无" {
+		return 0.0
+	}
 	if biddiscount := RateToFloat(str); biddiscount > 0.0 {
 		baseCount := 1.0
 		num1 := decimal.NewFromFloat(baseCount)
@@ -52,7 +52,7 @@ func RateToFloat(str string) float64 {
 	if num0 := qu.Float64All(numReg.FindString(str)); num0 > 0.0 {
 		num1 := decimal.NewFromFloat(100.0)
 		num2 := decimal.NewFromFloat(num0)
-		if strings.Contains(str, "%") || strings.Contains(str, "%") {
+		if symbolReg.MatchString(str) {
 			decimalValue := num2.Div(num1)
 			res, _ := decimalValue.Float64()
 			if res < 1.0 {

+ 40 - 2
main.go

@@ -1,6 +1,7 @@
 package main
 
 import (
+	"data_ai/clean"
 	"data_ai/extract"
 	"data_ai/udp"
 	"data_ai/ul"
@@ -30,9 +31,8 @@ func main() {
 		//tool.StartToolUpdateInfo()
 		return
 	}
-
 	//extract.TestSingleFieldInfo("bidding", "6722de29b25c3e1debe624c9")
-
+	test1()
 	lock := make(chan bool)
 	<-lock
 }
@@ -72,3 +72,41 @@ func test() {
 	wg_mgo.Wait()
 	log.Debug("ai is over ...")
 }
+
+func test1() {
+	arr := []string{
+		"下浮率:0.44%",
+		"下浮率:0.60%",
+		"下浮率:1.00%!",
+		"下浮率:0.39!",
+		"上浮率/下浮率:25%!",
+		"下浮率:1.500%!",
+		"上浮率/下浮率:25%!",
+		"下浮率:20%",
+		"下浮率:10%",
+		"下浮率:10%",
+		"下浮率:2.5!",
+		"下浮率:1.00%!",
+		"下浮率:0.39!",
+		"下浮率:0.44%",
+		"下浮率:6%!",
+		"下浮率:10%-30%!",
+		"下浮率:10%-25%",
+		"下浮率:15%-20%",
+		"下浮率:0.09%",
+		"下浮率:5.5!",
+		"下浮率:4.20%",
+		"下浮率:1.50%!",
+		"下浮率:12%!",
+		"上浮率/下浮率:0.60%!",
+		"下浮率:XX%",
+		"下浮率:5.9%",
+		"下浮率:40%",
+	}
+
+	for _, v := range arr {
+		nv := clean.CleanDiscount(v)
+		log.Debug(v, "~~~", nv)
+	}
+
+}