🚨 Shai-Hulud Strikes Again:834 Packages Compromised.Technical Analysis →
Socket
Book a DemoInstallSign in
Socket

@nrk/valg-valgomat-algoritme

Package Overview
Dependencies
Maintainers
183
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@nrk/valg-valgomat-algoritme

The algorithm used to calculate distance between sets of positions for NRKs Valgomat

latest
Source
npmnpm
Version
5.0.0
Version published
Maintainers
183
Created
Source

Valgomat algorithm

Calculate the proximity of two sets of positions.

Calculates the proximity of two sets of positions. Mostly used to calculate the proximity of various party positions and a voter position.

Usage

The simple case is comparing to sets of positions.

import { proximity } from '@nrk/valg-valgomat-algoritme'

let partyPositions = {
  id1: 1,
  id2: -1
}

let voterPositions = {
  id1: -2,
  id2: 2
}

let p = proximity(partyPositions, voterPositions)
// => 0.25

The module also comes with a function to compare many positions to one position.

import { proximityMap } from '@nrk/valg-valgomat-algoritme'

let partyAPositions = {
  id1: 1,
  id2: -1
}

let partyBPositions = {
  id1: 2,
  id2: -2
}

let partyPostitions = {
  partyA: partyAPositions,
  partyB: partyBPositions
}

let voterPositions = {
  id1: null,
  id2: -2
}

let proximities = proximityMap(voterPositions, partyPositions)
// => { "partyA": 0.75, "partyB": 1.0 }

API

import { proximity, proximityMap } from '@nrk/valg-valgomat-algoritme'

let d = proximity(positionsA, positionsB);

Accepts two sets of positions and returns the proximity between them.

Positions are given in the form of sets:

{
  [statement: string]: -2 | -1 | 1 | -2 | null
}

Output will be a number in the interval [0.0, 1.0] where 0.0 is the furthest away and 1.0 is the closest possible proximity (iow. identical).

If we are unable to determine a proximity, the output will be null. This happens if we are comparing a pair of vectors where one of the vectors are empty or there are no overlapping statements.

let proximities = proximityMap(positionsA, positionsMap);

Accepts a set of positions and a map of many sets of positions and returns a map of the proximities between a position in the position map and the first position.

This is useful if you want to calculate the proximity of one set of positions and many sets of positions. For instance between all parties and a single voter.

Output will be a map from the keys in the positionsMap and the proximity to the given position.

Installation

npm install @nrk/valg-valgomat-algoritme

Glossary

  • Position = Standpunkt
  • Statement = PĂĄstand
  • Party = Parti
  • Voter = Velger

Keywords

nrk

FAQs

Package last updated on 30 Apr 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts