AggsToTable returns a Table containing this Splits' aggregate data. Must have Levels and Aggs all created as in the split.Agg* methods. if colName == ColumnNameOnly, then the name of the columns for the Table is just the corresponding agg column name -- otherwise it also includes the name of the agg
(colName bool)
| 402 | // is just the corresponding agg column name -- otherwise it also includes |
| 403 | // the name of the aggregation function with a : divider (e.g., Name:Mean) |
| 404 | func (spl *Splits) AggsToTable(colName bool) *Table { |
| 405 | nsp := len(spl.Splits) |
| 406 | if nsp == 0 { |
| 407 | return nil |
| 408 | } |
| 409 | dt := spl.Splits[0].Table |
| 410 | st := NewTable().SetNumRows(nsp) |
| 411 | for _, cn := range spl.Levels { |
| 412 | oc := dt.ColumnByName(cn) |
| 413 | if oc != nil { |
| 414 | st.AddColumnOfType(oc.DataType(), cn) |
| 415 | } else { |
| 416 | st.AddStringColumn(cn) |
| 417 | } |
| 418 | } |
| 419 | for _, ag := range spl.Aggs { |
| 420 | col := dt.Columns[ag.ColumnIndex] |
| 421 | an := dt.ColumnNames[ag.ColumnIndex] |
| 422 | if colName == AddAggName { |
| 423 | an += ":" + ag.Name |
| 424 | } |
| 425 | st.AddFloat64TensorColumn(an, col.Shape().Sizes[1:], col.Shape().Names[1:]...) |
| 426 | } |
| 427 | for si := range spl.Splits { |
| 428 | cidx := 0 |
| 429 | for ci := range spl.Levels { |
| 430 | col := st.Columns[cidx] |
| 431 | col.SetString1D(si, spl.Values[si][ci]) |
| 432 | cidx++ |
| 433 | } |
| 434 | for _, ag := range spl.Aggs { |
| 435 | col := st.Columns[cidx] |
| 436 | _, csz := col.RowCellSize() |
| 437 | sti := si * csz |
| 438 | av := ag.Aggs[si] |
| 439 | for j, a := range av { |
| 440 | col.SetFloat1D(sti+j, a) |
| 441 | } |
| 442 | cidx++ |
| 443 | } |
| 444 | } |
| 445 | return st |
| 446 | } |
| 447 | |
| 448 | // AggsToTableCopy returns a Table containing this Splits' aggregate data |
| 449 | // and a copy of the first row of data for each split for all non-agg cols, |