Why make donate

VoteCounting

author : Nolwenn Rannou <rannou@codelutin.com>
revision : 2773
date : 2009-09-09 12:05:20 +0200 (mer., 09 sept. 2009)

This part describe the VoteCounting module implementation.

There are 2 interfaces :

  • ServiceVoteCounting : Vote couting management service.
  • ServicePollExport : Poll and results export management service.

ServiceVoteCounting

DTOVoteCounting

The VoteCounting DTOs (Data Transfer Object) allow to use correctly the interfaces exposed by the VoteCounting module.

There are two important root DTOs :

  • PollDTO : Correspond to a poll and all the important elements for vote counting.
  • VoteCountingResultDTO : The vote counting result organized following the poll's

choices.

PollExportDTO have been added for exports. It conatines a PollDTO and several VoteCountingResultDTOs.

Two enumerations are also available and allows the types normalization :

  • PollType : Poll type (Group, Free, Restricted, ...)
  • VoteCountingType : Vote counting type (Condorcet, Percentage, ...)

Please note that the VoteCountingType is used as reference for a poll vote counting.

VoteCounting module DTO

PollDTO

It is coumpounded of PollChoiceDTO (the poll's choices) and Comment DTO (the poll's comments).

It is compounded of VotingGroupDTO. This one correspond to group of voters in case of a group typed poll. In case of another type, there will be one and only one VotingGroupDTO with null values (weight and idGroup).

Each VotingGroupDTO is compounded of VotingPersonDTO corresponding to voters linked to the poll (people who have already voted). The votingID will be "anonymous" in case of an anonymous poll.

Each VotingPersonDTO is compounded of VoteToChoiceDTOs corresponding to the voter's votes (for each choice a value).

It is not necessary to know all the choices in advance at the poll's level. The vote counting will manage the organization of the results regarding the choices.

VoteCountingResultDTO

The results are shared out according to the poll's choices. A ResultDTOV is compouded of ChoiceDTOVs corresponding to those choices.

So for a poll we have :

  • the global result (VoteCountingResultDTO.choiceResult)
  • the result per choice (ChoiceDTO.value)

Operations

  • executeVoteCounting(poll : PollDTO) : VoteCountingResultDTO

This operation allows to execute a poll's vote counting.

  • executeGroupCounting(poll : PollDTO) : VoteCountingResultDTO

This operation allows the execution of a poll's vote counting functions of groups.

Implementation

The Strategy Pattern is used to manage the vote counting. A Context class allows to define which strategy type to use. The strategy is defined at the beginning with PollDTO's typeVoteCounting attribute.

Here the strategies are represented by the Method interface that will be implemented by :

  • CondorcetMethod : Vote counting using the Condorcet criterion.
  • StandardMethod : Normal vote counting.
  • PercentageMethod : Vote counting using choices balancing.

Each method implements the "executeMethod(choices)" operation that will be called in the Context class by the "execute()" method. So the context needs to know all the choices and the votes by choice and by group.

When calling for ServiceVoteCounting, a new context will be created and the PollDTO will be scanned to create the choices, groups and votes needed for the vote counting.

VoteCounting service implementation diagram.

Execution

  • Call to executeVoteCounting
  • Context creation depending on PollDTO.typeVoteCounting
  • Scan PollChoiceDTOs : Add the choices to the context.
  • Scan VotingGroupDTOs : For each group -> VoteCounting.routeGroup(VotingGroupDTO)

(with group adding to the context Context.addGroup(idGroup, weight)) - Scan VotingPersonDTO : For each people -> VoteCounting.routePerson(VotingPersonDTO) - Scan Vote : For each choice -> add it to the context via Context.getChoice(idChoice).getGroup(VoteCounting.currentIdGroup).addVote(value, weight) - Execute the vote counting method -> Context.execute() - Create the VoteCountingResultDTO that contains all the choices with their results.

Sequence diagram of a normal vote counting (without algorithm details)

Condorcet vote counting

With a classical vote counting, the winner is the one that has the biggest number of voices. With the Condorcet method that is not necessarily the case. The winner is the one that, compared to each other candidate, is always prefered. In certain situations, such a winner does not exist, this is what we call the Condorcet paradox (A>B>C>A). The algorithm chosen in Pollen consit in chosing the candidate that won more duels. In case of deuce a vote needs to be done between the leading group.

A condorcet vote sequence is the following :

  1. The voters sort the candidates by preference order
  2. For each vote, we compare the condidtaes rankings by pairs and we count the

number of wins of each candidate 3. The winner is the one that have the greatest number of victories.

In Pollen, the implementation of Condorcet vote has in addition the notion of voters groups. In cas of vote counting by groups, the algorithm is applied for each groups, and then applied a second time between the results of each group. When the voters vote in a poll, they can make two choices equals. It is not necessary to sort all the choices, those which are not ranked will be all last.

ServicePollExport

Operations

  • executeExport(export : PollExportDTO) : String

This is the main operation that allows the poll export, the object given in parameter contains the poll object and a list of the results to export. Those results are obtained by the different vote counting methods. This methods returns the name of the exported file.

  • executeImport(path : String) : PollExportDTO

This operation imports the poll and its results from the file which path is given in parameter, so it builds the PollExportDTO return by this method.

Export implementation

An easy implementation have been made for this part. Itturns out that the Visitor pattern use is significant for this module implementation as it works the same way that the Visitor pattern, but to do so, we need to add methods to the DTO classes that violates their semantics, so we proceeded as shown in the following diagram.

PollExport service implementation diagram.

Export result

To conceive Pollen's poll export module, we needed to specify the wanted result. To do so we have done an UML modelisation to extract the tree architecture of our export. Have a look to the following class diagram :

Class diagram of a poll and its results export