Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Calculate full histograms for better accuracy, fix off by a factor of…

… 1/2 error in code offsets
  • Loading branch information...
commit 5a164d92e40effc1df2fd379715bc48f3e25ae0e 1 parent edf0cb8
John Hurliman authored

Showing 2 changed files with 16 additions and 27 deletions. Show diff stats Hide diff stats

  1. +9 15 controllers/debug.js
  2. +7 12 controllers/fingerprinter.js
24 controllers/debug.js
@@ -104,7 +104,7 @@ exports.debugQuery = function(req, res) {
104 104 */
105 105 function getContributors(fp, match) {
106 106 var MAX_DIST = 32767;
107   - var i, j;
  107 + var i, j, k;
108 108
109 109 match.contributors = [];
110 110
@@ -115,7 +115,7 @@ function getContributors(fp, match) {
115 115 var keys = Object.keys(match.histogram);
116 116 var array = new Array(keys.length);
117 117 for (i = 0; i < keys.length; i++)
118   - array[i] = [ keys[i], match.histogram[keys[i]] ];
  118 + array[i] = [ parseInt(keys[i], 10), match.histogram[keys[i]] ];
119 119 array.sort(function(a, b) { return b[1] - a[1]; });
120 120 var topOffsets = array.splice(0, 2);
121 121
@@ -124,26 +124,20 @@ function getContributors(fp, match) {
124 124 // Iterate over each {code,time} tuple in the query
125 125 for (i = 0; i < fp.codes.length; i++) {
126 126 var code = fp.codes[i];
127   - var time = Math.floor(fp.times[i] / fingerprinter.MATCH_SLOP);
128   - var minDist = MAX_DIST;
  127 + var time = Math.floor(fp.times[i] / fingerprinter.MATCH_SLOP) * fingerprinter.MATCH_SLOP;
129 128
130   - // Find the distance of the nearest instance of this code in the match
131 129 var matchTimes = matchCodesToTimes[code];
132 130 if (matchTimes) {
133 131 for (j = 0; j < matchTimes.length; j++) {
134 132 var dist = Math.abs(time - matchTimes[j]);
135   - if (dist < minDist)
136   - minDist = dist;
137   - }
138   -
139   - if (minDist < MAX_DIST) {
140   - // If minDist is in topOffsets, add a contributor object
141   - for (j = 0; j < topOffsets.length; j++) {
142   - if (minDist === parseInt(topOffsets[j][0], 10)) {
  133 +
  134 + // If dist is in topOffsets, add a contributor object
  135 + for (k = 0; k < topOffsets.length; k++) {
  136 + if (dist === topOffsets[k][0]) {
143 137 match.contributors.push({
144 138 code: code,
145   - time: time,
146   - dist: minDist
  139 + time: matchTimes[j],
  140 + dist: dist
147 141 });
148 142 break;
149 143 }
19 controllers/fingerprinter.js
@@ -230,7 +230,7 @@ function getCodesToTimes(match, slop) {
230 230
231 231 for (var i = 0; i < match.codes.length; i++) {
232 232 var code = match.codes[i];
233   - var time = Math.floor(match.times[i] / slop);
  233 + var time = Math.floor(match.times[i] / slop) * slop;
234 234
235 235 if (codesToTimes[code] === undefined)
236 236 codesToTimes[code] = [];
@@ -258,23 +258,18 @@ function getActualScore(fp, match, threshold, slop) {
258 258 // Iterate over each {code,time} tuple in the query
259 259 for (i = 0; i < fp.codes.length; i++) {
260 260 var code = fp.codes[i];
261   - var time = Math.floor(fp.times[i] / slop);
  261 + var time = Math.floor(fp.times[i] / slop) * slop;
262 262 var minDist = MAX_DIST;
263   -
264   - // Find the distance of the nearest instance of this code in the match
  263 +
265 264 var matchTimes = matchCodesToTimes[code];
266 265 if (matchTimes) {
267 266 for (j = 0; j < matchTimes.length; j++) {
268 267 var dist = Math.abs(time - matchTimes[j]);
269   - if (dist < minDist)
270   - minDist = dist;
271   - }
272   -
273   - if (minDist < MAX_DIST) {
  268 +
274 269 // Increment the histogram bucket for this distance
275   - if (timeDiffs[minDist] === undefined)
276   - timeDiffs[minDist] = 0;
277   - timeDiffs[minDist]++;
  270 + if (timeDiffs[dist] === undefined)
  271 + timeDiffs[dist] = 0;
  272 + timeDiffs[dist]++;
278 273 }
279 274 }
280 275 }

0 comments on commit 5a164d9

Please sign in to comment.
Something went wrong with that request. Please try again.