Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 3ba0130

Browse files
committedJan 27, 2021
poc-recommender-sub-2
1 parent 28f06e3 commit 3ba0130

File tree

2 files changed

+3791
-1
lines changed

2 files changed

+3791
-1
lines changed
 

‎src/services/__mocks__/data/recommended-challenges.json

Lines changed: 3747 additions & 0 deletions
Large diffs are not rendered by default.

‎src/services/challenges.js

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { COMPETITION_TRACKS, getApiResponsePayload } from '../utils/tc';
1414
import { getApi } from './api';
1515
import { getService as getMembersService } from './members';
1616
import { getService as getSubmissionsService } from './submissions';
17+
import mockRecommendedChallenges from './__mocks__/data/recommended-challenges.json';
1718

1819
export function getFilterUrl(backendFilter, frontFilter) {
1920
const ff = _.clone(frontFilter);
@@ -185,6 +186,7 @@ class ChallengesService {
185186
totalCount: res.headers ? res.headers.get('x-total') : 0,
186187
meta: {
187188
allChallengesCount: res.headers ? res.headers.get('x-total') : 0,
189+
allRecommendedChallengesCount: 0,
188190
myChallengesCount: 0,
189191
ongoingChallengesCount: 0,
190192
openChallengesCount: 0,
@@ -474,12 +476,21 @@ class ChallengesService {
474476
* @return {Promise} Resolves to the array of subtrack names.
475477
*/
476478
getChallengeTypes() {
479+
const recommended = {
480+
id: 'e06b074d-43c2-4e7e-9cd3-c43e13d51b40',
481+
name: 'Recommended',
482+
description: "Available challenges that match competitor's skills",
483+
isActive: true,
484+
isTask: false,
485+
abbreviation: 'REC',
486+
};
487+
477488
return this.private.apiV5.get('/challenge-types')
478489
.then(res => (res.ok ? res.json() : new Error(res.statusText)))
479490
.then(res => (
480491
res.message
481492
? new Error(res.message)
482-
: res
493+
: [...res, recommended]
483494
));
484495
}
485496

@@ -527,6 +538,38 @@ class ChallengesService {
527538
});
528539
}
529540

541+
/**
542+
* TODO: Integrate with real API.
543+
* Gets recommended challenges.
544+
* @param {Object} sort
545+
* @param {Object} filter
546+
* @return {Promise} Resolves to the api response.
547+
*/
548+
async getRecommendedChallenges(sort, filter) {
549+
let sortedChallenges = [];
550+
const tracks = [];
551+
if (filter.tracks.DS) tracks.push('Data Science');
552+
if (filter.tracks.Des) tracks.push('Design');
553+
if (filter.tracks.Dev) tracks.push('Development');
554+
if (filter.tracks.QA) tracks.push('Quality Assurance');
555+
if (filter.openForRegistration === 'best-match' || sort.openForRegistration === {}) {
556+
sortedChallenges = _.sortBy(mockRecommendedChallenges, ['matchScore']);
557+
} else {
558+
sortedChallenges = _.sortBy(mockRecommendedChallenges, [sort.openForRegistration]);
559+
}
560+
561+
const filteredChallenges = sortedChallenges.filter(item => tracks.includes(item.track));
562+
const mockResponse = _.clone(this.private.tokenV3 ? filteredChallenges : []);
563+
564+
const sleep = m => new Promise(r => setTimeout(r, m));
565+
await sleep(1000);
566+
567+
return Promise.resolve({
568+
challenges: mockResponse,
569+
meta: mockResponse.length,
570+
});
571+
}
572+
530573
/**
531574
* Gets SRM matches.
532575
* @param {Object} params

0 commit comments

Comments
 (0)
Please sign in to comment.