Skip to content

Election files formats

From Condorcet Election Format, from Debian Tally Format, from David Hill Format.

From Condorcet Election Format

$file can be a string file path, or a \SplFileInfo (or \SplFileObject, \SplTempFileObject

php
use CondorcetPHP\Condorcet\Tools\Converters\CEF\CondorcetElectionFormat;

$condorcetFormat = new CondorcetElectionFormat('election.cef');

// Create a new election from format, with all data
$election = $condorcetFormat->setDataToAnElection(); # CondorcetPHP\Condorcet\Election

From Debian Format

php
use CondorcetPHP\Condorcet\Tools\Converters\DebianFormat;

$debianFormat = new DebianFormat('debian_leader2020_tally.txt'); # CondorcetPHP\Condorcet\Tools\Converters\DebianFormat
$election = $debianFormat->setDataToAnElection(); # CondorcetPHP\Condorcet\Election

To set up parameters before set Data (but can be done after): <<< @/code_snippets/debian_format_with_params.php

From David Hill Format

php
use CondorcetPHP\Condorcet\Tools\Converters\DavidHillFormat;

$davidFormat = new DavidHillFormat('david_hill_format.hil'); # CondorcetPHP\Condorcet\Tools\Converters\DavidHillFormat
$election = $davidFormat->setDataToAnElection(); # CondorcetPHP\Condorcet\Election

To set up parameters before set Data (but can be done after):

php
use CondorcetPHP\Condorcet\Tools\Converters\DavidHillFormat;

$election = new Election;
$election->setImplicitRanking(false);

$davidFormat = new DavidHillFormat(__DIR__.'/DebianData/leader2020_tally.txt') # CondorcetPHP\Condorcet\Tools\Converters\DavidHillFormat
$election = $davidFormat->setDataToAnElection($election); # CondorcetPHP\Condorcet\Election

Convert an election (or another format) to Condorcet Election Format

php
use CondorcetPHP\Condorcet\Tools\Converters\DebianFormat;
use CondorcetPHP\Condorcet\Tools\Converters\CEF\CondorcetElectionFormat;

// Convert Debian Format to an election
$election = new DebianFormat('debian_leader2020_tally.txt')->setDataToAnElection();

# Return the Condorcet Election Format for this election
CondorcetElectionFormat::createFromElection($election);

# Write to a file
$myFile = new \SplTempFileObject;
CondorcetElectionFormat::createFromElection(election: $election, file: $myFile);

Released under the MIT License.