Skip to content
This repository was archived by the owner on Mar 4, 2025. It is now read-only.
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 5e65d0d

Browse files
author
vikasrohit
committedDec 29, 2015
Merge pull request #628 from appirio-tech/feature/sup-2895-placement-fix-f2f-challenges
Feature/sup 2895 placement fix f2f challenges
2 parents 585024e + 8c1e917 commit 5e65d0d

File tree

4 files changed

+506
-16
lines changed

4 files changed

+506
-16
lines changed
 

‎app/services/challenge.service.js

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,8 @@
168168
function processPastSRM(challenge) {
169169
if (Array.isArray(challenge.rounds) && challenge.rounds.length
170170
&& challenge.rounds[0].userSRMDetails) {
171-
challenge.newRating = challenge.rounds[0].userMMDetails.newRating;
172-
challenge.pointTotal = challenge.rounds[0].userMMDetails.pointTotal;
171+
challenge.newRating = challenge.rounds[0].userSRMDetails.newRating;
172+
challenge.finalPoints = challenge.rounds[0].userSRMDetails.finalPoints;
173173
}
174174
}
175175

@@ -180,10 +180,6 @@
180180
// process placement for challenges having winningPlacements array in response
181181
if (Array.isArray(challenge.userDetails.winningPlacements)) {
182182
challenge.highestPlacement = _.min(challenge.userDetails.winningPlacements);
183-
challenge.wonFirst = challenge.highestPlacement == 1;
184-
if (challenge.highestPlacement === 0) {
185-
challenge.highestPlacement = null;
186-
}
187183
}
188184
// process placement for design challenges
189185
if (challenge.track == 'DESIGN' && challenge.userDetails.submissions && challenge.userDetails.submissions.length > 0) {
@@ -192,11 +188,17 @@
192188
challenge.highestPlacement = _.min(challenge.userDetails.submissions.filter(function(submission) {
193189
return submission.type === CONSTANTS.SUBMISSION_TYPE_CONTEST && submission.placement;
194190
}), 'placement').placement;
195-
196-
if (challenge.highestPlacement == 1) {
197-
challenge.wonFirst = true;
198-
}
199191
}
192+
if (challenge.track === 'DEVELOP' && challenge.subTrack === 'FIRST_2_FINISH') {
193+
challenge.highestPlacement = _.min(challenge.userDetails.submissions.filter(function(submission) {
194+
return submission.type === CONSTANTS.SUBMISSION_TYPE_CONTEST
195+
&& submission.status === CONSTANTS.STATUS_ACTIVE && submission.placement;
196+
}), 'placement').placement;
197+
}
198+
if (challenge.highestPlacement === 0) {
199+
challenge.highestPlacement = null;
200+
}
201+
challenge.wonFirst = challenge.highestPlacement == 1;
200202

201203
challenge.userHasSubmitterRole = false;
202204

‎app/services/challenge.service.spec.js

Lines changed: 472 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,476 @@ describe('Challenge Service', function() {
4040
$httpBackend.flush();
4141
});
4242

