Skip to content

Commit

Permalink
passing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
zeke committed Jan 16, 2018
1 parent 5d1bf7c commit ecbe0d2
Show file tree
Hide file tree
Showing 76 changed files with 89 additions and 499 deletions.
Binary file modified db/000045.ldb
Binary file not shown.
Binary file modified db/000046.ldb
Binary file not shown.
Binary file added db/000051.ldb
Binary file not shown.
Binary file added db/000084.ldb
Binary file not shown.
Binary file added db/000085.ldb
Binary file not shown.
Binary file added db/000086.ldb
Binary file not shown.
Binary file added db/000087.ldb
Binary file not shown.
Binary file added db/000088.ldb
Binary file not shown.
Binary file removed db/000091.ldb
Binary file not shown.
Binary file removed db/000101.ldb
Binary file not shown.
Binary file removed db/000112.ldb
Binary file not shown.
Binary file added db/000122.ldb
Binary file not shown.
Binary file removed db/000123.ldb
Binary file not shown.
Binary file added db/000132.ldb
Binary file not shown.
Binary file added db/000133.ldb
Binary file not shown.
Binary file modified db/000134.ldb
Binary file not shown.
Binary file added db/000135.ldb
Binary file not shown.
Binary file added db/000136.ldb
Binary file not shown.
Binary file added db/000137.ldb
Binary file not shown.
Binary file removed db/000138.ldb
Binary file not shown.
Binary file removed db/000139.ldb
Binary file not shown.
Binary file removed db/000140.ldb
Binary file not shown.
Binary file removed db/000141.ldb
Binary file not shown.
Binary file removed db/000142.ldb
Binary file not shown.
Binary file removed db/000176.ldb
Binary file not shown.
Binary file added db/000178.ldb
Binary file not shown.
Binary file removed db/000180.ldb
Binary file not shown.
Binary file removed db/000181.ldb
Binary file not shown.
Binary file removed db/000182.ldb
Binary file not shown.
Binary file removed db/000183.ldb
Binary file not shown.
Binary file removed db/000184.ldb
Binary file not shown.
Binary file added db/000189.ldb
Binary file not shown.
Binary file added db/000196.ldb
Binary file not shown.
Binary file added db/000197.ldb
Binary file not shown.
Binary file added db/000198.ldb
Binary file not shown.
Binary file added db/000199.ldb
Binary file not shown.
Binary file added db/000200.ldb
Binary file not shown.
Binary file added db/000201.ldb
Binary file not shown.
Binary file removed db/000218.ldb
Binary file not shown.
Binary file removed db/000225.ldb
Binary file not shown.
Binary file removed db/000226.ldb
Binary file not shown.
Binary file removed db/000227.ldb
Binary file not shown.
Binary file removed db/000228.ldb
Binary file not shown.
Binary file removed db/000229.ldb
Binary file not shown.
Binary file removed db/000230.ldb
Binary file not shown.
Binary file removed db/000231.ldb
Binary file not shown.
Binary file removed db/000233.ldb
Binary file not shown.
Binary file added db/000242.ldb
Binary file not shown.
Binary file added db/000252.ldb
Binary file not shown.
Binary file added db/000262.ldb
Binary file not shown.
Binary file added db/000263.ldb
Binary file not shown.
Binary file added db/000264.ldb
Binary file not shown.
Binary file added db/000265.ldb
Binary file not shown.
Binary file added db/000266.ldb
Binary file not shown.
Binary file added db/000267.ldb
Binary file not shown.
Binary file added db/000268.ldb
Binary file not shown.
Binary file added db/000270.ldb
Binary file not shown.
Binary file added db/000272.ldb
Binary file not shown.
Binary file added db/000274.ldb
Binary file not shown.
Binary file added db/000276.ldb
Binary file not shown.
Binary file added db/000278.ldb
Binary file not shown.
Binary file added db/000280.ldb
Binary file not shown.
Binary file added db/000282.ldb
Binary file not shown.
Binary file added db/000284.ldb
Binary file not shown.
Binary file added db/000286.ldb
Binary file not shown.
File renamed without changes.
2 changes: 1 addition & 1 deletion db/CURRENT
Original file line number Diff line number Diff line change
@@ -1 +1 @@
MANIFEST-000232
MANIFEST-000296
15 changes: 3 additions & 12 deletions db/LOG
Original file line number Diff line number Diff line change
@@ -1,12 +1,3 @@
2018/01/15-12:39:49.619498 70000a01a000 Recovering log #223
2018/01/15-12:39:49.627377 70000a01a000 Level-0 table #233: started
2018/01/15-12:39:49.634932 70000a01a000 Level-0 table #233: 401226 bytes OK
2018/01/15-12:39:49.636255 70000a01a000 Delete type=2 #5
2018/01/15-12:39:49.636502 70000a01a000 Delete type=2 #16
2018/01/15-12:39:49.637256 70000a01a000 Delete type=2 #17
2018/01/15-12:39:49.637585 70000a01a000 Delete type=2 #18
2018/01/15-12:39:49.638321 70000a01a000 Delete type=2 #19
2018/01/15-12:39:49.638411 70000a01a000 Delete type=2 #21
2018/01/15-12:39:49.638969 70000a01a000 Delete type=2 #23
2018/01/15-12:39:49.639074 70000a01a000 Delete type=0 #223
2018/01/15-12:39:49.639347 70000a01a000 Delete type=3 #22
2018/01/15-21:07:11.409573 700005565000 Recovering log #295
2018/01/15-21:07:11.412481 700005565000 Delete type=0 #295
2018/01/15-21:07:11.412591 700005565000 Delete type=3 #294
473 changes: 3 additions & 470 deletions db/LOG.old

