Skip to content

Commit

Permalink
fix: use latest dataset for building entity files
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickhulce committed Jul 25, 2019
1 parent d9d9437 commit 7fb18ae
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
7 changes: 5 additions & 2 deletions bin/build-entity-json-files.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ const _ = require('lodash')
const fs = require('fs')
const path = require('path')
const JSON5 = require('json5')
const {importMergedData} = require('./shared/merge-entity-origin-data')
const {
importMergedData,
getEntityDatasetsMostRecentFirst,
} = require('./shared/merge-entity-origin-data')

const DIST_DIR = path.join(__dirname, '../dist')
const DATA_DIR = path.join(__dirname, '../data')
Expand All @@ -16,7 +19,7 @@ function cleanStatsFromEntity(entity) {
const sourceEntities = JSON5.parse(fs.readFileSync(`${DATA_DIR}/entities.json5`, 'utf8'))
fs.writeFileSync(`${DIST_DIR}/entities.json`, JSON.stringify(sourceEntities))

const httpArchiveData = importMergedData('2019-04-01-entity-scripting.json')
const httpArchiveData = importMergedData(getEntityDatasetsMostRecentFirst()[0])
const {getEntity} = require('../lib/index.js') // IMPORTANT: require this after entities have been written
const entityExecutionStats = _(httpArchiveData)
.groupBy(({domain}) => {
Expand Down
8 changes: 8 additions & 0 deletions bin/shared/merge-entity-origin-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ function importDataset(filename) {
}

module.exports = {
importDataset,
getEntityDatasetsMostRecentFirst() {
return fs
.readdirSync(DATA_FOLDER)
.filter(f => f.includes('entity-scripting'))
.sort()
.reverse()
},
importMergedData(entityFilename) {
const originFilename = entityFilename.replace('entity-scripting', 'origin-scripting')

Expand Down
12 changes: 6 additions & 6 deletions lib/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ describe('getEntity', () => {
it('works for direct domain usage', () => {
expect(getEntity('https://js.connect.facebook.net/lib.js')).toMatchInlineSnapshot(`
Object {
"averageExecutionTime": 142.24502022559832,
"averageExecutionTime": 161.0291502603836,
"categories": Array [
"social",
],
Expand All @@ -60,16 +60,16 @@ Object {
],
"homepage": "https://www.facebook.com",
"name": "Facebook",
"totalExecutionTime": 288666212,
"totalOccurrences": 2029359,
"totalExecutionTime": 578108820,
"totalOccurrences": 3590088,
}
`)
})

it('works for inferred domain usage', () => {
expect(getEntity('https://unknown.typekit.net/fonts.css')).toMatchInlineSnapshot(`
Object {
"averageExecutionTime": 91.44604519774012,
"averageExecutionTime": 93.6581576026637,
"categories": Array [
"cdn",
],
Expand All @@ -84,8 +84,8 @@ Object {
],
"homepage": "https://fonts.adobe.com/",
"name": "Adobe TypeKit",
"totalExecutionTime": 971157,
"totalOccurrences": 10620,
"totalExecutionTime": 1940878,
"totalOccurrences": 20723,
}
`)
})
Expand Down

0 comments on commit 7fb18ae

Please sign in to comment.