Skip to content

Commit

Permalink
v.0.25
Browse files Browse the repository at this point in the history
  • Loading branch information
nikolainp committed Oct 20, 2023
1 parent 6d95231 commit 71ee682
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,6 @@ jobs:
# either 'goreleaser' (default) or 'goreleaser-pro'
distribution: goreleaser
version: latest
args: release --clean --snapshot
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
15 changes: 14 additions & 1 deletion datarecord/datarecord.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ type dataReader struct {
dateFormat string
dateColumn int
pivotColumn int
delimiter []byte

columnNames map[string]void
points int
Expand Down Expand Up @@ -61,6 +62,11 @@ func (obj *dataReader) WithPivotColumn(column int) *dataReader {
return obj
}

func (obj *dataReader) WithDelimiter(delimiter string) *dataReader {
obj.delimiter = []byte(delimiter)
return obj
}

func (obj *dataReader) ReadDataRecord(data string) {
record := obj.getDataRecord(data)

Expand Down Expand Up @@ -158,7 +164,14 @@ func (obj *dataReader) getColumnNames() []string {

func (obj *dataReader) getDataRecord(data string) (record dataRecord) {
scan := bufio.NewScanner(strings.NewReader(data))
scan.Split(bufio.ScanWords)

onDelimiter := func(data []byte, atEOF bool) (advance int, token []byte, err error) {
if i := bytes.Index(data, obj.delimiter); i >= 0 {
return i + len(obj.delimiter), data[:i], nil
}
return 0, data, bufio.ErrFinalToken
}
scan.Split(onDelimiter) //bufio.ScanWords

record.points = make([]float32, 0, 5)

Expand Down
2 changes: 2 additions & 0 deletions datarecord/datarecord_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ func TestGetDataRecord(t *testing.T) {
var reader dataReader
reader.dateFormat = "20060102150405"
reader.dateColumn = 1
reader.delimiter = []byte{' '}

type args struct {
data string
Expand Down Expand Up @@ -40,6 +41,7 @@ func TestGetDataRecordPivot(t *testing.T) {
reader.dateFormat = "20060102150405"
reader.dateColumn = 1
reader.pivotColumn = 2
reader.delimiter = []byte{' '}

type args struct {
data string
Expand Down
8 changes: 7 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@

Usage of C:\Users\worker\Documents\toGraph\toGraph.exe:
Usage of toGraph:
-h print usage
-pc int
pivot column
-t string
time field format (YYYY-MM-DDTHH:mm:SS.ssssss) (default "YYYYMMDDHHmmSS")
-tc int
ordinal number of the column with time (default 1)
3 changes: 2 additions & 1 deletion statecontext/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ type Configuration struct {
DateFormat string
DateColumn int
PivotColumn int
Delimiter string

programName string
printUsage bool
Expand Down Expand Up @@ -56,7 +57,7 @@ func readCommandLineArguments(config *Configuration, args []string) (fs *flag.Fl
fs.StringVar(&config.DateFormat, "t", "YYYYMMDDHHmmSS", "time field format (YYYY-MM-DDTHH:mm:SS.ssssss)")
fs.IntVar(&config.DateColumn, "tc", 1, "ordinal number of the column with time")
fs.IntVar(&config.PivotColumn, "pc", 0, "pivot column")
// fs.StringVar(&config.LogOutputPath, "o", "", "log output file")
fs.StringVar(&config.Delimiter, "d", " ", "field separator")

if len(args) == 0 {
return nil, errEmptyArgumentList
Expand Down
8 changes: 8 additions & 0 deletions statecontext/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,48 +19,56 @@ func Test_readCommandLineArguments(t *testing.T) {
want{Configuration{
DateFormat: "YYYYMMDDHHmmSS",
DateColumn: 1,
Delimiter: " ",
printUsage: false}, errEmptyArgumentList}},
{"test 1", []string{"programname"},
want{Configuration{
DateFormat: "YYYYMMDDHHmmSS",
DateColumn: 1,
Delimiter: " ",
programName: "programname",
printUsage: true}, nil}},
{"help", []string{"programname", "-h"},
want{Configuration{
DateFormat: "YYYYMMDDHHmmSS",
DateColumn: 1,
Delimiter: " ",
programName: "programname",
printUsage: true}, nil}},
{"dateFormat", []string{"programname", "-t", "YYMMDDHHmm"},
want{Configuration{
DateFormat: "YYMMDDHHmm",
DateColumn: 1,
Delimiter: " ",
programName: "programname",
printUsage: true}, nil}},
{"dateColumn", []string{"programname", "-tc", "2"},
want{Configuration{
DateFormat: "YYYYMMDDHHmmSS",
DateColumn: 2,
Delimiter: " ",
programName: "programname",
printUsage: true}, nil}},
{"test 2", []string{"programname", "what"},
want{Configuration{
InputFiles: []string{"what"},
DateFormat: "YYYYMMDDHHmmSS",
DateColumn: 1,
Delimiter: " ",
programName: "programname"}, nil}},
{"test 3", []string{"programname", "what", "where"},
want{Configuration{
InputFiles: []string{"what", "where"},
DateFormat: "YYYYMMDDHHmmSS",
DateColumn: 1,
Delimiter: " ",
programName: "programname"}, nil}},
{"test 4", []string{"programname", "newLine", "what", "where"},
want{Configuration{
InputFiles: []string{"newLine", "what", "where"},
DateFormat: "YYYYMMDDHHmmSS",
DateColumn: 1,
Delimiter: " ",
programName: "programname"}, nil}},
}
for _, tt := range tests {
Expand Down
3 changes: 2 additions & 1 deletion toGraph.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ var checkErr = func(err error) {
}
}

// TODO: truncate file
// TODO: delimiter
// TODO: column names
// TODO: graph name + output file name

func main() {
state.InitState()
Expand Down Expand Up @@ -49,6 +49,7 @@ func processFile(sIn io.Reader, sOut io.Writer, config state.Configuration) erro
reader.WithDateFormat(config.DateFormat)
reader.WithDateColumn(config.DateColumn)
reader.WithPivotColumn(config.PivotColumn)
reader.WithDelimiter(config.Delimiter)

dataGraph, err := template.New("dataGraph").Parse(graphTemplate)
checkErr(err)
Expand Down

0 comments on commit 71ee682

Please sign in to comment.