MCPcopy Index your code
hub / github.com/microsoft/SandDance / getStats

Function getStats

packages/sanddance-specs/src/inference.ts:93–129  ·  view source on GitHub ↗
(data: object[], column: Column)

Source from the content-addressed store, hash-verified

91}
92
93export function getStats(data: object[], column: Column) {
94 const distinctMap = {};
95 const stats: ColumnStats = {
96 distinctValueCount: null,
97 max: null,
98 mean: null,
99 min: null,
100 };
101 let sum = 0;
102 for (let i = 0; i < data.length; i++) {
103 const row = data[i];
104 const value = row[column.name];
105 distinctMap[value] = true;
106 if (stats.max === null || value > stats.max) {
107 stats.max = value;
108 }
109 if (stats.min === null || value < stats.min) {
110 stats.min = value;
111 }
112 const num = +value;
113 if (!isNaN(num)) {
114 sum += num;
115 }
116 if (column.type === 'string' && !stats.hasColorData && isColor(value)) {
117 stats.hasColorData = true;
118 }
119 }
120 if (column.quantitative) {
121 stats.mean = data.length > 0 && (sum / data.length);
122 stats.hasNegative = detectNegative(column, data);
123 if (column.type === 'integer') {
124 stats.isSequential = detectSequentialColumn(column, data);
125 }
126 }
127 stats.distinctValueCount = Object.keys(distinctMap).length;
128 return stats;
129}
130
131function detectNegative(column: Column, data: object[]) {
132 for (let i = 1; i < data.length; i++) {

Callers 2

inferAllFunction · 0.70

Calls 3

isColorFunction · 0.70
detectNegativeFunction · 0.70
detectSequentialColumnFunction · 0.70

Tested by

no test coverage detected