PHP Classes

Calculadora Escons: Calculate elected seats using D'Hondt method

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in Bookmark in
  Info   View files View files (3)   DownloadInstall with Composer Download .zip   Reputation   Support forum (1)   Blog    
Last Updated Ratings Unique User Downloads Download Rankings  
2007-07-01 (8 years ago) RSS 2.0 feedNot enough user ratingsTotal: 284 All time: 6,947 This week: 1,020Up
Version License PHP version Categories  
calculadoraescons 1.1GNU General Publi...5.0Algorithms
Description Author  

This class can be used to calculate the number of seats assigned to a party upon election results using the D'Hondt method.

It takes as parameters the number of available seats and an associative array that relates each party with the votes they received.

The class distributes the available seats using the D'Hondt method and returns an associative arrays that relates each party with the number of assigned seats that they got.

The code and the comments are in Catalan.

Innovation Award  
PHP Programming Innovation award nominee
June 2007
Number 10
The D'Hondt method is used in many countries to calculate the number of seats assigned to a party, depending on the percentage of votes that they get in elections.

This class provides an implementation of the D'Hondt method. It can be used by PHP sites that want to show on the Web the partial or final results of elections that take place on countries that use this method of assigning elected seats.

Manuel Lemos
Picture of Manel Zaera
Name: Manel Zaera <contact>
Classes: 3 packages by
Country: Spain Spain
Age: 41
All time rank: 205848 in Spain Spain
Week rank: 1501 Up38 in Spain Spain Up
Innovation award
Innovation award
Nominee: 1x

CalculadoraEscons is a class that calculates the number of seats belonging to each party in an election process, using the D'Hondt's method.

To use this class you have to:

1.- Create an object:
$aCalc = new CalculadoraEscons();

2.- Call the class with the list of parties and votes collected by each of them, and the number of seats to distribute:
$aPartits = array('CiU' => 4367,'PSC' => 2252, 'ERC' => 2131,'ICV' => 403,'PP' => 287,'IPE' => 234);
$aEscons = $aCalc->calcula($aPartits,17);

The "calcula" method returns an array where the keys are the names of the parties and the values are the seats assigned to them.

2005-05-21, Manel Zaera
CalculadoraEscons is free software released under the GNU GPL license, la qual podeu consultar a
  Files folder image Files  
File Role Description
Plain text file CalculadoraEscons.php Class Class CalculdoraEscons
Accessible without login Plain text file exemple.php Example Sample file
Accessible without login Plain text file README Doc. README

 Version Control Unique User Downloads Download Rankings  
 0%Total:284All time:6,947
 This week:0This week:1,020Up