Skip to content

Commit

Permalink
[Shaffi] Identifying pair names with fuzzy matching
Browse files Browse the repository at this point in the history
  • Loading branch information
Mohammed Shaffi committed Jan 26, 2017
1 parent 1a90d24 commit f55a1ef
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"license": "ISC",
"dependencies": {
"botkit": "^0.4.9",
"fuzzy-matching": "^0.4.3",
"jfs": "^0.2.6"
}
}
16 changes: 13 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ if (!process.env.token) {

var Store = require("jfs");
var db = new Store("data");

var FuzzyMatching = require('fuzzy-matching');

var personList = null;

var pairingStore = {};

db.get('pairingStore', function (err, data) {
Expand All @@ -14,6 +17,7 @@ db.get('pairingStore', function (err, data) {
return;
}
pairingStore = data;
personList = new FuzzyMatching(Object.keys(data));
});

var Botkit = require('Botkit');
Expand Down Expand Up @@ -95,7 +99,7 @@ const getPairNames = (commitMessage, commitPusher) => {
let regexForNamesWithColon = '([a-zA-Z]*)(?:\/)?([a-zA-Z]*)\\s?:.*$';
let regexForNamesWithHyphen = '([a-zA-Z]*)(?:\/)?([a-zA-Z]*).?\\-\\s.*$';
let regexText = new RegExp(`${regexForNamesWithinSquareBraces}|${regexForNamesWithColon}|${regexForNamesWithHyphen}`);

let match = regexText.exec(commitMessage)
if (match) {
match.shift();
Expand Down Expand Up @@ -132,10 +136,16 @@ const updatePairInfo = (pair, pairInfo) => {
if (!isAlreadyUpdatedForCurrentDay(pairInfo))
pairInfo.count += 1;
} else {
pairInfo = pairingStore[pair.toString()] = {
let fuzzyResult = [
personList.get(pair.toString(), { maxChanges: 4 }),
personList.get(`${pair[1]},${pair[0]}`, { maxChanges: 4 })
];
let nearestNameMatch = fuzzyResult.reduce((prev, current) => (prev.distance > current.distance) ? prev : current);
pairInfo = pairingStore[nearestNameMatch.value || pair.toString()] = {
count: 1,
timeStamp: new Date().getTime()
}
personList = new FuzzyMatching(Object.keys(pairingStore));
}
return pairInfo;
}
Expand Down

0 comments on commit f55a1ef

Please sign in to comment.