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

scalable-majority-judgment

v1.0.2

Published

[![MIT](https://img.shields.io/github/license/MieuxVoter/majority-judgment-library-typescript?style=for-the-badge)](LICENSE) [![Release](https://img.shields.io/github/v/release/MieuxVoter/majority-judgment-library-typescript?include_prereleases&style=for-

Downloads

10

Readme

Majority Judgment for Typescript

MIT Release Build Status Code Quality LoC Discord Chat

This typescript package helps to resolve polls using Majority Judgment.

Features

  • Efficient Majority Judgment algorithm, scales well to billions of participants
  • Configure whether to favor adhesion or contestation (default)
  • Balance proposal tallies using a static default grade or the median grade
  • Room for Central Judgment and Usual Judgment
  • Unit-tested (run npm run converage)

Install

npm install scalable-majority-judgment

Get started

Majority judgment from ballots

import {
    TallyCollector,
    MajorityJudgmentDeliberator,
    IDeliberator,
    IResult,
} from "majority-judgment";

const proposalAmount: number = 5;
const mentionAmount: number = 7;
const voterAmount: number = 1000;
const tally: TallyCollector = new TallyCollector(proposalAmount, mentionAmount);
fillTallyCollectorWithRandomVote(tally, voterAmount);

const deliberator: IDeliberator = new MajorityJudgmentDeliberator();
const result: IResult = deliberator.deliberate(tally);

for (let i: number = 0; i < proposalAmount; i++)
    console.log(
        `Proposal at index ${i} obtains the rank ${result.proposalResults[i].rank} with the majority mention at index ${result.proposalResults[i].analysis.medianMentionIndex}`
    );

function fillTallyCollectorWithRandomVote(tally: TallyCollector, voterAmount: number): void {
    const applyRandomVoteForEachProposal = () => {
        let randomProposalIndex: number;
        let randomMentionIndex: number;

        for (let i: number = 0; i < proposalAmount; i++) {
            randomProposalIndex = Math.floor(Math.random() * proposalAmount);
            randomMentionIndex = Math.floor(Math.random() * mentionAmount);
            tally.collect(randomProposalIndex, randomMentionIndex);
        }
    };

    for (let i: number = 0; i < voterAmount; i++) applyRandomVoteForEachProposal();
}

Known datas

import {
    MajorityJudgmentDeliberator,
    IDeliberator,
    IResult,
    ITally,
    Tally,
    Proposal,
} from "majority-judgment";

const meritProfileSample: bigint[] = [4n, 0n, 2n, 1n];
// index 0 = worst mention, 4 vote
// max index (3) = best mention, 1 vote

const tally: ITally = new Tally([
    new Proposal(meritProfileSample),
    new Proposal([2n, 1n, 0n, 4n]),
    new Proposal([3n, 2n, 1n, 1n]),
]);

const deliberator: IDeliberator = new MajorityJudgmentDeliberator();
const result: IResult = deliberator.deliberate(tally);
const proposalAmount: number = tally.proposalAmount;

for (let i: number = 0; i < proposalAmount; i++)
    console.log(
        `Proposal at index ${i} obtains the rank ${result.proposalResults[i].rank} with the majority mention at index ${result.proposalResults[i].analysis.medianMentionIndex}`
    );

// Note: the sum vote in proposal must be equal. If not, the deliberator will throw an error.

Majority judgment where voters did not vote for every proposal

import { ITally, Proposal, NormalizedTally } from "majority-judgment";

// If the sum vote in proposal are not equal. You can use NormalizedTally.
const tally: ITally = new NormalizedTally([
    new Proposal([4n, 0n, 2n, 10n]),
    new Proposal([20n, 10n, 0n, 4n]),
    new Proposal([3n, 200n, 100n, 1n]),
]);

// (...) Same logic

Contribute

Usual git flow: clone, tinker, request a merge.

Authors

This package was made by MieuxVoter, a French nonprofit.