Skip to content

WIP: Recommender final fix api #301

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

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"lint:js": "./node_modules/.bin/eslint --ext .js,.jsx .",
"test": "npm run lint && npm run jest"
},
"version": "1000.26.5",
"version": "1.1.6",
"dependencies": {
"auth0-js": "^6.8.4",
"config": "^3.2.0",
Expand Down
51 changes: 51 additions & 0 deletions src/services/challenges.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import { getApi } from './api';
import { getService as getMembersService } from './members';
import { getService as getSubmissionsService } from './submissions';

const MAX_PER_PAGE = 300;

export function getFilterUrl(backendFilter, frontFilter) {
const ff = _.clone(frontFilter);
// eslint-disable-next-line object-curly-newline
Expand Down Expand Up @@ -185,6 +187,7 @@ class ChallengesService {
totalCount: res.headers ? res.headers.get('x-total') : 0,
meta: {
allChallengesCount: res.headers ? res.headers.get('x-total') : 0,
allRecommendedChallengesCount: 0,
myChallengesCount: 0,
ongoingChallengesCount: 0,
openChallengesCount: 0,
Expand Down Expand Up @@ -527,6 +530,54 @@ class ChallengesService {
});
}

/**
* Gets challenges.
* @param {Object} filters Optional.
* @param {Object} params Optional.
* @param {String} handle user handle
* @return {Promise} Resolves to the api response.
*/
async getRecommendedChallenges(filter, handle) {
filter.frontFilter.per_page = filter.frontFilter.perPage;
delete filter.frontFilter.perPage;

const query = getFilterUrl(filter.backendFilter, filter.frontFilter);

const totalQuery = getFilterUrl(
filter.backendFilter,
{ ...filter.frontFilter, page: 1, perPage: MAX_PER_PAGE },
);

let res = {};
let totalChallengeCount = {};
if (_.some(filter.frontFilter.tracks, val => val)
&& !_.isEqual(filter.frontFilter.types, [])) {
const url = `/recommender-api/${handle}?${query}`;
res = await this.private.apiV5.get(url).then(checkErrorV5);
// Note: Recommender API is not returning X-Total response header.
// Please remove below statement with response get method.
const totalUrl = `/recommender-api/${handle}?${totalQuery}`;
totalChallengeCount = await this.private.apiV5.get(totalUrl).then(checkErrorV5);
}
const challenges = res.result ? res.result.filter(ch => ch.jaccard_index > 0) : [];
const total = totalChallengeCount.result
? totalChallengeCount.result.filter(ch => ch.jaccard_index > 0) : [];

const totalCount = total.length;
return {
challenges,
totalCount,
meta: {
allChallengesCount: totalCount,
allRecommendedChallengesCount: 0,
myChallengesCount: 0,
ongoingChallengesCount: 0,
openChallengesCount: 0,
totalCount,
},
};
}

/**
* Gets SRM matches.
* @param {Object} params
Expand Down