Skip to content

Commit

Permalink
fix: correct execution stats
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickhulce committed Apr 19, 2019
1 parent 3ec7612 commit 241cb96
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
17 changes: 11 additions & 6 deletions bin/build-entity-json-files.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,16 @@ fs.writeFileSync(`${DIST_DIR}/entities.json`, JSON.stringify(sourceEntities))
const httpArchiveData = require('../data/2019-03-01-origin-scripting.json')
const {getEntity} = require('../lib/index.js') // IMPORTANT: require this after entities have been written
const entityExecutionStats = _(httpArchiveData)
.groupBy(({origin}) => getEntity(origin))
.mapValues(dataset => ({
totalExecutionTime: Math.round(_.sum(dataset.map(x => Number(x.totalExecutionTime)))),
totalOccurrences: Math.round(_.sum(dataset.map(x => Number(x.totalOccurrences)))),
}))
.groupBy(({origin}) => {
const entity = getEntity(origin)
return entity && entity.name
})
.mapValues(dataset => {
return {
totalExecutionTime: Math.round(_.sum(dataset.map(x => Number(x.totalExecutionTime)))),
totalOccurrences: Math.round(_.sum(dataset.map(x => Number(x.totalOccurrences)))),
}
})
.value()

const entitiesInHTTPArchive = _(httpArchiveData)
Expand All @@ -35,7 +40,7 @@ const entitiesInHTTPArchive = _(httpArchiveData)
.value()

for (const entity of entitiesInHTTPArchive) {
Object.assign(entity, entityExecutionStats[entity])
Object.assign(entity, entityExecutionStats[entity.name])
}

fs.writeFileSync(`${DIST_DIR}/entities.json`, JSON.stringify(sourceEntities))
Expand Down
12 changes: 6 additions & 6 deletions lib/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ describe('getEntity', () => {
it('works for direct domain usage', () => {
expect(getEntity('https://js.connect.facebook.net/lib.js')).toMatchInlineSnapshot(`
Object {
"averageExecutionTime": 233.43429691479307,
"averageExecutionTime": 119.80635511714381,
"categories": Array [
"social",
],
Expand Down Expand Up @@ -54,16 +54,16 @@ Object {
],
"homepage": "https://www.facebook.com",
"name": "Facebook",
"totalExecutionTime": 2249323397,
"totalOccurrences": 9635788,
"totalExecutionTime": 132167256,
"totalOccurrences": 1103174,
}
`)
})

it('works for inferred domain usage', () => {
expect(getEntity('https://unknown.typekit.net/fonts.css')).toMatchInlineSnapshot(`
Object {
"averageExecutionTime": 233.43429691479307,
"averageExecutionTime": 95.1277705345502,
"categories": Array [
"library",
],
Expand All @@ -75,8 +75,8 @@ Object {
],
"homepage": "https://fonts.adobe.com/",
"name": "Adobe TypeKit",
"totalExecutionTime": 2249323397,
"totalOccurrences": 9635788,
"totalExecutionTime": 656667,
"totalOccurrences": 6903,
}
`)
})
Expand Down

0 comments on commit 241cb96

Please sign in to comment.