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

dce-live-grouper

v2.0.7

Published

Live algorithm for assigning students to groups.

Downloads

451

Readme

dce-live-grouper

README is still a WIP.

Live algorithm for assigning students to groups.

Table of Contents

  1. Quick Start
  2. User Guide
    1. Setup
    2. Collections
    3. Banned Pairs
    4. Pre-Assignments
  3. Running Tests
  4. Implementation
  5. Contributors

Quick Start

This library provides a set of tools to consistently assign students to groups as they enter events, across multiple events, courses, and with the algorithm running on multiple servers, in a distributed manner.

Using the Live Grouper is simple, start by initializing, then create an event, and start assigning students:

// Import from grouper library
import { 
   initGrouper,
   createEvent,
   getGroupAssignment,
   // Types
   GrouperAlgorithm,
} from 'dce-live-grouper';

// Import a Collection constructor
import { Collection } from 'dce-mango';

// Initialize the internal state and connection to the database
initGrouper(Collection);

// Create an event
await createEvent({
   courseId: 1, 
   eventId: 'awesome-event',
   // Here we are choosing to have any number of groups with a max size of 5
   grouperAlgorithm: GrouperAlgorithm.FixedGroupSize,
   capacity: 5,
});

// Assign a student to a group
const studentAssignment = await getGroupAssignment({
   courseId: 1,
   eventId: 'awesome-event',
   studentId: 1,
});

It's possible to run with any number of courses, events, or students, and the internal algorithms will guarantee data consistency. The main thing to keep in mind is that you will need to retry requests if they fail.


User Guide

More in-depth:

Setup

There are two choices of GrouperAlgorithm:

  1. FixedGroupSize - where we specify a max size for the groups, but can have any number of groups.
  2. FixedNumGroups - where we specify a max number of groups, but groups can be of any size.

For FixedGroupSize we need to specify a capacity when we create an event:

await createEvent({
   eventId: 'my-event',
   courseId: 1,
   grouperAlgorithm: GrouperAlgorithm.FixedGroupSize,
   // This is the max size for any one group
   capacity: 5,
});

For FixedNumGroups we need to specify a maxGroups

await createEvent({
   eventId: 'my-event',
   courseId: 1,
   grouperAlgorithm: GrouperAlgorithm.FixedNumGroups,
   // This is the max number of groups 
   maxGroups: 5,
});

Collections

If you want direct access to the events and courses, simply use the event and course collections returned by initGrouper:

const {
   eventCollection,
   courseCollection,
} = initGrouper(Collection);

// Now we can manually interact with the collections:
const myEvents = await eventCollection.find({ id: '1-my-event' });
const myEvent = myEvents[0];

// Manually changing the max number of groups or the group size:
if (myEvent.maxGroups) {
   await eventCollection.insert({
      ...myEvent,
      maxGroups: myEvent.maxGroups + 1,
   });
} else {
   await eventCollection.insert({
      ...myEvent,
      capacity: myEvent.capacity + 2,
   });
}

// And even delete events or courses
await eventCollection.delete({ id: '1-my-event' });
await courseCollection.delete({ id: 1 });

Banned Pairs

To assigned banned pairs, use the get and set functions:

// Imports
import { initGrouper, getBannedPairs, setBannedPairs } from 'dce-live-grouper';
import { Collection } from 'dce-mango';

initGrouper(Collection);

// Choosing a course
const courseId = 5;

// Getting
const bannedPairs = await getBannedPairs(courseId);

// Change the banned pairs
bannedPairs.push({
   student1: 333,
   student2: 666,
});

// Push the changes to the course in the database
await setBannedPairs({
   courseId,
   bannedPairs,
});


// Completely resetting a courses banned pairs:
await setBannedPairs({
   courseId: 7,
   bannedPairs: [],
});

Pre-Assignments

Pre-assignments allow you to assign students to groups before they arrive:

import { createEvent, PreAssignment } from 'dce-live-grouper';

// For example, we want student 1 and student 2 to sit together in group 1
const preAssignments = [
   {
      studentId: 1,
      groupNum: 1,
   },
   {
      studentId: 2,
      groupNum: 1,
   },
];

await createEvent({
   ...eventOpts, // The other configuration options for the event
   preAssignments,
});


// Now, if I try to assign student 1, it will return group 1
const { groupNum } = await getGroupAssignment({ ...eventOpts, studentId: 1 });

if (groupNum == 1) {
   console.log('Pre-assignment worked!');
} else {
   console.log('This should not happen...');
}

Running Tests

To run the unit tests, you will need to set a MONGO_URL in a .env file, following along with the .env.template. Then, simply run npm run test in the root of the repository.

For more detailed tests of the algorithm suite, see the dce-live-grouper-tests-and-training repository.


Implementation

There are two key parts of this library:

  1. the core algorithms for choosing groups for students as they join an event
  2. the capability for these algorithms to run on multiple servers in a distributed manner

For the first part, see the ALGORITHMS.md file in src/algorithms. There we describe the different algorithm choices, how they are designed, and other details.

For the second part, we implemented a 'batch-queue', which is described in detail in BATCH_QUEUE.md in the src/queue directory.


Contributors


License

DCE © MIT