Skip to content

Commit

Permalink
v.0.40
Browse files Browse the repository at this point in the history
  • Loading branch information
nikolainp committed Nov 4, 2023
1 parent 91d0656 commit 8619cfc
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
22 changes: 15 additions & 7 deletions datarecord/datarecord.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}
}

Expand Down
5 changes: 5 additions & 0 deletions datarecord/datarecord_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 8619cfc

Please sign in to comment.