AggsToTableCopy returns a Table containing this Splits' aggregate data and a copy of the first row of data for each split for all non-agg cols, which is useful for recording other data that goes along with aggregated values. Must have Levels and Aggs all created as in the split.Agg* methods. if colN
(colName bool)
| 453 | // is just the corresponding agg column name -- otherwise it also includes |
| 454 | // the name of the aggregation function with a : divider (e.g., Name:Mean) |
| 455 | func (spl *Splits) AggsToTableCopy(colName bool) *Table { |
| 456 | nsp := len(spl.Splits) |
| 457 | if nsp == 0 { |
| 458 | return nil |
| 459 | } |
| 460 | dt := spl.Splits[0].Table |
| 461 | st := NewTable().SetNumRows(nsp) |
| 462 | exmap := make(map[string]struct{}) |
| 463 | for _, cn := range spl.Levels { |
| 464 | st.AddStringColumn(cn) |
| 465 | exmap[cn] = struct{}{} |
| 466 | } |
| 467 | for _, ag := range spl.Aggs { |
| 468 | col := dt.Columns[ag.ColumnIndex] |
| 469 | an := dt.ColumnNames[ag.ColumnIndex] |
| 470 | exmap[an] = struct{}{} |
| 471 | if colName == AddAggName { |
| 472 | an += ":" + ag.Name |
| 473 | } |
| 474 | st.AddFloat64TensorColumn(an, col.Shape().Sizes[1:], col.Shape().Names[1:]...) |
| 475 | } |
| 476 | var cpcol []string |
| 477 | for _, cn := range dt.ColumnNames { |
| 478 | if _, ok := exmap[cn]; !ok { |
| 479 | cpcol = append(cpcol, cn) |
| 480 | col := dt.ColumnByName(cn) |
| 481 | st.AddColumn(col.Clone(), cn) |
| 482 | } |
| 483 | } |
| 484 | for si, sidx := range spl.Splits { |
| 485 | cidx := 0 |
| 486 | for ci := range spl.Levels { |
| 487 | col := st.Columns[cidx] |
| 488 | col.SetString1D(si, spl.Values[si][ci]) |
| 489 | cidx++ |
| 490 | } |
| 491 | for _, ag := range spl.Aggs { |
| 492 | col := st.Columns[cidx] |
| 493 | _, csz := col.RowCellSize() |
| 494 | sti := si * csz |
| 495 | av := ag.Aggs[si] |
| 496 | for j, a := range av { |
| 497 | col.SetFloat1D(sti+j, a) |
| 498 | } |
| 499 | cidx++ |
| 500 | } |
| 501 | if len(sidx.Indexes) > 0 { |
| 502 | stidx := sidx.Indexes[0] |
| 503 | for _, cn := range cpcol { |
| 504 | st.CopyCell(cn, si, dt, cn, stidx) |
| 505 | } |
| 506 | } |
| 507 | } |
| 508 | return st |
| 509 | } |
| 510 | |
| 511 | // Less calls the LessFunc for sorting |
| 512 | func (spl *Splits) Less(i, j int) bool { |
nothing calls this directly
no test coverage detected