Skip to content

Commit

Permalink
Merge pull request #535 from o19s/518-fix-AP
Browse files Browse the repository at this point in the history
518 fix ap
  • Loading branch information
david-fisher committed Jul 18, 2022
2 parents de6c1a6 + 7a62d21 commit 6fbf749
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 34 deletions.
34 changes: 1 addition & 33 deletions app/assets/javascripts/factories/ScorerFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,42 +10,11 @@
function ScorerFactory($q, $timeout) {
var Scorer = function(data) {
var self = this;
var defaultAlgorithm = [
'// This is the AP@10 formula as an example',
'let k = 10; // @Rank',
'let count = 0;',
'let totalRel = 0;',
'total = 0;',
'// if less than K results, need to reduce K now or final score is too low',
'k = numReturned() < k ? numReturned() : k',
'// for each returned document, calculate precision each time a new',
'// relevant document is added to the ranked list.',
'eachDoc(function(doc, i) {',
'if (hasDocRating(i) && (docRating(i)) > 0) {',
'count++;',
'total += count/(i+1)',
'}',
'}, k);',
'// count up the total number of relevant (not judged) documents',
'eachDocWithRating(function(doc) {',
'if (doc.rating > 0) {',
'totalRel++;',
'}',
'}, bestDocs.length);',
'// AP is the sum of the precision points divided by the total',
'// number of relevant documents',
'const score = total / totalRel;',
'setScore(score);',
].join('\n');

if (angular.isUndefined(data)) {
data = {};
}

if ( angular.isUndefined(data.code) ) {
data.code = defaultAlgorithm;
}

if ( angular.isUndefined(data.scale) ) {
data.scale = ['0', '1'];
data.scaleWithLabels = scaleToScaleWithLabels(data.scale, null);
Expand All @@ -54,7 +23,6 @@
// Attributes
self.code = data.code;
self.colors = scaleToColors(data.scale);
self.defaultAlgorithm = defaultAlgorithm;
self.displayName = setDisplayName(data.name, data.communal);
self.error = false;
self.manualMaxScore = data.manualMaxScore || false;
Expand Down Expand Up @@ -92,7 +60,7 @@
self.getBestRatings = getBestRatings;


var DEFAULT_NUM_DOCS = 10;
const DEFAULT_NUM_DOCS = 10;


// public functions
Expand Down
2 changes: 1 addition & 1 deletion spec/javascripts/angular/services/scorerFactory_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ describe('Service: ScorerFactory', function () {
var mockScorer = {
'scorerId': 1,
'name': 'Scorer 1',
'code': scorerSvc.defaultAlgorithm,
'code': "setScore(99)",
'scale': [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
'owner_id': 1
};
Expand Down

0 comments on commit 6fbf749

Please sign in to comment.