Skip to content
This repository was archived by the owner on Mar 13, 2025. It is now read-only.

Add metadata from review summation #3

Merged
merged 1 commit into from
Nov 13, 2018
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
1 change: 1 addition & 0 deletions config/default.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ module.exports = {
GROUP_IDS: process.env.GROUP_IDS || '202343,20000000', // Comma separated string of Group IDs

SUBMISSION_API_URL: process.env.SUBMISSION_API_URL || 'https://api.topcoder-dev.com/v5/submissions',
REVIEW_SUMMATION_API_URL: process.env.REVIEW_SUMMATION_API_URL || 'https://api.topcoder-dev.com/v5/reviewSummations',
CHALLENGE_API_URL: process.env.CHALLENGE_API_URL || 'https://api.topcoder-dev.com/v3/challenges',
MEMBER_API_URL: process.env.MEMBER_API_URL || 'https://api.topcoder-dev.com/v3/users',

Expand Down
3 changes: 2 additions & 1 deletion src/models/Leaderboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ const LeaderboardSchema = new Schema({
challengeId: { type: String },
memberId: { type: String },
handle: { type: String },
aggregateScore: { type: Number }
aggregateScore: { type: Number },
testsPassed: { type: Number }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we also post the total number of tests?

})

module.exports = {
Expand Down
37 changes: 31 additions & 6 deletions src/services/ProcessorService.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,41 @@ const logger = require('../common/logger')
const helper = require('../common/helper')
const { Leaderboard } = require('../models')

/**
* Returns the tests passed using the metadata information
* @param {object} metadata the object from which to retrieve the tests passed
*/
function getTestsPassed (metadata = {}) {
const tests = metadata.tests || {}

let testsPassed = tests.total - tests.pending - tests.failed
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

won't this error when tests is just {} ?


if (!testsPassed) {
testsPassed = 0
}

return testsPassed
}

/**
* Handle create / update topic messages from Kafka queue
* @param {Object} message the Kafka message in JSON format
*/
const upsert = async (message) => {
// const existRecord = await Leaderboard.findOne({$and: [{challengeId: }]})

const submission = await helper.reqToAPI(`${config.SUBMISSION_API_URL}/${message.payload.submissionId}`)

// const existRecord = await Leaderboard.findOne({ reviewSummationId: message.payload.id })
const existRecord = await Leaderboard.findOne({$and: [{challengeId: submission.body.challengeId}, {memberId: submission.body.memberId}]})

const reviewSummation = await helper.reqToAPI(`${config.REVIEW_SUMMATION_API_URL}/${message.payload.id}`)

let testsPassed

if (reviewSummation.metadata) {
testsPassed = getTestsPassed(reviewSummation.metadata)
} else {
testsPassed = 0
}

if (existRecord) {
logger.debug(`Record with ID # ${message.payload.id} exists in database. Updating the score`)
await Leaderboard.updateOne(
Expand All @@ -29,13 +52,14 @@ const upsert = async (message) => {
{
$set: {
aggregateScore: message.payload.aggregateScore,
reviewSummationId: message.payload.id
reviewSummationId: message.payload.id,
testsPassed
}
}
)
} else {
logger.debug(`Record with ID # ${message.payload.id} does not exists in database. Creating the record`)
// const submission = await helper.reqToAPI(`${config.SUBMISSION_API_URL}/${message.payload.submissionId}`)

const challengeDetail = await helper.reqToAPI(`${config.CHALLENGE_API_URL}?filter=id=${submission.body.challengeId}`)

if (!helper.isGroupIdValid(challengeDetail.body.result.content[0].groupIds)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this too. Shouldn't we do this in a safer manner with _.get() with defaults?

Expand All @@ -53,7 +77,8 @@ const upsert = async (message) => {
memberId: submission.body.memberId,
challengeId: submission.body.challengeId,
handle: memberDetail.body.result.content[0].handle,
aggregateScore: message.payload.aggregateScore
aggregateScore: message.payload.aggregateScore,
testsPassed
}

await Leaderboard.create(record)
Expand Down