The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Vote::Count::RankCount

VERSION 1.213

Rank

Takes a single argument of a hashref containing Choices as Keys and Votes as Values. Returns an Object. This method is also aliased as new.

newFromList

Takes an ordered list and returns a RankCount Object where the RawCount values are zero minus the position: Item 3 in the list will have -3 votes while Item 1 will have -1.

  my $ordered_rank_count = Vote::Count::RankCount->newFromList( @ordered_list );

Methods

The following Methods are available from RankCount Objects.

RawCount

Returns the original HashRef used for Object Creation.

HashWithOrder

Returns a HashRef with the Choices as Keys and the position of the choice, the value for the Leader would be 1 and the Third Place Choice would be 3. If choices are tied they will share the same value for their position.

HashByRank

Returns a HashRef where the keys are numbers and the values an ArrayRef of the Choices in that position. The ArrayRefs are sorted alphanumerically.

ArrayTop, ArrayBottom

Returns an ArrayRef of the Choices in the Top or Bottom Positions.

OrderedList

Returns the array that was to create the RankCount object if it was created from a List. Returns an exception if the object was created from a HashRef, because RankCount does not deal with ties. Returning a list with ties resolved by randomness or a sort would not be correct.

CountVotes

Returns the number of votes in the RawCount. This is not the same as the votes in the BallotSet from which that was derived. For TopCount it is the number of non-exhausted ballots in the round that generated RawCount, for Approval and Boorda it is probably not useful.

Leader

Returns a HashRef with the keys tie, tied, winner where winner is the winner, tie is true or false and tied is an array ref of the choices in the tie.

RankTable

Generates a MarkDown formatted table.

  say $Election->TopCount->RankTable;

  | Rank | Choice     | Votes |
  |------|------------|-------|
  | 1    | VANILLA    | 7     |
  | 2    | MINTCHIP   | 5     |

RankTableWeighted ($votevalue)

Ranktable for use with weighted votes. Displays both the Vote Value and the Vote Total (rounded to two places). Requires Vote Value as an argument.

  say $WeightedElection->TopCount->RankTableWeighted( 100 );

  | Rank | Choice     | Votes | VoteValue |
  |:-----|:-----------|------:|----------:|
  | 1    | VANILLA    |  7.00 |       700 |
  | 2    | MINTCHIP   |  5.00 |       500 |

BUG TRACKER

https://github.com/brainbuz/Vote-Count/issues

AUTHOR

John Karr (BRAINBUZ) brainbuz@cpan.org

CONTRIBUTORS

Copyright 2019-2021 by John Karr (BRAINBUZ) brainbuz@cpan.org.

LICENSE

This module is released under the GNU Public License Version 3. See license file for details. For more information on this license visit http://fsf.org.

SUPPORT

This software is provided as is, per the terms of the GNU Public License. Professional support and customisation services are available from the author.