MCPcopy Create free account
hub / github.com/cogentcore/core / AggsToTable

Method AggsToTable

tensor/table/splits.go:404–446  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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)
404func (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,

Callers 4

AvgByColumnFunction · 0.95
AnalyzePlanetsFunction · 0.80
TestAggFunction · 0.80
TestAggEmptyFunction · 0.80

Calls 11

ColumnByNameMethod · 0.80
AddColumnOfTypeMethod · 0.80
AddStringColumnMethod · 0.80
NewTableFunction · 0.70
SetNumRowsMethod · 0.65
DataTypeMethod · 0.65
ShapeMethod · 0.65
SetString1DMethod · 0.65
RowCellSizeMethod · 0.65
SetFloat1DMethod · 0.65

Tested by 2

TestAggFunction · 0.64
TestAggEmptyFunction · 0.64