Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

518 fix ap #535

Merged
merged 11 commits into from
Jul 18, 2022
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