@adobe/rum-distiller
Advanced tools
Comparing version 1.13.0 to 1.13.1
@@ -0,1 +1,9 @@ | ||
## [1.13.1](https://github.com/adobe/rum-distiller/compare/v1.13.0...v1.13.1) (2024-12-16) | ||
### Bug Fixes | ||
* **distiller:** harden aggregates against call stack size overflow ([978ef12](https://github.com/adobe/rum-distiller/commit/978ef1297c364ede71b1ff89c23def3c790b936d)) | ||
* **stats:** avoid overflow in confidence interval calculation ([0f73c9a](https://github.com/adobe/rum-distiller/commit/0f73c9aa683cbf3a25eab943b5bd2b51ffa9930f)) | ||
# [1.13.0](https://github.com/adobe/rum-distiller/compare/v1.12.0...v1.13.0) (2024-12-06) | ||
@@ -2,0 +10,0 @@ |
@@ -12,8 +12,9 @@ /* | ||
*/ | ||
/* eslint-disable max-classes-per-file */ | ||
/* | ||
* @module distiller | ||
* This module is another service worker, which will handle the number crunching, i.e. | ||
* filtering, aggregating, and summarizing the data. | ||
*/ | ||
import { producer } from "./utils.js"; | ||
/* eslint-disable max-classes-per-file */ | ||
import { urlProducer } from './utils.js'; | ||
/** | ||
@@ -109,7 +110,7 @@ * @typedef {Object} RawEvent - a raw RUM event | ||
get min() { | ||
return Math.min(...this.values); | ||
return this.values.reduce((min, val) => Math.min(min, val), Infinity); | ||
} | ||
get max() { | ||
return Math.max(...this.values); | ||
return this.values.reduce((max, val) => Math.max(max, val), -Infinity); | ||
} | ||
@@ -398,6 +399,9 @@ | ||
* @param {number} clusterOptions.count number of clusters, The default value is log10(nValues) | ||
* @param {function} clusterOptions.producer function that takes the cluster value and returns all possible cluster values | ||
* @param {function} clusterOptions.producer function that takes the cluster value and returns | ||
* all possible cluster values | ||
*/ | ||
addClusterFacet(facetName, baseFacet, { count: clustercount = Math.floor(Math.log10(this.facets[baseFacet].length)), | ||
producer: urlProducer }) { | ||
addClusterFacet(facetName, baseFacet, { | ||
count: clustercount = Math.floor(Math.log10(this.facets[baseFacet].length)), | ||
producer = urlProducer, | ||
}) { | ||
const facetValues = this.facets[baseFacet]; | ||
@@ -408,3 +412,3 @@ | ||
const clusters = producer(facet.value); | ||
clusters.forEach(cluster => { | ||
clusters.forEach((cluster) => { | ||
if (!map.has(cluster)) { | ||
@@ -419,3 +423,5 @@ map.set(cluster, 0); | ||
// Find the most occurring cluster | ||
const [mostOccurringCluster] = [...clusterMap.entries()].sort((a, b) => b[1] - a[1]).map(([cluster]) => cluster); | ||
const [mostOccurringCluster] = [...clusterMap.entries()] | ||
.sort((a, b) => b[1] - a[1]) | ||
.map(([cluster]) => cluster); | ||
@@ -428,12 +434,12 @@ // Calculate the total number of items in the superset cluster | ||
const { clusterMap, mostOccurringCluster, totalItemsInSupersetCluster } = createClusterMap(); | ||
const { clusterMap } = createClusterMap(); | ||
const sortedClusters = [...clusterMap.entries()] | ||
.sort((a, b) => b[1] - a[1]) | ||
.slice(0, clustercount) | ||
.map(([cluster]) => cluster); | ||
.sort((a, b) => b[1] - a[1]) | ||
.slice(0, clustercount) | ||
.map(([cluster]) => cluster); | ||
this.addFacet(facetName, (bundle) => { | ||
const facetMatch = facetValues.find(f => f.entries.some(e => e.id === bundle.id)); | ||
const clusters = producer(facetMatch.value); | ||
return [ facetMatch, ...clusters.filter(cluster => sortedClusters.includes(cluster)) ]; | ||
const facetMatch = facetValues.find((f) => f.entries.some((e) => e.id === bundle.id)); | ||
const clusters = producer(facetMatch.value); | ||
return [facetMatch, ...clusters.filter((cluster) => sortedClusters.includes(cluster))]; | ||
}); | ||
@@ -440,0 +446,0 @@ } |
@@ -196,3 +196,3 @@ /* | ||
}), | ||
}; | ||
}; | ||
@@ -199,0 +199,0 @@ /** |
{ | ||
"name": "@adobe/rum-distiller", | ||
"version": "1.13.0", | ||
"version": "1.13.1", | ||
"scripts": { | ||
@@ -5,0 +5,0 @@ "test": "node --test --experimental-test-coverage --test-reporter=lcov --test-reporter-destination=lcov.info --test-reporter=spec --test-reporter-destination=stdout --test-reporter=junit --test-reporter-destination=junit.xml", |
15
stats.js
@@ -218,8 +218,11 @@ /* | ||
const minStr = min.toPrecision(`${min}`.length); | ||
const common = Math.min(maxStr.split('').reduce((acc, digit, i) => { | ||
if (digit === minStr[i]) { | ||
return acc + 1; | ||
} | ||
return acc; | ||
}, 0), Number.isNaN(maxPrecision) ? Infinity : maxPrecision); | ||
const common = Math.min( | ||
maxStr.length > 0 ? [...maxStr].reduce((acc, digit, i) => { | ||
if (digit === minStr[i]) { | ||
return acc + 1; | ||
} | ||
return acc; | ||
}, 0) : 0, | ||
Number.isNaN(maxPrecision) ? Infinity : maxPrecision, | ||
); | ||
const precision = Math.max( | ||
@@ -226,0 +229,0 @@ Math.min(2, Number.isNaN(maxPrecision) ? Infinity : maxPrecision), |
@@ -452,2 +452,4 @@ /* | ||
assert.equal(totals.clickcount.mean, 0.5); | ||
assert.equal(totals.clickcount.min, 0); | ||
assert.equal(totals.clickcount.max, 1); | ||
}); | ||
@@ -826,3 +828,3 @@ | ||
describe('DataChunks.hasConversion', () => { | ||
const chunks = [ | ||
const testChunks = [ | ||
{ | ||
@@ -892,3 +894,3 @@ date: '2024-05-06', | ||
const d = new DataChunks(); | ||
d.load(chunks); | ||
d.load(testChunks); | ||
@@ -912,3 +914,3 @@ const spec = { | ||
const d = new DataChunks(); | ||
d.load(chunks); | ||
d.load(testChunks); | ||
@@ -944,3 +946,3 @@ const spec = { | ||
d.addClusterFacet('urlCluster', 'url', { | ||
count: Math.log10(d.facets.url.length), | ||
count: Math.log10(d.facets.url.length), | ||
}); | ||
@@ -962,3 +964,3 @@ | ||
d.addClusterFacet('urlCluster', 'url', { | ||
count: Math.log10(d.facets.url.length), | ||
count: Math.log10(d.facets.url.length), | ||
}); | ||
@@ -981,3 +983,3 @@ | ||
d.addClusterFacet('urlCluster', 'url', { | ||
count, | ||
count, | ||
}); | ||
@@ -998,3 +1000,3 @@ | ||
d.addClusterFacet('urlCluster', 'url', { | ||
count: Math.log10(d.facets.url.length), | ||
count: Math.log10(d.facets.url.length), | ||
}); | ||
@@ -1008,2 +1010,2 @@ | ||
}); | ||
}); | ||
}); |
@@ -240,3 +240,3 @@ /* | ||
export function producer(url) { | ||
export function urlProducer(url) { | ||
const path = new URL(url).pathname; | ||
@@ -250,8 +250,8 @@ return path | ||
...acc.length ? [acc[acc.length - 1].split('/').slice(1)] : [], | ||
part | ||
part, | ||
] | ||
.flat() | ||
.join('/') | ||
.padStart(part.length + 1, '/') | ||
.padStart(part.length + 1, '/'), | ||
], []); | ||
} |
2905829
90945