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

schedulator-sorter

v1.0.1

Published

Sorts out who the next people in line are

Downloads

4

Readme

Build Status

For a given pool of workers, and a given list of jobs, find out who should work those jobs in the next time period.

Assigns work using these rules

  1. Workers should only work whatever job they haven't worked for the longest amount of time (or a job they haven't worked yet).
  2. Whichever workers have not worked any job for the longest amount of time should be used to work these jobs, as long as rule 1 is met

API

Constructor

Takes no arguments. Maintains an internal list of work history, to be used when determining a week's schedule.

var Sorter = require('schedulator-sorter')
var sorter = new Sorter()

priorWork(work)

Takes a single argument: an object with parameters personId, time, and job - a person identifier, time identifier, and job identifier.

personId should match the personId property in the pool of workers passed to getNextSchedule, and job should match the value in the jobsToSchedule passed to the same function.

sorter.priorWork({
	personId: [number/string],
	time: [number],
	job: [number/string]
})

time must be a number. It can be a unix timestamp, a year/week number, whatever, but all the jobs that happened at X time should have the same number, and that number should be greater than all the jobs that happened at previous time Y.

getNextSchedule(jobs, workers)

Takes an array of jobs to schedule, and an array of objects representing workers who can do those jobs.

Returns an object whose parameters are job ids linking to the person to do that job.

jobs should be an array of primitive identifiers that match up to the identifiers passed to priorWork. workers should be an array of objects that have a personId property. Any other properties are optional, and will appear in the final schedule object.

var workerPool = [{ name: 'Josh', personId: 1},
	{ name: 'Caleb', personId: 2},
	{ name: 'Nathan', personId: 3}]

var sorter = new Sorter()

sorter.priorWork({
	personId: 1,
	time: 1,
	job: 'b'
})

sorter.priorWork({
	personId: 3,
	time: 1,
	job: 'a'
})

var firstWeek = sorter.getNextSchedule(['a', 'b'], workerPool)
console.log(firstWeek)
// => { a: { time: 2, job: 'a', name: 'Caleb', personId: 2 }, b: { time: 2, job: 'b', name: 'Nathan', personId: 3 } }

var secondWeek = sorter.getNextSchedule(['a', 'b'], workerPool)
console.log(secondWeek)
// => { a: { time: 3, job: 'a', name: 'Josh', personId: 1 }, b: { time: 3, job: 'b', name: 'Caleb', personId: 2 } }