-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
72 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/** | ||
* Reads csv file of watch events line by line | ||
*/ | ||
var fs = require('fs'); | ||
var csv = require('csv-parse'); | ||
module.exports = forEachLine; | ||
|
||
function forEachLine(fileName, cb, done) { | ||
var inputFile = fs.createReadStream(fileName); | ||
var parser = csv(); | ||
var processed = 0; | ||
|
||
parser.on('readable', processLine); | ||
parser.on('end', function() { | ||
done(); | ||
}); | ||
|
||
inputFile.pipe(parser); | ||
|
||
function processLine() { | ||
var line = parser.read(); | ||
if (!line) return; | ||
var user = line[0]; | ||
var repo = line[1]; | ||
|
||
// we want to fix twitter. Normally we should not care about it | ||
// but in this it has to be changed, since it is so popular | ||
if (user === 'twitter' && repo === 'bootstrap') { | ||
user = 'twbs'; | ||
} | ||
|
||
if (!repo || repo.indexOf('/') <= 0) return; // ignore invalid data. | ||
|
||
cb(user, repo); | ||
processed += 1; | ||
if (processed % 100000 === 0) console.log('Read ' + processed + ' lines of ' + fileName); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/** | ||
* loads set of unique repositories within csv file | ||
*/ | ||
module.exports = loadRepositories; | ||
var forEachLine = require('./for-each-line-in-csv.js'); | ||
|
||
function loadRepositories(fileName, doneCb) { | ||
var repos = new Set(); | ||
|
||
forEachLine(fileName, processLine, done); | ||
|
||
function processLine(user, repo) { | ||
repos.add(user + '/' + repo); | ||
} | ||
|
||
function done() { | ||
doneCb(repos); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters