Skip to content
Merged
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
46 changes: 29 additions & 17 deletions src/shared/utils/mm-review-summations.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ function ensureSubmissionEntry(existingEntry, { submissionId, timestamp, timesta
const baseEntry = {
submissionId,
submissionTime: timestamp || null,
isLatest: null,
provisionalScore: null,
finalScore: null,
status: 'completed',
Expand All @@ -80,6 +81,7 @@ function ensureSubmissionEntry(existingEntry, { submissionId, timestamp, timesta
...existingEntry,
submissionId: existingEntry.submissionId || submissionId,
submissionTime: existingEntry.submissionTime || baseEntry.submissionTime,
isLatest: existingEntry.isLatest === undefined ? baseEntry.isLatest : existingEntry.isLatest,
status: existingEntry.status || 'completed',
reviewSummations,
reviewSummation,
Expand Down Expand Up @@ -128,6 +130,7 @@ function updateSubmissionEntry(existingEntry, {
normalizedScore,
summation,
isProvisional,
isLatest,
}) {
const baseEntry = ensureSubmissionEntry(existingEntry, {
submissionId,
Expand All @@ -137,10 +140,12 @@ function updateSubmissionEntry(existingEntry, {
const {
submissionTime: baseSubmissionTime,
latestTimestamp: baseLatestTimestamp,
isLatest: baseIsLatest,
} = baseEntry;

let submissionTime = baseSubmissionTime;
let latestTimestamp = baseLatestTimestamp;
let submissionIsLatest = baseIsLatest;

if (timestampValue > latestTimestamp) {
latestTimestamp = timestampValue;
Expand All @@ -149,6 +154,10 @@ function updateSubmissionEntry(existingEntry, {
submissionTime = timestamp;
}

if (!_.isNil(isLatest)) {
submissionIsLatest = Boolean(isLatest);
}

const provisionalResult = isProvisional
? mergeScoreData(
baseEntry.provisionalMeta,
Expand All @@ -173,6 +182,7 @@ function updateSubmissionEntry(existingEntry, {
...baseEntry,
submissionTime,
latestTimestamp,
isLatest: submissionIsLatest,
provisionalMeta: provisionalResult.meta,
provisionalScore: provisionalResult.value,
finalMeta: finalResult.meta,
Expand Down Expand Up @@ -278,8 +288,6 @@ export function buildMmSubmissionData(reviewSummations = []) {
memberId: null,
rating: null,
submissionsMap: new Map(),
bestProvisionalScore: null,
bestFinalScore: null,
});
}

Expand All @@ -302,7 +310,7 @@ export function buildMmSubmissionData(reviewSummations = []) {

const normalizedScore = normalizeScoreValue(_.get(summation, 'aggregateScore'));
const isProvisional = Boolean(summation.isProvisional);
const isLatest = _.isNil(summation.isLatest) ? true : Boolean(summation.isLatest);
const isLatest = _.isNil(summation.isLatest) ? null : Boolean(summation.isLatest);

Choose a reason for hiding this comment

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

[❗❗ correctness]
The change from true to null as the default value for isLatest alters the logic significantly. Ensure that this change is intentional and that all dependent logic correctly handles null values.


const updatedEntry = updateSubmissionEntry(memberEntry.submissionsMap.get(submissionId), {
submissionId,
Expand All @@ -311,28 +319,18 @@ export function buildMmSubmissionData(reviewSummations = []) {
normalizedScore,
summation,
isProvisional,
isLatest,
});

memberEntry.submissionsMap.set(submissionId, updatedEntry);

if (!_.isNil(normalizedScore) && isLatest) {
if (isProvisional) {
memberEntry.bestProvisionalScore = _.isNil(memberEntry.bestProvisionalScore)
? normalizedScore
: Math.max(memberEntry.bestProvisionalScore, normalizedScore);
} else {
memberEntry.bestFinalScore = _.isNil(memberEntry.bestFinalScore)
? normalizedScore
: Math.max(memberEntry.bestFinalScore, normalizedScore);
}
}
});

const members = Array.from(membersByHandle.values()).map((memberEntry) => {
const submissions = Array.from(memberEntry.submissionsMap.values())
.map(submission => ({
submissionId: submission.submissionId,
submissionTime: submission.submissionTime,
isLatest: submission.isLatest,
provisionalScore: _.isNil(submission.provisionalScore) ? null : submission.provisionalScore,
finalScore: _.isNil(submission.finalScore) ? null : submission.finalScore,
status: submission.status || 'completed',
Expand All @@ -341,6 +339,20 @@ export function buildMmSubmissionData(reviewSummations = []) {
}))
.sort((a, b) => toTimestampValue(b.submissionTime) - toTimestampValue(a.submissionTime));

const hasLatestFlag = submissions.some(s => !_.isNil(s.isLatest));

Choose a reason for hiding this comment

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

[❗❗ correctness]
The logic for determining latestSubmissions now relies on the presence of the isLatest flag. Ensure that all submissions have this flag set appropriately, as missing or incorrect flags could lead to incorrect ranking calculations.

const latestSubmissions = hasLatestFlag ? submissions.filter(s => s.isLatest) : submissions;
const candidates = latestSubmissions.length ? latestSubmissions : submissions;
const bestProvisionalScore = _.chain(candidates)
.map(s => (_.isNil(s.provisionalScore) ? null : s.provisionalScore))
.filter(s => !_.isNil(s))
.max()
.value() || null;
const bestFinalScore = _.chain(candidates)
.map(s => (_.isNil(s.finalScore) ? null : s.finalScore))
.filter(s => !_.isNil(s))
.max()
.value() || null;

const rating = _.isNil(memberEntry.rating) ? null : memberEntry.rating;
const memberId = memberEntry.memberId ? _.toString(memberEntry.memberId) : null;

Expand All @@ -358,8 +370,8 @@ export function buildMmSubmissionData(reviewSummations = []) {
provisionalRank: null,
finalRank: null,
submissions,
bestProvisionalScore: memberEntry.bestProvisionalScore,
bestFinalScore: memberEntry.bestFinalScore,
bestProvisionalScore,
bestFinalScore,
};
});

Expand Down
Loading