MCPcopy
hub / github.com/antonycourtney/tad / columnHistogramQuery

Function columnHistogramQuery

packages/reltab/src/histogram.ts:49–102  ·  view source on GitHub ↗
(
  baseQuery: QueryExp,
  colId: string,
  colType: ColumnType,
  colStats: NumericSummaryStats
)

Source from the content-addressed store, hash-verified

47}
48
49export function columnHistogramQuery(
50 baseQuery: QueryExp,
51 colId: string,
52 colType: ColumnType,
53 colStats: NumericSummaryStats
54): NumericColumnHistogramQuery | null {
55 const minVal = colStats.min;
56 const maxVal = colStats.max;
57
58 if (minVal == null || maxVal == null || minVal === maxVal) {
59 return null;
60 }
61 const binCount = binsForColumn(colStats);
62
63 const [niceMinVal, niceMaxVal] = nice(minVal, maxVal, binCount);
64
65 const binWidth = (niceMaxVal - niceMinVal) / binCount;
66
67 // add a column with bin number:
68 const binQuery = baseQuery
69 .extend("column", constVal(colId))
70 .extend(
71 "bin",
72 cast(
73 floor(
74 divide(
75 minus(
76 cast(col(colId), doubleType),
77 cast(constVal(niceMinVal), doubleType)
78 ),
79 cast(constVal(binWidth), doubleType)
80 )
81 ),
82 intType
83 )
84 );
85
86 const histoQuery = binQuery
87 .extend("binCount", constVal(1))
88 .project(["column", "bin", "binCount"])
89 .groupBy(["column", "bin"], [["count", "binCount"]]);
90
91 const ret = {
92 colId,
93 histoQuery,
94 minVal,
95 maxVal,
96 niceMinVal,
97 niceMaxVal,
98 binCount,
99 binWidth,
100 };
101 return ret;
102}
103
104// histogram data for rendering a single column histogram
105export interface NumericColumnHistogramData {

Callers 2

histo.auto.test.tsFile · 0.90

Calls 11

niceFunction · 0.90
constValFunction · 0.90
castFunction · 0.90
floorFunction · 0.90
divideFunction · 0.90
minusFunction · 0.90
colFunction · 0.90
binsForColumnFunction · 0.85
groupByMethod · 0.80
projectMethod · 0.80
extendMethod · 0.45

Tested by

no test coverage detected