Code Monkey home page Code Monkey logo

votes's Introduction

votes

version npm bundle size language downloads last commit Libraries.io dependency status for latest release license Build Status Codacy Badge Codacy Badge CodeClimate Coverage CodeClimate Maintainability Code Climate technical debt CodeFactor codecov npms.io (final) npms.io (final) Website

πŸ§‘β€πŸ’» Install

yarn add votes

πŸ—³οΈ Use

import { Borda } from 'votes'

const borda = new Borda({
  candidates: ['Lion', 'Bear', 'Sheep'],
  ballots: [
    { ranking: [['Lion'], ['Bear'], ['Sheep']], weight: 4 },
    { ranking: [['Sheep'], ['Bear'], ['Lion']], weight: 3 },
    { ranking: [['Bear', 'Sheep'], ['Lion']], weight: 2 },
  ],
})

const scores = borda.scores()
// -> { Bear: 10, Lion: 8, Sheep: 9}

const ranking = borda.ranking()
// -> [ [ 'Bear' ], [ 'Sheep' ], [ 'Lion' ] ]

πŸ“š Documentation

πŸ“Š Voting systems

Absolute majority: Checks if a candidate is ranked first by more than 50% of voters.

Approval voting: Each voter can select (β€œapprove”) any number of candidates. The winner is the most-approved candidate.

Baldwin method: Iterative Borda count in which, each round, candidates scoring the lowest score are eliminated.

Borda count: For each voter, every candidate is given a number of points which equals the number of candidates ranked lower in the voter's preference.

Bottom-two-runoff: take the two options with the fewest first preference votes. The pairwise loser out of those two options is eliminated. Repeat.

Contingent vote (immediate Two-round system): If no candidate receives 50% of the votes in the first round, then a second round of voting is held with only the top two candidates.

Coombs' method: Each round, the candidate with the most last rank is eliminated. The election repeats until there is a winner.

Copeland's method: Rank candidates by number of duels won against other candidates.

Instant-runoff: Considering only the top choice of each voter, the candidate with the fewest votes is eliminated. The election repeats until there is a winner. This voting system is very similar to single transferable vote method.

Kemeny–Young method: A relatively complex computation generating a preference order aiming to minimize dissatisfaction of the voters. Also known as Kemeny rule, VoteFair popularity ranking, the maximum likelihood method, and the median relation.

Maximal lotteries & Randomized Condorcet: Returns probabilities for each candidate that should be used for a lottery between the Candidates. If a candidate is the Condorcet winner, its probability will be 1. Despite being non-deterministic, those methods are the fairest. Currently, these methods give incorrect results in many cases because of mistakes in the codes!

Majority Judgement: (⚠️ cardinal voting system). Voters can rank candidates in an array corresponding to 6 categories ("Excellent", "Very good", "Good", "Passable", "Mediocre" and "Bad"). Candidates with the best median are ranked first.

Minimax Condorcet method: Ranking the candidates by smallest pairwise defeat.

Minimax-TD: Compute the Smith set . Then compute the Minimax ranking on that set. TD stands for Tideman-Darlington.

Nanson method: Iterative Borda count in which, each round, candidates scoring the average score or less are eliminated.

Plurality: Simple voting method where only the preferred candidate of each voter gets 1 point. AKA first-past-the-post.

Random candidate: Selects a random ranking, regardless of ballots.

Random dictator: Selects a random ballot that decides the ranking.

Ranked pairs: Using the duel results as edges, build an acyclic graph starting by the strongest score differences. The roots of the graph are the winners.

Schulze method: From the votes, compute the results of all possible duels. Then remove the most indecisive (closest to 50/50) duels until there is an undefeated candidate, the winner. This popular voting system is used by several organizations (Ubuntu, Debian, Wikimedia...).

Smith's method: All members of the top cycle (a.k.a. Smith set): "the smallest non-empty set of candidates in a particular election such that each member defeats every candidate outside the set in a pairwise election"

🀝 Contributing

Contributions, issues and feature requests are welcome!
Feel free to check issues page.

The repository is split in 2 projects:

  • /votes contains the source of the NPM package votes

  • /demo contains the source of the demo website

votes's People

Contributors

dependabot[bot] avatar github-actions[bot] avatar lzear avatar snyk-bot avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

votes's Issues

Questions

