提交 4816fdca 编写于 作者: aaronchen2k2k's avatar aaronchen2k2k

close task#7784,7787-7790

上级 742f2d04
...@@ -57,3 +57,7 @@ fields: ...@@ -57,3 +57,7 @@ fields:
range: "`0000-00`,`AA[2,a-z]`,[1-3]:2{3},`[1-3]:2{3}`" range: "`0000-00`,`AA[2,a-z]`,[1-3]:2{3},`[1-3]:2{3}`"
type: text type: text
- field: field_timestamp
range: today-aa:10
type: timestamp
...@@ -3,7 +3,7 @@ desc: ...@@ -3,7 +3,7 @@ desc:
author: zentao author: zentao
version: 1.0 version: 1.0
from: custom.ip.private.yaml from: jenkins.ip.private.yaml
fields: fields:
- field: field_use_instance - field: field_use_instance
......
此差异已折叠。
...@@ -85,7 +85,7 @@ func mergerDefine(defaultDef, configDef *model.DefData, fieldsToExport *[]string ...@@ -85,7 +85,7 @@ func mergerDefine(defaultDef, configDef *model.DefData, fieldsToExport *[]string
} else if defaultDef.Type != "" { } else if defaultDef.Type != "" {
vari.Type = defaultDef.Type vari.Type = defaultDef.Type
} else { } else {
vari.Type = constant.TypeText vari.Type = constant.ConfigTypeText
} }
if configDef.From != "" && defaultDef.From == "" { if configDef.From != "" && defaultDef.From == "" {
...@@ -210,6 +210,10 @@ func CopyField(child model.DefField, parent *model.DefField) { ...@@ -210,6 +210,10 @@ func CopyField(child model.DefField, parent *model.DefField) {
(*parent).From = child.From (*parent).From = child.From
} }
if child.Type != "" {
(*parent).Type = child.Type
}
if child.Precision != 0 { if child.Precision != 0 {
(*parent).Precision = child.Precision (*parent).Precision = child.Precision
} }
......
package gen
import (
"github.com/easysoft/zendata/src/model"
constant "github.com/easysoft/zendata/src/utils/const"
)
func CreateField(field *model.DefField) model.FieldWithValues {
fieldWithValue := model.FieldWithValues{}
if field.Type == "" { // set default
field.Type = constant.FieldTypeList
}
if field.Type == constant.FieldTypeList {
CreateListField(field, &fieldWithValue)
} else if field.Type == constant.FieldTypeTimestamp {
CreateTimestampField(field, &fieldWithValue)
}
return fieldWithValue
}
\ No newline at end of file
...@@ -171,7 +171,7 @@ func GenerateForField(field *model.DefField, withFix bool) (values []string) { ...@@ -171,7 +171,7 @@ func GenerateForField(field *model.DefField, withFix bool) (values []string) {
func GenerateFieldValuesForDef(field *model.DefField) []string { func GenerateFieldValuesForDef(field *model.DefField) []string {
values := make([]string, 0) values := make([]string, 0)
fieldWithValues := CreateList(field) fieldWithValues := CreateField(field)
computerLoop(field) computerLoop(field)
indexOfRow := 0 indexOfRow := 0
......
...@@ -5,11 +5,11 @@ import ( ...@@ -5,11 +5,11 @@ import (
constant "github.com/easysoft/zendata/src/utils/const" constant "github.com/easysoft/zendata/src/utils/const"
) )
func GenerateIntItems(start int64, end int64, step interface{}, rand bool, limit int) []interface{} { func GenerateIntItems(start int64, end int64, step interface{}, rand bool, repeat int) []interface{} {
if !rand { if !rand {
return GenerateIntItemsByStep(start, end, step.(int), limit) return GenerateIntItemsByStep(start, end, step.(int), repeat)
} else{ } else{
return GenerateIntItemsRand(start, end, step.(int), limit) return GenerateIntItemsRand(start, end, step.(int), repeat)
} }
} }
......
...@@ -8,13 +8,6 @@ import ( ...@@ -8,13 +8,6 @@ import (
"strings" "strings"
) )
func CreateList(field *model.DefField) model.FieldWithValues {
fieldWithValue := model.FieldWithValues{}
CreateListField(field, &fieldWithValue)
return fieldWithValue
}
func CreateListField(field *model.DefField, fieldWithValue *model.FieldWithValues) { func CreateListField(field *model.DefField, fieldWithValue *model.FieldWithValues) {
fieldWithValue.Field = field.Field fieldWithValue.Field = field.Field
fieldWithValue.Precision = field.Precision fieldWithValue.Precision = field.Precision
...@@ -25,11 +18,11 @@ func CreateListField(field *model.DefField, fieldWithValue *model.FieldWithValue ...@@ -25,11 +18,11 @@ func CreateListField(field *model.DefField, fieldWithValue *model.FieldWithValue
CreateListField(&child, &childFieldWithValue) CreateListField(&child, &childFieldWithValue)
} }
} else { } else {
CreateFieldValues(field, fieldWithValue) CreateListFieldValues(field, fieldWithValue)
} }
} }
func CreateFieldValues(field *model.DefField, fieldValue *model.FieldWithValues) { func CreateListFieldValues(field *model.DefField, fieldValue *model.FieldWithValues) {
if strings.Index(field.Range, ".txt") > -1 { if strings.Index(field.Range, ".txt") > -1 {
CreateFieldValuesFromText(field, fieldValue) CreateFieldValuesFromText(field, fieldValue)
} else { } else {
......
package gen
import (
"github.com/easysoft/zendata/src/model"
constant "github.com/easysoft/zendata/src/utils/const"
"strconv"
"strings"
"time"
)
func CreateTimestampField(field *model.DefField, fieldWithValue *model.FieldWithValues) {
fieldWithValue.Field = field.Field
rang := strings.Trim(strings.TrimSpace(field.Range), ",")
rangeSections := strings.Split(rang, ",")
values := make([]interface{}, 0)
for _, section := range rangeSections {
createTimestampSectionValue(section, &values)
}
if len(values) == 0 {
values = append(values, "N/A")
}
fieldWithValue.Values = values
}
func createTimestampSectionValue(section string, values *[]interface{}) {
desc, step := parseTsSection(section)
start, end := parseTsDesc(desc)
if step > 0 && start > end {
step *= -1
}
// get index numbers for data retrieve
numbs := GenerateIntItems(start, end, step, false, 1)
// generate data by index
index := 0
for _, numb := range numbs {
if index >= constant.MaxNumb { break }
*values = append(*values, numb)
index = index + 1
}
}
func parseTsSection(section string) (desc string, step int) {
section = strings.TrimSpace(section)
sectionArr := strings.Split(section, ":")
desc = sectionArr[0]
step = 1
if len(sectionArr) > 1 {
stepStr := sectionArr[1]
stepTemp, err := strconv.Atoi(stepStr)
if err == nil {
step = stepTemp
}
}
return
}
func parseTsDesc(desc string) (start, end int64) {
desc = strings.TrimSpace(desc)
if desc == "today" {
start, end = getTodayTs()
return
}
arr := strings.Split(desc, "-")
startStr := arr[0]
endStr := ""
if len(arr) > 1 {
endStr = arr[1]
}
if endStr == "" {
endStr = startStr
}
start = parseTsValue(startStr, true)
end = parseTsValue(endStr, false)
return
}
func parseTsValue(str string, isStart bool) (value int64) {
str = strings.TrimSpace(str)
if strings.Contains(str, "now") {
value = time.Now().Unix()
return
} else if str == "today" {
start, end := getTodayTs()
if isStart {
value = start
} else {
value = end
}
return
}
tm, err := time.Parse("20060102", str)
if err != nil {
todayStart, todayEnd := getTodayTs()
if isStart {
value = todayStart
} else {
value = todayEnd
}
} else {
if !isStart {
tm = time.Date(tm.Year(), tm.Month(), tm.Day(), 23, 59, 59, 0, tm.Location())
}
value = tm.Unix()
}
return
}
func getTodayTs() (start, end int64) {
now := time.Now()
start = time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, now.Location()).Unix()
end = time.Date(now.Year(), now.Month(), now.Day(), 23, 59, 59, 0, now.Location()).Unix()
return
}
\ No newline at end of file
...@@ -78,6 +78,7 @@ type FieldSimple struct { ...@@ -78,6 +78,7 @@ type FieldSimple struct {
Loopfix string `yaml:"loopfix"` Loopfix string `yaml:"loopfix"`
Format string `yaml:"format"` Format string `yaml:"format"`
Rand bool `yaml:"rand"` Rand bool `yaml:"rand"`
Type string `yaml:"type"`
LoopStart int `yaml:"-"` LoopStart int `yaml:"-"`
LoopEnd int `yaml:"-"` LoopEnd int `yaml:"-"`
......
...@@ -38,11 +38,14 @@ var ( ...@@ -38,11 +38,14 @@ var (
FormatData = "data" FormatData = "data"
Formats = []string{FormatText, FormatJson, FormatXml, FormatSql} Formats = []string{FormatText, FormatJson, FormatXml, FormatSql}
TypeText = "text" ConfigTypeText = "text"
TypeImage = "image" ConfigTypeArticle = "article"
TypeVoice = "voice" ConfigTypeImage = "image"
TypeVideo = "video" ConfigTypeVoice = "voice"
TypeArticle = "article" ConfigTypeVideo = "video"
FieldTypeList = "list"
FieldTypeTimestamp = "timestamp"
LeftBrackets rune = '(' LeftBrackets rune = '('
RightBrackets rune = ')' RightBrackets rune = ')'
......
...@@ -80,7 +80,7 @@ func PrintErrMsg(msg string) { ...@@ -80,7 +80,7 @@ func PrintErrMsg(msg string) {
} }
func PrintLine(line string) { func PrintLine(line string) {
if vari.Type == constant.TypeText { if vari.Type == constant.ConfigTypeText {
line += "\n" line += "\n"
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册