PHP Classes

Calculadora Escons: Calculate elected seats using D'Hondt method

Recommend this page to a friend!
  Info   View files View files (3)   DownloadInstall with Composer Download .zip   Reputation   Support forum (1)   Blog    
Ratings Unique User Downloads Download Rankings
StarStarStarStar 64%Total: 313 This week: 1All time: 7,278 This week: 560Up
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: 50
All time rank: 216250 in Spain Spain
Week rank: 416 Up14 in Spain Spain Up
Innovation award
Innovation award
Nominee: 1x

Details

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 http://www.gnu.org/copyleft/gpl.html

  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:313
This week:1
All time:7,278
This week:560Up
 User Ratings  
 
 All time
Utility:83%StarStarStarStarStar
Consistency:75%StarStarStarStar
Documentation:75%StarStarStarStar
Examples:75%StarStarStarStar
Tests:-
Videos:-
Overall:64%StarStarStarStar
Rank:725