This repository was archived by the owner on Mar 13, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Add metadata from review summation #3
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. won't this error when |
||
|
||
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( | ||
|
@@ -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)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this too. Shouldn't we do this in a safer manner with |
||
|
@@ -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) | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?