Hi Izear
First of all, I am very impressed with your work.
I have a few questions.

  1. What's the meaning of weight in the below example?
  2. What's the use of scoresFromBallots?
  3. Can you share one example for Minimax Condorcet method?
  4. Is there any similar npm package for voting algorithms?

return scoresFromBallots(
[
{ ranking: [['Lion'], ['Bear'], ['Sheep']], weight: 4 },
{ ranking: [['Sheep'], ['Bear'], ['Lion']], weight: 3 },
{ ranking: [['Bear', 'Sheep'], ['Lion']], weight: 2 },
],
['Lion', 'Bear', 'Sheep'],
VotingSystem.Schulze,
)

Next.js production env with side effect

I'm still trying to understand what is exactly the root cause, the only thing I know for sure is that it only happens when I try to use the votes import, if I remove the code reference it works fine.

It's using InstantRunoff to calculate results, it works fine locally, but once I deploy into Vercel it fails and the only error I got is this one:
image

Any tip how can I investigate it better or what to do? I already sent Vercel a ticket to follow up as well.

Sentry information:

Crashed in non-app: /var/task/node_modules/votes/dist/votes.cjs.prod.js in InstantRunoff.lastRoundQualified

The automated release is failing 🚨

🚨 The automated release from the master branch failed. 🚨

I recommend you give this issue a high priority, so other packages depending on you could benefit from your bug fixes and new features.

You can find below the list of errors reported by semantic-release. Each one of them has to be resolved in order to automatically publish your package. I’m sure you can resolve this πŸ’ͺ.

Errors are usually caused by a misconfiguration or an authentication problem. With each error reported below you will find explanation and guidance to help you to resolve it.

Once all the errors are resolved, semantic-release will release your package the next time you push a commit to the master branch. You can also manually restart the failed CI job that runs semantic-release.

If you are not sure how to resolve this, here is some links that can help you:

If those don’t help, or if this issue is reporting something you think isn’t right, you can always ask the humans behind semantic-release.


The release 1.1.0 on branch master cannot be published as it is out of range.

Based on the releases published on other branches, only versions within the range >=1.0.0 <1.1.0 can be published from branch master.

The following commits are responsible for the invalid release:

  • feat: force a deployment (f6f966b)
  • ci: fix release action (dc73b37)
  • ci: fix deploy action (2746668)
  • ci: fix semantic release github action (47e9f1b)
  • ci: remove travis deploy (10b8d7b)
  • ci: add github action: semantic release (9021961)
  • Create codeql-analysis.yml (7c94cde)
  • chore(deps): bump npm-user-validate from 1.0.0 to 1.0.1 (87d9eec)

Those commits should be moved to a valid branch with git merge or git cherry-pick and removed from branch master with git revert or git reset.

A valid branch could be next.

See the workflow configuration documentation for more details.


Good luck with your project ✨

Your semantic-release bot πŸ“¦πŸš€

Question

Hi Izear
Thanks for your great work here. We are using your repo in our app Forby.io and we would like to add 2 algorithms based on some research we came across:

Minimax-TD

https://drive.google.com/file/d/1ZvId-tdOLb4vWp0pm5XZaBK2FkqkXLXh/view?usp=share_link

And Score Voting:
https://en.wikipedia.org/wiki/Score_voting
Just adds up the scores. We are using +5 to -5 as our options.

Are you interested in adding these?
I am willing to hire someone to develop these.
Thanks,
[email protected]

In-browser use

Hi,

have you tried/had success with adapting this package for in-browser use?

Cannot resolve Lodash dependencies from Webpack + TypeScript

First, I just want to say thanks for publishing this library! This is a high-quality resource for running different types of voting algorithms. I'm interested in using this library for hobby purposes.


I'm trying to run this library from a Webpack config, but I'm running into error messages that resemble the following:

ERROR in ./node_modules/votes/dist/index.mjs 1:895-929
Module not found: Error: Can't resolve 'lodash/difference' in '[...]\node_modules\votes\dist'
Did you mean 'difference.js'?
BREAKING CHANGE: The request 'lodash/difference' failed to resolve only because it was resolved as fully specified
(probably because the origin is strict EcmaScript Module, e. g. a module with javascript mimetype, a '*.mjs' file, or a '*.js' file where the package.json contains '"type": "module"').
The extension in the request is mandatory for it to be fully specified.
Add the extension to the request.

The Webpack config I'm using comes from the official Webpack + TypeScript docs.

I'm able to resolve this issue by following these steps. Can we provide an out-of-the-box fix for this, though?

Additional information:

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.