Skip to content

Advanced Results

Get metadata from Result object

php
$result = $electionWithVotes->getResult('Schulze');

$result->byClass; // Namespace of the Schulze module. Like 'CondorcetPHP\Condorcet\Algo\Methods\SchulzeWinning'
$result->fromMethod; // Method who build this result. Like 'Schulze'.
$result->electionCondorcetVersion; // Condorcet version at the build time.
$result->buildTimestamp; // Return timestamp (float) of the build time.

Get compute details

php
$electionWithVotes->getResult()->ranking; // An explicit array using your Candidate Name as keys.
$electionWithVotes->getResult()->stats; // Stats about computing result for the default object method.

Get result infos

Classical

INFO

Candidate object are not immutable, and a candidate can change his name at any moment. Despite that the history is keeped: if you play with that powerful but dangerous simulations tools, result object can produce surprising results if your are not vigilant. If you follow a simpler use, you don't care.
More information on the Mutability chapter.

php
$electionWithVotes->getResult('Schulze')->CondorcetWinner; // Equivalent to $electionWithVotes->getWinner('Schulze');
$electionWithVotes->getResult('Schulze')->CondorcetLoser; // Equivalent to $electionWithVotes->getLoser('Schulze');

$electionWithVotes->getResult('Schulze')->CondorcetWinner ; // Get the condorcet winner from the parent election at the build time (can became different. This one never change) or null if he don't exist.
$electionWithVotes->getResult('Schulze')->CondorcetLoser ; // Get the condorcet loser from the parent election at the build time (can became different. This one never change) or null if he don't exist.

$electionWithVotes->getResult('Schulze')->ranking ; // Return Result ranking as array. So, the original Result object is iterable, support array access and count... Why doing that ?
$electionWithVotes->getResult('Schulze')->rankingAsArrayString ; // Same thing. But more: that convert Candidate object into string by name.

Strictly immutable

INFO

These two methods are strictly immutable and provide the string name at the moment of the creation of the result object.

php
$result = $electionWithVotes->getResult();

$result->originalRankingAsArrayString; // Returns the result as an array with Candidate as string by name. Because Candidate name can continue to change (Even if you can get the history of the changes). This method gives you reliability.
$result->originalRankingAsString; // Returns a string like "A > B = C > D > E > G = H"

Released under the MIT License.