Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Places array computation algorithm is wrong #17

Open
user202729 opened this issue Aug 24, 2019 · 0 comments
Open

Places array computation algorithm is wrong #17

user202729 opened this issue Aug 24, 2019 · 0 comments

Comments

@user202729
Copy link
Contributor

user202729 commented Aug 24, 2019

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?

  1. 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) {
  1. 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant