Skip to content

Release v5 develop #239

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

Merged
merged 2 commits into from
Sep 1, 2020
Merged
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
21 changes: 7 additions & 14 deletions src/actions/challenge.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import { createActions } from 'redux-actions';
import { decodeToken } from 'tc-accounts';
import { getService as getChallengesService } from '../services/challenges';
import { getService as getSubmissionService } from '../services/submissions';
import { getService as getMemberService } from '../services/members';
import { getApi } from '../services/api';
import * as submissionUtil from '../utils/submission';

Expand Down Expand Up @@ -147,25 +146,19 @@ function getMMSubmissionsInit(challengeId) {
* @param {String} tokenV3 Topcoder auth token v3.
* @return {Action}
*/
function getMMSubmissionsDone(challengeId, registrants, tokenV3) {
function getMMSubmissionsDone(challengeId, tokenV3) {
const filter = { challengeId };
const memberService = getMemberService(tokenV3);
const submissionsService = getSubmissionService(tokenV3);

// TODO: Move those numbers to configs
return getAll(params => submissionsService.getSubmissions(filter, params), 1, 500)
.then((submissions) => {
const userIds = _.uniq(_.map(submissions, sub => sub.memberId));
return memberService.getMembersInformation(userIds)
.then((resources) => {
const finalSubmissions = submissionUtil
.processMMSubmissions(submissions, resources, registrants);
return {
challengeId,
submissions: finalSubmissions,
tokenV3,
};
});
const finalSubmissions = submissionUtil.processMMSubmissions(submissions);
return {
challengeId,
submissions: finalSubmissions,
tokenV3,
};
});
}

Expand Down
2 changes: 1 addition & 1 deletion src/services/challenges.js
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ class ChallengesService {
if (/^[\d]{5,8}$/.test(challengeId)) {
isLegacyChallenge = true;
challenge = await this.private.getChallenges('/challenges/', { legacyId: challengeId })
.then(res => res.challenges[0]);
.then(res => res.challenges[0] || {});
} else {
challenge = await this.private.getChallenges(`/challenges/${challengeId}`)
.then(res => res.challenges);
Expand Down
24 changes: 5 additions & 19 deletions src/utils/submission.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,6 @@ function toFixed(num, decimal) {
return result;
}

function getMMChallengeHandleStyle(handle, registrants) {
const style = _.get(_.find(registrants, m => m.handle === handle), 'colorStyle', null);
if (style) return JSON.parse(style.replace(/(\w+):\s*([^;]*)/g, '{"$1": "$2"}'));
return {};
}

/**
* Process each submission rank of MM challenge
* @param submissions the array of submissions
Expand Down Expand Up @@ -118,21 +112,14 @@ export function getFinalScore(submission) {
* @param resources the challenge resources
* @param registrants the challenge registrants
*/
export function processMMSubmissions(submissions, resources, registrants) {
export function processMMSubmissions(submissions) {
const data = {};
const result = [];

_.each(submissions, (submission) => {
const { memberId } = submission;
let memberHandle;
const resource = _.find(resources, r => _.get(r, 'userId').toString() === memberId.toString());
if (_.isEmpty(resource)) {
memberHandle = memberId;
} else {
memberHandle = _.has(resource, 'handle') ? _.get(resource, 'handle') : memberId.toString();
}
if (!data[memberHandle]) {
data[memberHandle] = [];
if (!data[memberId]) {
data[memberId] = [];
}
const validReviews = _.reject(submission.review, ['typeId', AV_SCAN_SCORER_REVIEW_TYPE_ID]);
validReviews.sort((a, b) => {
Expand All @@ -149,7 +136,7 @@ export function processMMSubmissions(submissions, resources, registrants) {
const provisionalScore = toFixed(_.get(validReviews, '[0].score', '-'), 5);
const finalScore = toFixed(_.get(submission, 'reviewSummation[0].aggregateScore', '-'), 5);

data[memberHandle].push({
data[memberId].push({
submissionId: submission.id,
submissionTime: submission.created,
provisionalScore,
Expand All @@ -163,8 +150,7 @@ export function processMMSubmissions(submissions, resources, registrants) {
result.push({
submissions: [...value.sort((a, b) => new Date(b.submissionTime)
.getTime() - new Date(a.submissionTime).getTime())],
member: key,
colorStyle: getMMChallengeHandleStyle(key, registrants),
memberId: key,
});
});

Expand Down