Large diffs are not rendered by default.

Binary file removed db/MANIFEST-000232
Binary file not shown.
Binary file added db/MANIFEST-000296
Binary file not shown.
16 changes: 16 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const path = require('path')
const db = require('level')(path.join(__dirname, 'db'))

module.exports = {
get: async (key) => {
const data = await db.get(key)
if (!data) return null
return JSON.parse(data)
},

set: async (key, value) => {
await db.set(key, JSON.stringify(value, null, 2))
},

db: db
}
8 changes: 8 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,15 @@
"license": "MIT",
"devDependencies": {
"all-the-package-names": "^1.3440.0",
"chai": "^4.1.2",
"chalk": "^2.3.0",
"is-number": "^4.0.0",
"level": "^2.1.1",
"lodash": "^4.17.4",
"mocha": "^4.1.0",
"urlencode": "^1.1.0"
},
"scripts": {
"test": "mocha"
}
}
32 changes: 17 additions & 15 deletions populate.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,29 @@

const db = require('level')('./db')
const fs = require('fs')
const path = require('path')
const urlencode = require('urlencode')
const {gray, yellow} = require('chalk')
const {sum} = require('lodash')

let extant = 0
let nonexistent = 0
db.createKeyStream()
.on('data', async (name) => {
const dataFile = path.join(__dirname, '../sourceranks/data', urlencode(name) + '.json')
if (fs.existsSync(dataFile)) {
await saveRank(name, dataFile)
console.log(dataFile, 'exists')
extant++
let data = {}
if (fs.existsSync(dataFile)) {
const scores = require(dataFile)
data = Object.assign({}, data, {
scores: scores,
total: sum(Object.values(scores))
})
process.stdout.write(gray('x'))
} else {
nonexistent++
console.log(dataFile, 'DOES NOT EXIST')
data.notFound = true
process.stdout.write(yellow('x'))
}

data.updatedAt = new Date()
await db.put(name, JSON.stringify(data, null, 2))
})
.on('end', () => {
console.log('done', extant, nonexistent)
})

async function saveRank (name, dataFile) {
db.put(name, JSON.stringify(require(dataFile), null, 2))
}
console.log('done')
})
8 changes: 7 additions & 1 deletion seed.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
const db = require('level')('./db')
const names = require('all-the-package-names')
const {chain} = require('lodash')
const isNumber = require('is-number')
const names = chain(require('all-the-package-names'))
.map(name => name.trim())
.filter(name => !isNumber(name))
.uniq()
.value()

for (i = 0; i < names.length; i++) {
const name = names[i]
Expand Down
34 changes: 34 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
require('chai').should()

const {describe, it} = require('mocha')
const test = it
const sourceranks = require('..')

describe('sourcerank-data', function () {
this.timeout(120 * 1000)

test('.get()', async () => {
const express = await sourceranks.get('express')
express.should.be.an('object')
express.total.should.be.above(25)
})

it('exposes a streamable leveldb instance', (done) => {
let bad = 0
let good = 0
var stream = sourceranks.db.createReadStream()
.on('data', ({key, value}) => {
value = JSON.parse(value)
if (value.scores && value.total) {
good++
} else {
bad++
}
})
.on('end', () => {
good.should.be.above(500 * 1000)
bad.should.be.above(10 * 1000).and.below(20 * 1000)
done()
})
})
})

0 comments on commit ecbe0d2

Please sign in to comment.