MCPcopy Create free account
hub / github.com/microsoft/SandDance / getStats

Function getStats

docs/app/js/sanddance-app.js:2101–2127  ·  view source on GitHub ↗
(data, column)

Source from the content-addressed store, hash-verified

2099 column.isColorData = true;
2100}
2101function getStats(data, column) {
2102 const distinctMap = {};
2103 const stats = {
2104 distinctValueCount: null,
2105 max: null,
2106 mean: null,
2107 min: null
2108 };
2109 let sum = 0;
2110 for(let i = 0; i < data.length; i++){
2111 let row = data[i];
2112 let value = row[column.name];
2113 distinctMap[value] = true;
2114 if (stats.max === null || value > stats.max) stats.max = value;
2115 if (stats.min === null || value < stats.min) stats.min = value;
2116 let num = +value;
2117 if (!isNaN(num)) sum += num;
2118 if (column.type === "string" && !stats.hasColorData && isColor(value)) stats.hasColorData = true;
2119 }
2120 if (column.quantitative) {
2121 stats.mean = data.length > 0 && sum / data.length;
2122 stats.hasNegative = detectNegative(column, data);
2123 if (column.type === "integer") stats.isSequential = detectSequentialColumn(column, data);
2124 }
2125 stats.distinctValueCount = Object.keys(distinctMap).length;
2126 return stats;
2127}
2128function detectNegative(column, data) {
2129 for(let i = 1; i < data.length; i++){
2130 if (data[i][column.name] < 0) return true;

Callers 1

inferAllFunction · 0.70

Calls 3

isColorFunction · 0.70
detectNegativeFunction · 0.70
detectSequentialColumnFunction · 0.70

Tested by

no test coverage detected