43+
it('processPastChallenges should process the won DESIGN/WEB_DESIGNS challenge ', function() {
44+
var challenges = [
45+
{
46+
id: 30041345,
47+
name: 'Mock Challenge 1',
48+
track: 'DESIGN',
49+
subTrack: 'WEB_DESIGNS',
50+
userDetails: {
51+
hasUserSubmittedForReview: true,
52+
roles: ['Submitter'],
53+
submissions: [
54+
{
55+
challengeId: 30041345,
56+
id: 12345,
57+
placement: 1,
58+
score: 98.0,
59+
status: 'Active',
60+
type: 'Contest Submission'
61+
},
62+
{
63+
challengeId: 30041345,
64+
id: 12346,
65+
placement: 11,
66+
score: 0.0,
67+
status: 'Failed Review',
68+
type: 'Contest Submission'
69+
},
70+
{
71+
challengeId: 30041345,
72+
id: 12347,
73+
placement: 21,
74+
score: 0.0,
75+
status: 'Completed Without Win',
76+
type: 'Checkpoint Submission'
77+
}
78+
]
79+
}
80+
}
81+
];
82+
ChallengeService.processPastChallenges(challenges);
83+
var challenge = challenges[0];
84+
expect(challenge.highestPlacement).to.exist.to.equal(1);
85+
expect(challenge.wonFirst).to.exist.to.true;
86+
expect(challenge.userStatus).to.exist.to.equal('PASSED_REVIEW');
87+
expect(challenge.userHasSubmitterRole).to.exist.to.true;
88+
});
89+
90+
it('processPastChallenges should process the won DEVELOP/<ANY> challenge ', function() {
91+
var challenges = [
92+
{
93+
id: 30041345,
94+
name: 'Mock Challenge 1',
95+
track: 'DEVELOP',
96+
subTrack: 'CODE',
97+
userDetails: {
98+
hasUserSubmittedForReview: true,
99+
roles: ['Submitter'],
100+
submissions: [
101+
{
102+
challengeId: 30041345,
103+
id: 12345,
104+
placement: 1,
105+
score: 98.0,
106+
status: 'Active',
107+
type: 'Contest Submission'
108+
},
109+
{
110+
challengeId: 30041345,
111+
id: 12346,
112+
placement: 11,
113+
score: 0.0,
114+
status: 'Failed Review',
115+
type: 'Contest Submission'
116+
},
117+
{
118+
challengeId: 30041345,
119+
id: 12347,
120+
placement: 21,
121+
score: 0.0,
122+
status: 'Completed Without Win',
123+
type: 'Checkpoint Submission'
124+
}
125+
],
126+
winningPlacements: [2, 11, 1]
127+
}
128+
129+
}
130+
];
131+
ChallengeService.processPastChallenges(challenges);
132+
var challenge = challenges[0];
133+
expect(challenge.highestPlacement).to.exist.to.equal(1);
134+
expect(challenge.wonFirst).to.exist.to.true;
135+
expect(challenge.userStatus).to.exist.to.equal('PASSED_REVIEW');
136+
expect(challenge.userHasSubmitterRole).to.exist.to.true;
137+
});
138+
139+
it('processPastChallenges should process the lost DEVELOP/<ANY> challenge ', function() {
140+
var challenges = [
141+
{
142+
id: 30041345,
143+
name: 'Mock Challenge 1',
144+
track: 'DEVELOP',
145+
subTrack: 'CODE',
146+
userDetails: {
147+
hasUserSubmittedForReview: true,
148+
roles: ['Submitter'],
149+
submissions: [
150+
{
151+
challengeId: 30041345,
152+
id: 12345,
153+
placement: 1,
154+
score: 98.0,
155+
status: 'Active',
156+
type: 'Contest Submission'
157+
},
158+
{
159+
challengeId: 30041345,
160+
id: 12346,
161+
placement: 11,
162+
score: 0.0,
163+
status: 'Failed Review',
164+
type: 'Contest Submission'
165+
},
166+
{
167+
challengeId: 30041345,
168+
id: 12347,
169+
placement: 21,
170+
score: 0.0,
171+
status: 'Completed Without Win',
172+
type: 'Checkpoint Submission'
173+
}
174+
],
175+
winningPlacements: [0]
176+
}
177+
178+
}
179+
];
180+
ChallengeService.processPastChallenges(challenges);
181+
var challenge = challenges[0];
182+
expect(challenge.highestPlacement).not.to.exist;
183+
expect(challenge.wonFirst).to.exist.to.false;
184+
expect(challenge.userStatus).to.exist.to.equal('PASSED_SCREENING');
185+
expect(challenge.userHasSubmitterRole).to.exist.to.true;
186+
});
187+
188+
it('processPastChallenges should process the won DEVELOP/FIRST_2_FINISH challenge ', function() {
189+
var challenges = [
190+
{
191+
id: 30041345,
192+
name: 'Mock Challenge 1',
193+
track: 'DEVELOP',
194+
subTrack: 'FIRST_2_FINISH',
195+
userDetails: {
196+
hasUserSubmittedForReview: true,
197+
roles: ['Submitter'],
198+
submissions: [
199+
{
200+
challengeId: 30041345,
201+
id: 12345,
202+
placement: 1,
203+
score: 98.0,
204+
status: 'Active',
205+
type: 'Contest Submission'
206+
},
207+
{
208+
challengeId: 30041345,
209+
id: 12346,
210+
placement: 11,
211+
score: 0.0,
212+
status: 'Failed Review',
213+
type: 'Contest Submission'
214+
},
215+
{
216+
challengeId: 30041345,
217+
id: 12347,
218+
placement: 21,
219+
score: 0.0,
220+
status: 'Completed Without Win',
221+
type: 'Checkpoint Submission'
222+
}
223+
]
224+
}
225+
}
226+
];
227+
ChallengeService.processPastChallenges(challenges);
228+
var challenge = challenges[0];
229+
expect(challenge.highestPlacement).to.exist.to.equal(1);
230+
expect(challenge.wonFirst).to.exist.to.true;
231+
expect(challenge.userStatus).to.exist.to.equal('PASSED_REVIEW');
232+
expect(challenge.userHasSubmitterRole).to.exist.to.true;
233+
});
234+
235+
it('processPastChallenges should process the lost(without placement) DEVELOP/FIRST_2_FINISH challenge ', function() {
236+
var challenges = [
237+
{
238+
id: 30041345,
239+
name: 'Mock Challenge 1',
240+
track: 'DEVELOP',
241+
subTrack: 'FIRST_2_FINISH',
242+
userDetails: {
243+
hasUserSubmittedForReview: true,
244+
roles: ['Submitter'],
245+
submissions: [
246+
{
247+
challengeId: 30041345,
248+
id: 12345,
249+
placement: null,
250+
score: 34.0,
251+
status: 'Active',
252+
type: 'Contest Submission'
253+
},
254+
{
255+
challengeId: 30041345,
256+
id: 12346,
257+
placement: null,
258+
score: 0.0,
259+
status: 'Failed Review',
260+
type: 'Contest Submission'
261+
},
262+
{
263+
challengeId: 30041345,
264+
id: 12347,
265+
placement: 1,
266+
score: 0.0,
267+
status: 'Completed Without Win',
268+
type: 'Checkpoint Submission'
269+
}
270+
]
271+
}
272+
}
273+
];
274+
ChallengeService.processPastChallenges(challenges);
275+
var challenge = challenges[0];
276+
expect(challenge.highestPlacement).not.to.exist;
277+
expect(challenge.wonFirst).to.exist.to.false;
278+
expect(challenge.userStatus).to.exist.to.equal('PASSED_SCREENING');
279+
expect(challenge.userHasSubmitterRole).to.exist.to.true;
280+
});
281+
282+
it('processPastChallenges should process the lost(with placement) DEVELOP/FIRST_2_FINISH challenge ', function() {
283+
var challenges = [
284+
{
285+
id: 30041345,
286+
name: 'Mock Challenge 1',
287+
track: 'DEVELOP',
288+
subTrack: 'FIRST_2_FINISH',
289+
userDetails: {
290+
hasUserSubmittedForReview: true,
291+
roles: ['Submitter'],
292+
submissions: [
293+
{
294+
challengeId: 30041345,
295+
id: 12345,
296+
placement: 5,
297+
score: 34.0,
298+
status: 'Active',
299+
type: 'Contest Submission'
300+
},
301+
{
302+
challengeId: 30041345,
303+
id: 12346,
304+
placement: null,
305+
score: 0.0,
306+
status: 'Failed Review',
307+
type: 'Contest Submission'
308+
},
309+
{
310+
challengeId: 30041345,
311+
id: 12347,
312+
placement: 1,
313+
score: 0.0,
314+
status: 'Completed Without Win',
315+
type: 'Checkpoint Submission'
316+
}
317+
]
318+
}
319+
}
320+
];
321+
ChallengeService.processPastChallenges(challenges);
322+
var challenge = challenges[0];
323+
expect(challenge.highestPlacement).to.exist.to.equal(5);
324+
expect(challenge.wonFirst).to.exist.to.false;
325+
expect(challenge.userStatus).to.exist.to.equal('PASSED_REVIEW');
326+
expect(challenge.userHasSubmitterRole).to.exist.to.true;
327+
});
328+
329+
it('processPastChallenges should process a not completed DEVELOP/FIRST_2_FINISH challenge ', function() {
330+
var challenges = [
331+
{
332+
id: 30041345,
333+
name: 'Mock Challenge 1',
334+
track: 'DEVELOP',
335+
subTrack: 'FIRST_2_FINISH',
336+
userDetails: {
337+
hasUserSubmittedForReview: false,
338+
roles: ['Submitter'],
339+
submissions: []
340+
}
341+
}
342+
];
343+
ChallengeService.processPastChallenges(challenges);
344+
var challenge = challenges[0];
345+
expect(challenge.highestPlacement).not.to.exist;
346+
expect(challenge.wonFirst).to.exist.to.false;
347+
expect(challenge.userStatus).to.exist.to.equal('NOT_FINISHED');
348+
expect(challenge.userHasSubmitterRole).to.exist.to.true;
349+
});
350+
351+
it('processPastChallenges should process a DEVELOP/FIRST_2_FINISH challenge for a non submitter user ', function() {
352+
var challenges = [
353+
{
354+
id: 30041345,
355+
name: 'Mock Challenge 1',
356+
track: 'DEVELOP',
357+
subTrack: 'FIRST_2_FINISH',
358+
userDetails: {
359+
hasUserSubmittedForReview: false,
360+
roles: ['Observer'],
361+
submissions: []
362+
}
363+
}
364+
];
365+
ChallengeService.processPastChallenges(challenges);
366+
var challenge = challenges[0];
367+
expect(challenge.highestPlacement).not.to.exist;
368+
expect(challenge.wonFirst).to.exist.to.false;
369+
expect(challenge.userStatus).to.exist.to.equal('COMPLETED');
370+
expect(challenge.userHasSubmitterRole).to.exist.to.false;
371+
});
372+
373+
it('processPastChallenges should process a DEVELOP/<ANY> challenge for a user without role ', function() {
374+
var challenges = [
375+
{
376+
id: 30041345,
377+
name: 'Mock Challenge 1',
378+
track: 'DEVELOP',
379+
subTrack: 'FIRST_2_FINISH',
380+
userDetails: {
381+
hasUserSubmittedForReview: false,
382+
roles: [],
383+
submissions: [],
384+
winningPlacements: [0]
385+
}
386+
}
387+
];
388+
ChallengeService.processPastChallenges(challenges);
389+
var challenge = challenges[0];
390+
expect(challenge.highestPlacement).not.to.exist;
391+
expect(challenge.wonFirst).to.exist.to.false;
392+
expect(challenge.userStatus).to.exist.to.equal('COMPLETED');
393+
expect(challenge.userHasSubmitterRole).to.exist.to.false;
394+
});
395+
396+
it('processPastSRM should process SRM with valid placement ', function() {
397+
var srm = {
398+
id: 4460,
399+
name: "Holder",
400+
status: "PAST",
401+
track: "DATA_SCIENCE",
402+
subTrack : "SRM",
403+
startDate: "8/30/15 12:00 AM",
404+
endDate: "8/30/15 12:00 AM",
405+
rounds: [
406+
{
407+
id: 12345,
408+
forumId: 54321,
409+
status: "PAST",
410+
userSRMDetails: {
411+
newRating: 678,
412+
finalPoints: 226.45
413+
}
414+
}
415+
]
416+
};
417+
ChallengeService.processPastSRM(srm);
418+
expect(srm.newRating).to.exist.to.equal(678);
419+
expect(srm.finalPoints).to.exist.to.equal(226.45);
420+
});
421+
422+
it('processPastSRM should process SRM without rounds gracefully ', function() {
423+
var srm = {
424+
id: 4460,
425+
name: "Holder",
426+
status: "PAST",
427+
track: "DATA_SCIENCE",
428+
subTrack : "SRM",
429+
startDate: "8/30/15 12:00 AM",
430+
endDate: "8/30/15 12:00 AM",
431+
rounds: []
432+
};
433+
ChallengeService.processPastSRM(srm);
434+
expect(srm.newRating).not.to.exist;
435+
expect(srm.finalPoints).not.to.exist;
436+
});
437+
438+
it('processPastMarathonMatch should process MM with valid placement ', function() {
439+
var mm = {
440+
id: 4460,
441+
name: "Holder",
442+
status: "PAST ",
443+
track: "DATA_SCIENCE",
444+
subTrack : "MARATHON_MATCH",
445+
startDate: "8/30/15 12:00 AM",
446+
endDate: "8/30/15 12:00 AM",
447+
rounds: [
448+
{
449+
id: 12345,
450+
forumId: 54321,
451+
status: "PAST",
452+
systemTestEndAt: "8/29/15 12:00 AM",
453+
userMMDetails: {
454+
newRating: 678,
455+
rated: true,
456+
pointTotal: 22645
457+
}
458+
}
459+
]
460+
};
461+
ChallengeService.processPastMarathonMatch(mm);
462+
expect(mm.status).to.exist.to.equal("PAST");// should trim the status
463+
expect(mm.newRating).to.exist.to.equal(678);
464+
expect(mm.pointTotal).to.exist.to.equal(22645);
465+
expect(mm.submissionEndDate).to.exist.to.equal("8/29/15 12:00 AM");
466+
});
467+
468+
it('processPastMarathonMatch should process MM without rounds gracefully ', function() {
469+
var mm = {
470+
id: 4460,
471+
name: "Holder",
472+
status: "PAST",
473+
track: "DATA_SCIENCE",
474+
subTrack : "MARATHON_MATCH",
475+
startDate: "8/30/15 12:00 AM",
476+
endDate: "8/30/15 12:00 AM",
477+
rounds: []
478+
};
479+
ChallengeService.processPastMarathonMatch(mm);
480+
expect(mm.newRating).not.to.exist;
481+
expect(mm.pointTotal).not.to.exist;
482+
expect(mm.submissionEndDate).not.to.exist;
483+
});
484+
485+
it('processPastMarathonMatch should process MM with unrated user details ', function() {
486+
var mm = {
487+
id: 4460,
488+
name: "Holder",
489+
status: "PAST ",
490+
track: "DATA_SCIENCE",
491+
subTrack : "MARATHON_MATCH",
492+
startDate: "8/30/15 12:00 AM",
493+
endDate: "8/30/15 12:00 AM",
494+
rounds: [
495+
{
496+
id: 12345,
497+
forumId: 54321,
498+
status: "PAST",
499+
systemTestEndAt: "8/29/15 12:00 AM",
500+
userMMDetails: {
501+
newRating: null,
502+
rated: false,
503+
pointTotal: null
504+
}
505+
}
506+
]
507+
};
508+
ChallengeService.processPastMarathonMatch(mm);
509+
expect(mm.status).to.exist.to.equal("PAST");// should trim the status
510+
expect(mm.newRating).not.to.exist;
511+
expect(mm.pointTotal).not.to.exist;
512+
expect(mm.submissionEndDate).not.to.exist;
513+
});
514+
43515
});

