Skip to content

Commit

Permalink
v.0.19
Browse files Browse the repository at this point in the history
  • Loading branch information
nikolainp committed Oct 14, 2023
1 parent ca4b285 commit d7ae2c3
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 213 deletions.
61 changes: 25 additions & 36 deletions datarecord/datarecord.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@ import (
"bytes"
"fmt"
"log"
"sort"
"strconv"
"strings"
"time"

"golang.org/x/exp/maps"
)

type void struct{}
Expand Down Expand Up @@ -82,15 +81,12 @@ func (obj *dataReader) ReadDataRecord(data string) {
func (obj *dataReader) GetColumns() []string {

columns := make([]string, 0, 10)
if len(obj.columnNames) == 0 {
for i := 1; i < obj.points+1; i++ {
columns = append(columns, fmt.Sprintf("Column %d", i))
for _, name := range obj.getColumnNames() {
if name == "" {
name = "Column"
}
} else {
for name := range obj.columnNames {
for i := 1; i < obj.points+1; i++ {
columns = append(columns, fmt.Sprintf("%s%d", name, i))
}
for i := 1; i < obj.points+1; i++ {
columns = append(columns, fmt.Sprintf("%s %d", name, i))
}
}

Expand All @@ -101,16 +97,13 @@ func (obj *dataReader) GetDataRows() []string {

rows := make([]string, 0, 10)

columns := maps.Keys(obj.columnNames)
if len(columns) == 0 {
columns = append(columns, "")
}
columns := obj.getColumnNames()

buffer := new(bytes.Buffer)
writer := bufio.NewWriter(buffer)

for i := 0; i < obj.points; i++ {
writer.WriteString(", ")
writer.WriteString(", null")
}
writer.Flush()
blankPoints := buffer.String()
Expand Down Expand Up @@ -143,6 +136,23 @@ func (obj *dataReader) GetDataRows() []string {
return rows
}

///////////////////////////////////////////////////////

func (obj *dataReader) getColumnNames() []string {
columns := make([]string, 0, 10)
if len(obj.columnNames) == 0 {
columns = append(columns, "")
} else {
for name := range obj.columnNames {
columns = append(columns, name)
}
}

sort.Strings(columns)

return columns
}

///////////////////////////////////////////////////////
// dateRecord

Expand Down Expand Up @@ -176,24 +186,3 @@ func (obj *dataReader) getDataRecord(data string) (record dataRecord) {

return
}

// func (obj *dataRecord) String() string {
// buffer := new(bytes.Buffer)
// writer := bufio.NewWriter(buffer)

// //[new Date(2314, 2, 16), {"": [24045, 12374]}],

// writer.WriteString("[")
// writer.WriteString(fmt.Sprintf("new Date(%s)", obj.dateTime.Format("2006, 01, 02, 15, 04, 05")))
// for _, point := range obj.points {
// writer.WriteString(fmt.Sprintf(", %g", point))
// }
// writer.WriteString("]")

// writer.Flush()
// return buffer.String()
// }

func (obj *dataRecord) Columns() int {
return len(obj.points)
}
4 changes: 2 additions & 2 deletions datarecord/datarecord_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,11 @@ func Test_dataReader_GetColumns(t *testing.T) {
}{
{
"test 1", dataReader{columnNames: map[string]void{"first": {}, "second": {}}, points: 3},
[]string{"first1", "first2", "first3", "second1", "second2", "second3"},
[]string{"first 1", "first 2", "first 3", "second 1", "second 2", "second 3"},
},
{
"test 2", dataReader{columnNames: map[string]void{}, points: 3},
[]string{"Column1", "Column2", "Column3"},
[]string{"Column 1", "Column 2", "Column 3"},
},
}
for _, tt := range tests {
Expand Down
175 changes: 0 additions & 175 deletions toGraph_test.go

This file was deleted.

0 comments on commit d7ae2c3

Please sign in to comment.