You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The current algorithm for computing the places array is wrong. For example there are 3 users with rank [1,2,3] and the virtual user is strictly worse than the user with rank 1 and strictly better than the user with rank 2, then the resulting places array is [1,2,2,3] instead of [1,2,3,4] (which becomes [1,3,3,4] instead of [1,2,3,4] after recomputing rank)
What's the best way to solve the problem?
Explicitly state that the places array doesn't need to be correct and only equality of adjacent elements matters. (for example [1, 1.5, 2, 3] is equivalent to [1, 2, 3, 4])
Diff:
diff --git a/js/calculate.js b/js/calculate.js
index 1a4f4a6..6dfbdec 100644
--- a/js/calculate.js
+++ b/js/calculate.js
@@ -89,6 +89,19 @@ function process(contestants) {
}
+/**
+ * Calculate rating changes.
+ *
+ * Arguments:
+ *
+ * previousRatings: An array of previous rating of contestants.
+ * standingsRows: An array of contestant ranks. This array must be
+ * non-decreasing, and the ranking of two adjacent contestants must be the
+ * same if and only if they have the same points/penalty; however the exact
+ * value does not matter - for example [1, 2, 3, 3] and [3, 6, 7.5, 7.5] are
+ * considered equivalent.
+ * userId: An array of contestants handles (strings).
+ */
function CalculateRatingChanges(previousRatings, standingsRows, userId) {
var arr = [];
for (var i = 0; i < standingsRows.length; i++) {
diff --git a/js/vir.js b/js/vir.js
index 615b0ba..833ede9 100644
--- a/js/vir.js
+++ b/js/vir.js
@@ -94,7 +94,7 @@ function refresh() {
if ((points > rows[i].points || (points == rows[i].points && penalty <= rows[i].penalty))
&& rank == -1) {
handles.push('virtual user');
- places.push(rows[i].rank);
+ places.push(points == rows[i].points && penalty == rows[i].penalty ? rows[i].rank : rows[i].rank - 0.5);
rank = rows[i].rank;
}
if (userHandle == rows[i].party.members[0].handle) {
Compute the ranking correctly. In this case it's easier to move the recalculate rank function to that part as the logic would mostly overlap.
Also: If the virtual user is worse than all of the participants, then the result will be the result of the last computation.
The text was updated successfully, but these errors were encountered:
The current algorithm for computing the
places
array is wrong. For example there are 3 users with rank[1,2,3]
and the virtual user is strictly worse than the user with rank 1 and strictly better than the user with rank 2, then the resultingplaces
array is[1,2,2,3]
instead of[1,2,3,4]
(which becomes[1,3,3,4]
instead of[1,2,3,4]
after recomputing rank)What's the best way to solve the problem?
places
array doesn't need to be correct and only equality of adjacent elements matters. (for example[1, 1.5, 2, 3]
is equivalent to[1, 2, 3, 4]
)Diff:
Also: If the virtual user is worse than all of the participants, then the result will be the result of the last computation.
The text was updated successfully, but these errors were encountered: