9
9
* OF ANY KIND, either express or implied. See the License for the specific language
10
10
* governing permissions and limitations under the License.
11
11
*/
12
+ /* eslint-disable max-classes-per-file */
12
13
/*
14
+ * @module distiller
13
15
* This module is another service worker, which will handle the number crunching, i.e.
14
16
* filtering, aggregating, and summarizing the data.
15
17
*/
16
- import { producer } from "./utils.js" ;
17
- /* eslint-disable max-classes-per-file */
18
+ import { urlProducer } from './utils.js' ;
18
19
/**
19
20
* @typedef {Object } RawEvent - a raw RUM event
20
21
* @property {string } checkpoint - the name of the event that happened
@@ -105,11 +106,11 @@ class Aggregate {
105
106
}
106
107
107
108
get min ( ) {
108
- return Math . min ( ... this . values ) ;
109
+ return this . values . reduce ( ( min , val ) => Math . min ( min , val ) , Infinity ) ;
109
110
}
110
111
111
112
get max ( ) {
112
- return Math . max ( ... this . values ) ;
113
+ return this . values . reduce ( ( max , val ) => Math . max ( max , val ) , - Infinity ) ;
113
114
}
114
115
115
116
get share ( ) {
@@ -393,16 +394,19 @@ export class DataChunks {
393
394
* @param {string } baseFacet name of the base facet, from which to derive the clusters
394
395
* @param {object } clusterOptions options
395
396
* @param {number } clusterOptions.count number of clusters, The default value is log10(nValues)
396
- * @param {function } clusterOptions.producer function that takes the cluster value and returns all possible cluster values
397
+ * @param {function } clusterOptions.producer function that takes the cluster value and returns
398
+ * all possible cluster values
397
399
*/
398
- addClusterFacet ( facetName , baseFacet , { count : clustercount = Math . floor ( Math . log10 ( this . facets [ baseFacet ] . length ) ) ,
399
- producer : urlProducer } ) {
400
+ addClusterFacet ( facetName , baseFacet , {
401
+ count : clustercount = Math . floor ( Math . log10 ( this . facets [ baseFacet ] . length ) ) ,
402
+ producer = urlProducer ,
403
+ } ) {
400
404
const facetValues = this . facets [ baseFacet ] ;
401
405
402
406
const createClusterMap = ( ) => {
403
407
const clusterMap = facetValues . reduce ( ( map , facet ) => {
404
408
const clusters = producer ( facet . value ) ;
405
- clusters . forEach ( cluster => {
409
+ clusters . forEach ( ( cluster ) => {
406
410
if ( ! map . has ( cluster ) ) {
407
411
map . set ( cluster , 0 ) ;
408
412
}
@@ -412,24 +416,26 @@ export class DataChunks {
412
416
} , new Map ( ) ) ;
413
417
414
418
// Find the most occurring cluster
415
- const [ mostOccurringCluster ] = [ ...clusterMap . entries ( ) ] . sort ( ( a , b ) => b [ 1 ] - a [ 1 ] ) . map ( ( [ cluster ] ) => cluster ) ;
419
+ const [ mostOccurringCluster ] = [ ...clusterMap . entries ( ) ]
420
+ . sort ( ( a , b ) => b [ 1 ] - a [ 1 ] )
421
+ . map ( ( [ cluster ] ) => cluster ) ;
416
422
417
423
// Calculate the total number of items in the superset cluster
418
424
const totalItemsInSupersetCluster = Math . floor ( facetValues . length + clustercount ) ;
419
425
420
426
return { clusterMap, mostOccurringCluster, totalItemsInSupersetCluster } ;
421
427
} ;
422
428
423
- const { clusterMap, mostOccurringCluster , totalItemsInSupersetCluster } = createClusterMap ( ) ;
429
+ const { clusterMap } = createClusterMap ( ) ;
424
430
const sortedClusters = [ ...clusterMap . entries ( ) ]
425
- . sort ( ( a , b ) => b [ 1 ] - a [ 1 ] )
426
- . slice ( 0 , clustercount )
427
- . map ( ( [ cluster ] ) => cluster ) ;
431
+ . sort ( ( a , b ) => b [ 1 ] - a [ 1 ] )
432
+ . slice ( 0 , clustercount )
433
+ . map ( ( [ cluster ] ) => cluster ) ;
428
434
429
435
this . addFacet ( facetName , ( bundle ) => {
430
- const facetMatch = facetValues . find ( f => f . entries . some ( e => e . id === bundle . id ) ) ;
431
- const clusters = producer ( facetMatch . value ) ;
432
- return [ facetMatch , ...clusters . filter ( cluster => sortedClusters . includes ( cluster ) ) ] ;
436
+ const facetMatch = facetValues . find ( ( f ) => f . entries . some ( ( e ) => e . id === bundle . id ) ) ;
437
+ const clusters = producer ( facetMatch . value ) ;
438
+ return [ facetMatch , ...clusters . filter ( ( cluster ) => sortedClusters . includes ( cluster ) ) ] ;
433
439
} ) ;
434
440
}
435
441
0 commit comments