npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

assign-by-preference

v1.0.0

Published

Assign users to group slots based on user preference and availability

Downloads

2

Readme

assign-by-preference 🗂

🗂 Assign users to group slots based on user preference and availability

assign-by-preference is a module that allows you input an array of objects containing individual data and their preferences for being organized into groups pertaining to various activities such as workshops, teams, classes, etc. and returns an object containing data about the group (assignees, capacity, etc.). As it sorts users into groups, it assumes "preference" based on the indices of a user's preference object, with 0 being the highest preference. If a user's preferred group has no availability, the module will search for a group with the highest availability and place the user into that group.

How to use it

assignByPreference(users, groups [, options])

The table below describes the expected properties of each parameter.

Users

Users is a list of objects which should contain the following key-value pairs

| Property | Type | Example | Description | | ----------- | ---------------- | ------------------------------- | ------------------------------------------------------------ | | key | unique string | jane-doe-1 | a unique string to identify individual | | preferences | array | ['coding 101', 'cooking 201'] | a list of group preferences | | assignments | [optional] array | ['coding 101'] | a list of user's current assignments (if no argument is passed, default value will be empty array [ ]) |

Groups

Groups is a list of objects which should contain the following key-value pairs

| Property | Type | Example | Description | | -------- | ------------- | ------------ | -------------------------------------- | | key | unique string | 'Intro to Archery' | a unique string to identify individual | | capacity | number | 23 | total number of spaces in a group |

Options

| Property | Type | Description | | ---------------------------- | ------ | ------------------------------------------------------------ | | options.assignmentsPerUser | number | sets limit for number of groups to which user can be assigned (if not defined, default value will be the minimum of two values: the number of groups that exist [preventing "double-assignment" ] or how ever many assignments per user that will not end up exceeding sum of all group capacities |

Example 1

Number of users: 3

Number of groups: 7

Capacity of each group: 2

Assignments per user: 4

Explanation: There are more groups than users, but each group cannot accommodate every user. Therefore, the maximum number of assignments each user can have without exceeding each group's capacity is the value of 7 * 2 / 3, rounded down (4).

Example 2

Number of users: 3

Number of groups: 7

Capacity of each group: 5

Assignments per user: 7

Explanation: Realistically, users cannot be assigned to a group more than once. Therefore, every user will be assigned to every group once.