Assign divisions users
Assigns divisions to users based on their ratings.
assignDivisions
Syntax
const assign = rankSystem.assignDivisions(options);
Parameters
options
(Object):users
(Array): An array of user objects. Each user object should have arating
property indicating the user's rating.numberOfRounds
(Number, optional): The number of rounds used to calculate the average rating. Defaults to 3 if not specified.
Returns
An object containing:
divisions
(Array): Updated array of divisions with calculatedminPoints
andmaxPoints
for each division.users
(Array): Updated array of user objects with thedivision
property assigned based on their rating.
Description
The assignDivisions
function calculates division assignments for users based on their ratings and the configured division thresholds. First, it calculates minPoints
and maxPoints
for each division using the specified or default number of rounds to determine the average rating. Then, it iterates through each user to find the appropriate division based on their rating and assigns it.
If a user's rating does not fall within the defined thresholds for any division, they are assigned to the first default division.
Example
const users = [
{ id: 1, rating: 1500 },
{ id: 2, rating: 1800 },
{ id: 3, rating: 1600 }
];
const assign = rankSystem.assignDivisions({ users, numberOfRounds: 2.5 });
console.log(assign);
Notes
Ensure that each user object in the
users
array has a validrating
property.If the
numberOfRounds
parameter is not specified, it defaults to 3.
Last updated