‎app/topcoder.constants.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ angular.module("CONSTANTS", [])
3333
"REGISTRATION": "REGISTRATION",
3434
"CODING": "CODING",
3535
"REGISTERED": "REGISTERED",
36-
"SUBMISSION_TYPE_CONTEST": "Contest Submission"
36+
"SUBMISSION_TYPE_CONTEST": "Contest Submission",
37+
"STATUS_ACTIVE": "Active"
3738
})
3839

3940
;

‎config.js

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,10 @@ module.exports = function() {
4545
REGISTERED: 'REGISTERED',
4646

4747
// submission type
48-
SUBMISSION_TYPE_CONTEST: 'Contest Submission'
48+
SUBMISSION_TYPE_CONTEST: 'Contest Submission',
49+
50+
// statuses for different objects
51+
STATUS_ACTIVE: 'Active'
4952

5053
}
5154
},
@@ -94,7 +97,10 @@ module.exports = function() {
9497
REGISTERED: 'REGISTERED',
9598

9699
// submission type
97-
SUBMISSION_TYPE_CONTEST: 'Contest Submission'
100+
SUBMISSION_TYPE_CONTEST: 'Contest Submission',
101+
102+
// statuses for different objects
103+
STATUS_ACTIVE: 'Active'
98104

99105
}
100106
},
@@ -143,7 +149,10 @@ module.exports = function() {
143149
REGISTERED: 'REGISTERED',
144150

145151
// submission type
146-
SUBMISSION_TYPE_CONTEST: 'Contest Submission'
152+
SUBMISSION_TYPE_CONTEST: 'Contest Submission',
153+
154+
// statuses for different objects
155+
STATUS_ACTIVE: 'Active'
147156

148157
}
149158
},
@@ -192,7 +201,10 @@ module.exports = function() {
192201
REGISTERED: 'REGISTERED',
193202

194203
// submission type
195-
SUBMISSION_TYPE_CONTEST: 'Contest Submission'
204+
SUBMISSION_TYPE_CONTEST: 'Contest Submission',
205+
206+
// statuses for different objects
207+
STATUS_ACTIVE: 'Active'
196208

197209
}
198210
},
@@ -241,7 +253,10 @@ module.exports = function() {
241253
REGISTERED: 'REGISTERED',
242254

243255
// submission type
244-
SUBMISSION_TYPE_CONTEST: 'Contest Submission'
256+
SUBMISSION_TYPE_CONTEST: 'Contest Submission',
257+
258+
// statuses for different objects
259+
STATUS_ACTIVE: 'Active'
245260

246261
}
247262
}

0 commit comments

Comments
 (0)
This repository has been archived.