API Documentation

Calculate Seats
POST /nz_election/api/calculateSeats

Calculates the number of seats that each party receives based off of the MMP Method, with the Sainte-Laguë allocation method.

Body Content Type: application/json

Information about the party votes, electorate seats won, and general election setup that is used to calculate the allocated seats.

votes
map[string][float]

A map of the number of votes that each party has got.

Here, the key of the map represents the party (any unique string), while the value is the number of votes that that party received. Note that the number of votes can be a fractional number if you want to represent this as percentages. Any party not present in this map is assigned 0 votes.

electorate_seats
map[string][integer]

A map of the number of electorate seats that each party has got.

Here, the key of the map represents the party (any unique string), while the value is the number of electorate seats that that party received. Note that the number of electorate seats must be an integer. Any party not present in this map is assigned 0 electorate seats.

total_seats
integer

The total number of seats that are available to be allocated by the MMP system.

In the case of the New Zealand election, this number is equal to 120.

threshold
float

The required threshold that a party's vote must reach in order to be allocated any seats. This number must be represented as the fractional representation.

In the case of the New Zealand election, this number is equal to 0.05 (5%).

Example

{
	"votes": {
		"0": 1000,
		"2": 10
	},
	"electorate_seats": {
		"0": 1,
		"1": 1
	},
	"total_seats": 120,
	"threshold": 0.05
}

Response

Information about the allocation of seats generated by the allocation method.

seats
map[string][integer]

A map of the number of seats that each party has received.

Here, the key of the map represents the party (using the same unique string as provided in the request), while the value is the number of seats that the party received.

total
integer

The total number of seats allocated. Note that this may be greater than the input value total_seats due to electorate seats (known as "overhang").

Example

{
    "seats": {
        "0": 120,
        "2": 0,
        "1": 1
    },
    "total": 121
}