diff --git a/datarecord/datarecord.go b/datarecord/datarecord.go index daf84e1..e18809b 100644 --- a/datarecord/datarecord.go +++ b/datarecord/datarecord.go @@ -187,17 +187,25 @@ func (obj *dataColumns) getColumnNames() []string { func (obj *dataColumns) getColumnStatistics() []ColumnStatistic { columns := make([]ColumnStatistic, 0) + getColumnStatistic := func (name string, data columnStatistic) ColumnStatistic{ + return ColumnStatistic{ + Name: name, + Minimum: data.minimum, + Maximum: data.maximum, + Average: data.sum / float32(data.count), + } + } + for name, pivotData := range obj.statistic { if name == "" { name = "Column" } - for i, data := range pivotData { - columns = append(columns, ColumnStatistic{ - Name: fmt.Sprintf("%s %d", name, i+1), - Minimum: data.minimum, - Maximum: data.maximum, - Average: data.sum / float32(data.count), - }) + if len(pivotData) == 1 { + columns = append(columns, getColumnStatistic(name, pivotData[0])) + }else { + for i, data := range pivotData { + columns = append(columns, getColumnStatistic(fmt.Sprintf("%s %d", name, i+1), data)) + } } } diff --git a/datarecord/datarecord_test.go b/datarecord/datarecord_test.go index 5fef4c4..f344dda 100644 --- a/datarecord/datarecord_test.go +++ b/datarecord/datarecord_test.go @@ -202,6 +202,11 @@ func Test_dataColumns_getColumnStatistics(t *testing.T) { dataColumns{names: []string{}, statistic: map[string][]columnStatistic{"": {{1, 1, 1, 1}, {2, 2, 2, 1}, {3, 3, 3, 1}}}}, []ColumnStatistic{{"Column 1", 1, 1, 1}, {"Column 2", 2, 2, 2}, {"Column 3", 3, 3, 3}}, }, + { + "test 3", + dataColumns{names: []string{}, statistic: map[string][]columnStatistic{"first": {{1, 1, 1, 1}}}}, + []ColumnStatistic{{"first", 1, 1, 1}}, + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) {