提交 97eff9f6 编写于 作者: 陈琦

fix issues

上级 c414e03d
......@@ -5,67 +5,116 @@ import (
constant "github.com/easysoft/zendata/src/utils/const"
)
func GenerateByteItems(start byte, end byte, step int, rand bool, repeat int, tag string) []interface{} {
func GenerateByteItems(start byte, end byte, step int, rand bool, repeat int, repeatTag string) []interface{} {
if !rand {
return generateByteItemsByStep(start, end, step, repeat)
return generateByteItemsByStep(start, end, step, repeat, repeatTag)
} else {
return generateByteItemsRand(start, end, step, repeat)
return generateByteItemsRand(start, end, step, repeat, repeatTag)
}
}
func generateByteItemsByStep(start byte, end byte, step int, repeat int) []interface{} {
func generateByteItemsByStep(start byte, end byte, step int, repeat int, repeatTag string) []interface{} {
arr := make([]interface{}, 0)
total := 0
for i := 0; true; {
val := start + byte(int(i)*step)
if (val > end && step > 0) || (val < end && step < 0) {
break
}
if repeatTag == "" {
for i := 0; true; {
val := start + byte(int(i)*step)
if (val > end && step > 0) || (val < end && step < 0) {
break
}
for round := 0; round < repeat; round++ {
arr = append(arr, val)
for round := 0; round < repeat; round++ {
arr = append(arr, val)
total++
if total > constant.MaxNumb {
break
}
}
total++
if total > constant.MaxNumb {
break
}
i++
}
} else if repeatTag == "!" {
for round := 0; round < repeat; round++ {
for i := 0; true; {
val := start + byte(int(i)*step)
if (val > end && step > 0) || (val < end && step < 0) {
break
}
if total > constant.MaxNumb {
break
arr = append(arr, val)
if total > constant.MaxNumb {
break
}
i++
}
total++
if total > constant.MaxNumb {
break
}
}
i++
}
return arr
}
func generateByteItemsRand(start byte, end byte, step int, repeat int) []interface{} {
func generateByteItemsRand(start byte, end byte, step int, repeat int, repeatTag string) []interface{} {
arr := make([]interface{}, 0)
countInRound := (int(end) - int(start)) / step
total := 0
for i := 0; i < countInRound; {
rand := commonUtils.RandNum(countInRound)
if step < 0 {
rand = rand * -1
}
val := start + byte(rand)
if repeatTag == "" {
for i := 0; i < countInRound; {
rand := commonUtils.RandNum(countInRound)
if step < 0 {
rand = rand * -1
}
for round := 0; round < repeat; round++ {
arr = append(arr, val)
val := start + byte(rand)
for round := 0; round < repeat; round++ {
arr = append(arr, val)
total++
if total > constant.MaxNumb {
break
}
}
total++
if total > constant.MaxNumb {
break
}
i++
}
} else if repeatTag == "!" {
for round := 0; round < repeat; round++ {
for i := 0; i < countInRound; {
rand := commonUtils.RandNum(countInRound)
if step < 0 {
rand = rand * -1
}
if total > constant.MaxNumb {
break
val := start + byte(rand)
arr = append(arr, val)
if total > constant.MaxNumb {
break
}
i++
}
total++
if total > constant.MaxNumb {
break
}
}
i++
}
return arr
......
......@@ -7,82 +7,129 @@ import (
"strings"
)
func GenerateFloatItems(start float64, end float64, step interface{}, rand bool, repeat int, tag string) []interface{} {
func GenerateFloatItems(start float64, end float64, step interface{}, rand bool, precision, repeat int, repeatTag string) []interface{} {
if !rand {
return generateFloatItemsByStep(start, end, step.(float64), repeat)
return generateFloatItemsByStep(start, end, step.(float64), precision, repeat, repeatTag)
} else {
return generateFloatItemsRand(start, end, step.(float64), repeat)
return generateFloatItemsRand(start, end, step.(float64), precision, repeat, repeatTag)
}
}
func generateFloatItemsByStep(start float64, end float64, step float64, repeat int) []interface{} {
func generateFloatItemsByStep(start float64, end float64, step float64, precision, repeat int, repeatTag string) []interface{} {
arr := make([]interface{}, 0)
total := 0
for i := 0; true; {
val := start + float64(i)*step
if (val > end && step > 0) || (val < end && step < 0) {
break
}
if repeatTag == "" {
for i := 0; true; {
val := start + float64(i)*step
if (val > end && step > 0) || (val < end && step < 0) {
break
}
for round := 0; round < repeat; round++ {
arr = append(arr, val)
total++
if total > constant.MaxNumb {
break
}
}
if total > constant.MaxNumb {
break
}
i++
}
} else if repeatTag == "!" {
for round := 0; round < repeat; round++ {
arr = append(arr, val)
for i := 0; true; {
val := start + float64(i)*step
if (val > end && step > 0) || (val < end && step < 0) {
break
}
arr = append(arr, val)
if total > constant.MaxNumb {
break
}
i++
}
total++
if total > constant.MaxNumb {
break
}
}
if total > constant.MaxNumb {
break
}
i++
}
return arr
}
func generateFloatItemsRand(start float64, end float64, step float64, repeat int) []interface{} {
func generateFloatItemsRand(start float64, end float64, step float64, precision, repeat int, repeatTag string) []interface{} {
arr := make([]interface{}, 0)
countInRound := (end - start) / step
total := 0
for i := float64(0); i < countInRound; {
rand := commonUtils.RandNum64(int64(countInRound))
if step < 0 {
rand = rand * -1
}
val := start + float64(rand)*step
if repeatTag == "" {
for i := float64(0); i < countInRound; {
rand := commonUtils.RandNum64(int64(countInRound))
if step < 0 {
rand = rand * -1
}
for round := 0; round < repeat; round++ {
arr = append(arr, val)
val := start + float64(rand)*step
for round := 0; round < repeat; round++ {
arr = append(arr, val)
total++
if total > constant.MaxNumb {
break
}
}
total++
if total > constant.MaxNumb {
break
}
i++
}
} else if repeatTag == "!" {
for round := 0; round < repeat; round++ {
for i := float64(0); i < countInRound; {
rand := commonUtils.RandNum64(int64(countInRound))
if step < 0 {
rand = rand * -1
}
val := start + float64(rand)*step
arr = append(arr, val)
if total > constant.MaxNumb {
break
}
i++
}
if total > constant.MaxNumb {
break
total++
if total > constant.MaxNumb {
break
}
}
i++
}
return arr
}
func GetPrecision(base float64, step interface{}) (precision int, newStep float64) {
val := base
if step != nil {
val += step.(float64)
var flt float64 = 1
if step == nil {
step = flt
}
str1 := strconv.FormatFloat(base, 'f', -1, 64)
str2 := strconv.FormatFloat(val, 'f', -1, 64)
str2 := strconv.FormatFloat(step.(float64), 'f', -1, 64)
index1 := strings.LastIndex(str1, ".")
index2 := strings.LastIndex(str2, ".")
......
......@@ -240,7 +240,7 @@ func CreateValuesFromInterval(field *model.DefField, desc, stepStr string, repea
endFloat, _ := strconv.ParseFloat(endStr, 64)
field.Precision = precision
items = GenerateFloatItems(startFloat, endFloat, step, rand, repeat, repeatTag)
items = GenerateFloatItems(startFloat, endFloat, step, rand, precision, repeat, repeatTag)
} else if dataType == "char" {
items = GenerateByteItems(startStr[0], endStr[0], step.(int), rand, repeat, repeatTag)
......
......@@ -3,7 +3,7 @@ desc: 描述
version: 1.0
fields:
- field: field_length
range: 1-3{2!}
range: 1.11-1.13:0.001
length: 3
leftpad: 0
prefix: "+"
......
......@@ -75,7 +75,6 @@ export default {
},
watch: {
id: function() {
console.log('watch id ' + this.id)
this.loadData();
}
},
......
......@@ -159,7 +159,7 @@ export default {
})
},
create() {
this.editRecord = null;
this.editRecord = {};
this.editModalVisible = true;
},
edit(record) {
......
title: 被引用测试
desc: ""
fields:
- field: field1
range: '`fd`'
prefix: '['
postfix: "]\t"
- field: 新字段
fields:
- field: 新字段
range: 0-9,0-9,0-9{11}
from: zentao.number.v1.yaml
use: small{0}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册