Skip to content

Commit 7a494df

Browse files
authored
Merge pull request #244 from meherchandan/new-v3-fixes
Marathon matches data added from v2
2 parents b1ba56f + bf90beb commit 7a494df

File tree

2 files changed

+59
-48
lines changed

2 files changed

+59
-48
lines changed

components/ChallengeFilters/ChallengeFiltersExample.jsx

Lines changed: 57 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import _ from 'lodash';
1919
import React, { PropTypes as PT } from 'react';
2020
import Sticky from 'react-stickynode';
2121

22-
import { DESIGN_TRACK, DEVELOP_TRACK } from './ChallengeFilter';
22+
import { DESIGN_TRACK, DEVELOP_TRACK, DATA_SCIENCE_TRACK } from './ChallengeFilter';
2323
import ChallengeFilterWithSearch from './ChallengeFilterWithSearch';
2424
import ChallengeFilters from './ChallengeFilters';
2525
import SideBarFilter, { MODE as SideBarFilterModes } from '../SideBarFilters/SideBarFilter';
@@ -231,67 +231,78 @@ class ChallengeFiltersExample extends React.Component {
231231
/* Normalizes challenge objects received from different API endpoints,
232232
* and adds them to the list of loaded challenges. */
233233
function helper2(response, community) {
234-
return response.json().then(res => res.result.content.forEach((item) => {
234+
return response.json().then((res) => {
235+
const content = res.result ? res.result.content : res.data;
236+
content.forEach((item) => {
235237
/* Only marathon matches, when received from the /data/marathon/challenges
236238
* endpoint, satisfy this. */
237-
if (item.roundId) {
238-
const endTimestamp = new Date(item.endDate).getTime();
239-
_.defaults(item, {
240-
challengeId: item.roundId,
241-
challengeName: item.fullName,
242-
challengeCommunity: 'Data',
243-
challengeType: 'Marathon',
244-
communities: new Set([community]),
245-
currentPhaseEndDate: item.endDate,
246-
currentPhaseName: endTimestamp > Date.now() ? 'Registration' : '',
247-
numRegistrants: item.numberOfRegistrants,
248-
numSubmissions: item.numberOfSubmissions,
249-
platforms: [],
250-
prize: [],
251-
registrationOpen: endTimestamp > Date.now() ? 'Yes' : 'No',
252-
registrationStartDate: item.startDate,
253-
submissionEndDate: item.endDate,
254-
submissionEndTimestamp: endTimestamp,
255-
technologies: [],
256-
totalPrize: 0,
257-
track: 'DATA_SCIENCE',
258-
status: endTimestamp > Date.now() ? 'Active' : 'Completed',
259-
subTrack: 'MARATHON_MATCH',
260-
});
261-
map[item.id] = item;
262-
} else if (item.track === 'SRM') {
263-
/* We don't support SRM yet, so we don't want them around */
264-
} else { /* All challenges from other endpoints have the same format. */
265-
const existing = map[item.id];
266-
if (existing) existing.communities.add(community);
267-
else {
239+
if (item.roundId) {
240+
const endTimestamp = new Date(item.endDate).getTime();
241+
const allphases = [{
242+
challengeId: item.roundId,
243+
phaseType: 'Registration',
244+
phaseStatus: endTimestamp > Date.now() ? 'Open' : 'Close',
245+
scheduledEndTime: item.endDate,
246+
},
247+
];
268248
_.defaults(item, {
249+
id: item.roundId,
250+
name: item.fullName,
251+
challengeCommunity: 'Data',
252+
challengeType: 'Marathon',
253+
allPhases: allphases,
254+
currentPhases: allphases.filter(phase => phase.phaseStatus === 'Open'),
269255
communities: new Set([community]),
256+
currentPhaseName: endTimestamp > Date.now() ? 'Registration' : '',
257+
numRegistrants: item.numberOfRegistrants,
258+
numSubmissions: item.numberOfSubmissions,
270259
platforms: '',
271-
registrationOpen: item.allPhases.filter(d => d.phaseType === 'Registration')[0].phaseStatus === 'Open' ? 'Yes' : 'No',
260+
prizes: [0],
261+
registrationOpen: endTimestamp > Date.now() ? 'Yes' : 'No',
262+
registrationStartDate: item.startDate,
263+
submissionEndDate: item.endDate,
264+
submissionEndTimestamp: endTimestamp,
272265
technologies: '',
273-
track: item.track,
274-
status: item.status,
275-
submissionEndTimestamp: item.submissionEndDate,
276-
subTrack: item.subTrack,
266+
totalPrize: 0,
267+
track: 'DATA_SCIENCE',
268+
status: endTimestamp > Date.now() ? 'ACTIVE' : 'COMPLETED',
269+
subTrack: 'MARATHON_MATCH',
277270
});
278271
map[item.id] = item;
279-
if (item.platforms) {
280-
item.platforms.split(',').forEach(helper1);
281-
}
282-
if (item.technologies) {
283-
item.technologies.split(',').forEach(helper1);
272+
} else if (item.track === 'SRM') {
273+
/* We don't support SRM yet, so we don't want them around */
274+
} else { /* All challenges from other endpoints have the same format. */
275+
const existing = map[item.id];
276+
if (existing) existing.communities.add(community);
277+
else {
278+
_.defaults(item, {
279+
communities: new Set([community]),
280+
platforms: '',
281+
registrationOpen: item.allPhases.filter(d => d.phaseType === 'Registration')[0].phaseStatus === 'Open' ? 'Yes' : 'No',
282+
technologies: '',
283+
submissionEndTimestamp: item.submissionEndDate,
284+
});
285+
map[item.id] = item;
286+
if (item.platforms) {
287+
item.platforms.split(',').forEach(helper1);
288+
}
289+
if (item.technologies) {
290+
item.technologies.split(',').forEach(helper1);
291+
}
284292
}
285293
}
286-
}
287-
}));
294+
});
295+
},
296+
);
288297
}
289298
const api = this.props.config.API_URL;
299+
const api2 = this.props.config.API_URL_V2;
290300
return Promise.all([
291301
/* Fetching of active challenges */
292302
fetch(`${api}/challenges/?filter=track%3Ddesign`).then(res => helper2(res, DESIGN_TRACK)),
293303
fetch(`${api}/challenges/?filter=track%3Ddevelop`).then(res => helper2(res, DEVELOP_TRACK)),
294-
fetch(`${api}/challenges/marathonMatches`),
304+
fetch(`${api2}/data/marathon/challenges/?listType=past&pageSize=100`).then(res => helper2(res, DATA_SCIENCE_TRACK)),
305+
fetch(`${api2}/data/marathon/challenges/?listType=active`).then(res => helper2(res, DATA_SCIENCE_TRACK)),
295306
]).then(() => {
296307
_.forIn(map, item => challenges.push(item));
297308
challenges.sort((a, b) => b.submissionEndDate - a.submissionEndDate);

components/ChallengeStatus/ChallengeStatus.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ class ChallengeStatus extends Component {
183183
const { challenge } = this.props;
184184
const { DS_CHALLENGE_URL, CHALLENGE_URL } = this.state;
185185
const { id, track } = challenge;
186-
const challengeURL = track.toLowerCase() === 'data' ? DS_CHALLENGE_URL : CHALLENGE_URL;
186+
const challengeURL = track === 'DATA_SCIENCE' ? DS_CHALLENGE_URL : CHALLENGE_URL;
187187
const leaderboard = this.state.winners && this.state.winners.map(winner => (
188188
<div className="avatar-container" key={winner.handle}>
189189
<UserAvatarTooltip user={getSampleProfile(winner)}>
@@ -432,7 +432,7 @@ class ChallengeStatus extends Component {
432432
const { id, track } = challenge;
433433

434434
// We don't have the API for data science challenge
435-
if (track.toLowerCase() === 'data') {
435+
if (track === 'DATA_SCIENCE') {
436436
return;
437437
}
438438
const results = this.getWinners(track.toLowerCase(), id);

0 commit comments

Comments
 (0)