@@ -4,38 +4,38 @@ |
||
4 | 4 | |
5 | 5 | class Ballot |
6 | 6 | { |
7 | - /** |
|
8 | - * Ranking of candidates ids |
|
9 | - * |
|
10 | - * @var array |
|
11 | - */ |
|
12 | - protected $ranking; |
|
7 | + /** |
|
8 | + * Ranking of candidates ids |
|
9 | + * |
|
10 | + * @var array |
|
11 | + */ |
|
12 | + protected $ranking; |
|
13 | 13 | |
14 | - /** |
|
15 | - * The current weighting or value of this person's vote |
|
16 | - * |
|
17 | - * @var float |
|
18 | - */ |
|
19 | - protected $weight; |
|
14 | + /** |
|
15 | + * The current weighting or value of this person's vote |
|
16 | + * |
|
17 | + * @var float |
|
18 | + */ |
|
19 | + protected $weight; |
|
20 | 20 | |
21 | - /** |
|
22 | - * The current preference in use from this ballot |
|
23 | - * |
|
24 | - * @var integer |
|
25 | - */ |
|
26 | - protected $levelUsed; |
|
21 | + /** |
|
22 | + * The current preference in use from this ballot |
|
23 | + * |
|
24 | + * @var integer |
|
25 | + */ |
|
26 | + protected $levelUsed; |
|
27 | 27 | |
28 | - /** |
|
29 | - * Constructor |
|
30 | - * |
|
31 | - * @param array $ranking The ranking of candidates Key being ranking, |
|
32 | - * value being a candidate id |
|
33 | - */ |
|
34 | - public function __construct(array $ranking) |
|
35 | - { |
|
36 | - $this->weight = 1.0; |
|
37 | - $this->ranking = $ranking; |
|
38 | - $this->levelUsed = 0; |
|
28 | + /** |
|
29 | + * Constructor |
|
30 | + * |
|
31 | + * @param array $ranking The ranking of candidates Key being ranking, |
|
32 | + * value being a candidate id |
|
33 | + */ |
|
34 | + public function __construct(array $ranking) |
|
35 | + { |
|
36 | + $this->weight = 1.0; |
|
37 | + $this->ranking = $ranking; |
|
38 | + $this->levelUsed = 0; |
|
39 | 39 | } |
40 | 40 | |
41 | 41 | /** |
@@ -33,7 +33,7 @@ discard block |
||
33 | 33 | |
34 | 34 | public function calculateElectionResult(Poll $poll): array |
35 | 35 | { |
36 | - return getElectionResults($poll); |
|
36 | + return getElectionResults($poll); |
|
37 | 37 | } |
38 | 38 | |
39 | 39 | public function submitVotes(array $choices) |
@@ -43,12 +43,12 @@ discard block |
||
43 | 43 | |
44 | 44 | public function getElectionPollVotes(Poll $poll): array |
45 | 45 | { |
46 | - return []; |
|
46 | + return []; |
|
47 | 47 | } |
48 | 48 | |
49 | 49 | public function getElectionResults(Poll $poll): array |
50 | 50 | { |
51 | - return []; |
|
51 | + return []; |
|
52 | 52 | } |
53 | 53 | |
54 | 54 | public function getElectionWinner(Poll $poll): AppBundle\Entity\Choice |
@@ -11,19 +11,19 @@ discard block |
||
11 | 11 | protected $pollRepo; |
12 | 12 | protected $electionManager; |
13 | 13 | |
14 | - /** |
|
15 | - * Constructor |
|
16 | - * |
|
17 | - * @param EntityManager $entityManager |
|
18 | - */ |
|
19 | - public function __construct(EntityManager $entityManager, ElectionManager $electionManager) |
|
20 | - { |
|
21 | - $this->entityManager = $entityManager; |
|
22 | - $this->repo = $this->entityManager->getRepository('AppBundle:Poll'); |
|
14 | + /** |
|
15 | + * Constructor |
|
16 | + * |
|
17 | + * @param EntityManager $entityManager |
|
18 | + */ |
|
19 | + public function __construct(EntityManager $entityManager, ElectionManager $electionManager) |
|
20 | + { |
|
21 | + $this->entityManager = $entityManager; |
|
22 | + $this->repo = $this->entityManager->getRepository('AppBundle:Poll'); |
|
23 | 23 | $this->electionManager = $electionManager; |
24 | - } |
|
24 | + } |
|
25 | 25 | |
26 | - /** |
|
26 | + /** |
|
27 | 27 | * Get an array of current polls (objects) |
28 | 28 | * |
29 | 29 | * @return array |
@@ -43,7 +43,7 @@ discard block |
||
43 | 43 | */ |
44 | 44 | public function getEligibleVoters(PollType $type): array |
45 | 45 | { |
46 | - return []; |
|
46 | + return []; |
|
47 | 47 | } |
48 | 48 | |
49 | 49 | /** |
@@ -53,9 +53,9 @@ discard block |
||
53 | 53 | */ |
54 | 54 | public function getAllPolls(): array |
55 | 55 | { |
56 | - $polls = $this->repo->findAll(); |
|
56 | + $polls = $this->repo->findAll(); |
|
57 | 57 | |
58 | - return $polls; |
|
58 | + return $polls; |
|
59 | 59 | } |
60 | 60 | |
61 | 61 | /** |
@@ -66,10 +66,10 @@ discard block |
||
66 | 66 | */ |
67 | 67 | public function getPollStats(Poll $poll): array |
68 | 68 | { |
69 | - // If Poll is election then reject |
|
69 | + // If Poll is election then reject |
|
70 | 70 | |
71 | - // Get standard stats |
|
72 | - return []; |
|
71 | + // Get standard stats |
|
72 | + return []; |
|
73 | 73 | } |
74 | 74 | |
75 | 75 | /** |
@@ -80,19 +80,19 @@ discard block |
||
80 | 80 | */ |
81 | 81 | public function getPollResult(Poll $poll): Choice |
82 | 82 | { |
83 | - // If election then call Election Manager |
|
83 | + // If election then call Election Manager |
|
84 | 84 | |
85 | - // Calculate winning choice |
|
86 | - return; |
|
85 | + // Calculate winning choice |
|
86 | + return; |
|
87 | 87 | } |
88 | 88 | |
89 | 89 | public function getStandardPollVotes(Poll $poll): array |
90 | 90 | { |
91 | - return []; |
|
91 | + return []; |
|
92 | 92 | } |
93 | 93 | |
94 | 94 | public function markPollClosed(Poll $poll) |
95 | 95 | { |
96 | - return; |
|
96 | + return; |
|
97 | 97 | } |
98 | 98 | } |
@@ -6,99 +6,99 @@ |
||
6 | 6 | |
7 | 7 | class Election |
8 | 8 | { |
9 | - /** |
|
10 | - * Count of candidates in election |
|
11 | - * |
|
12 | - * @var int |
|
13 | - */ |
|
14 | - protected $candidateCount; |
|
15 | - |
|
16 | - /** |
|
17 | - * Count of number of seats/winners |
|
18 | - * |
|
19 | - * @var int |
|
20 | - */ |
|
21 | - protected $winnersCount; |
|
22 | - |
|
23 | - /** |
|
24 | - * Array of candidates competing in election |
|
25 | - * |
|
26 | - * @var array |
|
27 | - */ |
|
28 | - protected $candidates; |
|
29 | - |
|
30 | - /** |
|
31 | - * Array of ballots cast in election |
|
32 | - * |
|
33 | - * @var array |
|
34 | - */ |
|
35 | - protected $ballots; |
|
36 | - |
|
37 | - /** |
|
38 | - * Constructor |
|
39 | - * |
|
40 | - * @param int $winnersCount Number of winners to allocate |
|
41 | - * @param array $candidates Array of candidates competing |
|
42 | - * @param array $ballots Array of all ballots cast in election |
|
43 | - */ |
|
44 | - public function __construct(int $winnersCount, array $candidates, array $ballots) |
|
45 | - { |
|
46 | - $this->winnersCount = $winnersCount; |
|
47 | - $this->candidates = $candidates; |
|
48 | - $this->ballots = $ballots; |
|
49 | - $this->candidateCount = count($candidates); |
|
50 | - } |
|
51 | - |
|
52 | - /** |
|
53 | - * Get a specific candidate object by their ID |
|
54 | - * |
|
55 | - * @param int $id ID of the candidate to get |
|
56 | - * @return \Michaelc\Voting\STV\Candidate |
|
57 | - */ |
|
58 | - public function getCandidate(int $id): Candidate |
|
59 | - { |
|
60 | - return $this->candidates[$id]; |
|
61 | - } |
|
62 | - |
|
63 | - /** |
|
64 | - * Get a count of candidates competing |
|
65 | - * |
|
66 | - * @return int |
|
67 | - */ |
|
68 | - public function getCandidateCount(): int |
|
69 | - { |
|
70 | - return $this->candidateCount; |
|
71 | - } |
|
72 | - |
|
73 | - /** |
|
74 | - * Get an array of candidates still running (not elected or defeated) |
|
75 | - * |
|
76 | - * @return \Michaelc\Voting\STV\Candidate[] |
|
77 | - */ |
|
78 | - public function getActiveCandidates(): array |
|
79 | - { |
|
80 | - $activeCandidates = []; |
|
81 | - |
|
82 | - foreach ($this->candidates as $candidateId => $candidate) |
|
83 | - { |
|
84 | - if ($candidate->getState() == Candidate::RUNNING) |
|
85 | - { |
|
86 | - $activeCandidates[$candidateId] = $candidate; |
|
87 | - } |
|
88 | - } |
|
89 | - |
|
90 | - return $activeCandidates; |
|
91 | - } |
|
92 | - |
|
93 | - /** |
|
94 | - * Get a count of candidates still running (not elected or defeated) |
|
95 | - * |
|
96 | - * @return int |
|
97 | - */ |
|
98 | - public function getActiveCandidateCount(): int |
|
99 | - { |
|
100 | - return count($this->getActiveCandidates()); |
|
101 | - } |
|
9 | + /** |
|
10 | + * Count of candidates in election |
|
11 | + * |
|
12 | + * @var int |
|
13 | + */ |
|
14 | + protected $candidateCount; |
|
15 | + |
|
16 | + /** |
|
17 | + * Count of number of seats/winners |
|
18 | + * |
|
19 | + * @var int |
|
20 | + */ |
|
21 | + protected $winnersCount; |
|
22 | + |
|
23 | + /** |
|
24 | + * Array of candidates competing in election |
|
25 | + * |
|
26 | + * @var array |
|
27 | + */ |
|
28 | + protected $candidates; |
|
29 | + |
|
30 | + /** |
|
31 | + * Array of ballots cast in election |
|
32 | + * |
|
33 | + * @var array |
|
34 | + */ |
|
35 | + protected $ballots; |
|
36 | + |
|
37 | + /** |
|
38 | + * Constructor |
|
39 | + * |
|
40 | + * @param int $winnersCount Number of winners to allocate |
|
41 | + * @param array $candidates Array of candidates competing |
|
42 | + * @param array $ballots Array of all ballots cast in election |
|
43 | + */ |
|
44 | + public function __construct(int $winnersCount, array $candidates, array $ballots) |
|
45 | + { |
|
46 | + $this->winnersCount = $winnersCount; |
|
47 | + $this->candidates = $candidates; |
|
48 | + $this->ballots = $ballots; |
|
49 | + $this->candidateCount = count($candidates); |
|
50 | + } |
|
51 | + |
|
52 | + /** |
|
53 | + * Get a specific candidate object by their ID |
|
54 | + * |
|
55 | + * @param int $id ID of the candidate to get |
|
56 | + * @return \Michaelc\Voting\STV\Candidate |
|
57 | + */ |
|
58 | + public function getCandidate(int $id): Candidate |
|
59 | + { |
|
60 | + return $this->candidates[$id]; |
|
61 | + } |
|
62 | + |
|
63 | + /** |
|
64 | + * Get a count of candidates competing |
|
65 | + * |
|
66 | + * @return int |
|
67 | + */ |
|
68 | + public function getCandidateCount(): int |
|
69 | + { |
|
70 | + return $this->candidateCount; |
|
71 | + } |
|
72 | + |
|
73 | + /** |
|
74 | + * Get an array of candidates still running (not elected or defeated) |
|
75 | + * |
|
76 | + * @return \Michaelc\Voting\STV\Candidate[] |
|
77 | + */ |
|
78 | + public function getActiveCandidates(): array |
|
79 | + { |
|
80 | + $activeCandidates = []; |
|
81 | + |
|
82 | + foreach ($this->candidates as $candidateId => $candidate) |
|
83 | + { |
|
84 | + if ($candidate->getState() == Candidate::RUNNING) |
|
85 | + { |
|
86 | + $activeCandidates[$candidateId] = $candidate; |
|
87 | + } |
|
88 | + } |
|
89 | + |
|
90 | + return $activeCandidates; |
|
91 | + } |
|
92 | + |
|
93 | + /** |
|
94 | + * Get a count of candidates still running (not elected or defeated) |
|
95 | + * |
|
96 | + * @return int |
|
97 | + */ |
|
98 | + public function getActiveCandidateCount(): int |
|
99 | + { |
|
100 | + return count($this->getActiveCandidates()); |
|
101 | + } |
|
102 | 102 | |
103 | 103 | /** |
104 | 104 | * Gets the value of winnersCount. |
@@ -4,48 +4,48 @@ |
||
4 | 4 | |
5 | 5 | class Candidate |
6 | 6 | { |
7 | - const ELECTED = 1; |
|
8 | - const RUNNING = 2; |
|
9 | - const DEFEATED = 3; |
|
10 | - |
|
11 | - /** |
|
12 | - * Identifier for the candidate |
|
13 | - * |
|
14 | - * @var integer |
|
15 | - */ |
|
16 | - protected $id; |
|
17 | - |
|
18 | - /** |
|
19 | - * Number of votes the candidate currently has |
|
20 | - * |
|
21 | - * @var float |
|
22 | - */ |
|
23 | - protected $votes; |
|
24 | - |
|
25 | - /** |
|
26 | - * Number of surplus votes the candidate has to be re-allocated |
|
27 | - * |
|
28 | - * @var float |
|
29 | - */ |
|
30 | - protected $surplus; |
|
31 | - |
|
32 | - /** |
|
33 | - * State of the candidate (use class constants) |
|
34 | - * |
|
35 | - * @var integer |
|
36 | - */ |
|
37 | - protected $state; |
|
38 | - |
|
39 | - /** |
|
40 | - * Constructor |
|
41 | - */ |
|
42 | - public function __construct(int $id) |
|
43 | - { |
|
44 | - $this->id = $id; |
|
45 | - $this->votes = 0.0; |
|
46 | - $this->surplus = 0.0; |
|
47 | - $this->state = self::RUNNING; |
|
48 | - } |
|
7 | + const ELECTED = 1; |
|
8 | + const RUNNING = 2; |
|
9 | + const DEFEATED = 3; |
|
10 | + |
|
11 | + /** |
|
12 | + * Identifier for the candidate |
|
13 | + * |
|
14 | + * @var integer |
|
15 | + */ |
|
16 | + protected $id; |
|
17 | + |
|
18 | + /** |
|
19 | + * Number of votes the candidate currently has |
|
20 | + * |
|
21 | + * @var float |
|
22 | + */ |
|
23 | + protected $votes; |
|
24 | + |
|
25 | + /** |
|
26 | + * Number of surplus votes the candidate has to be re-allocated |
|
27 | + * |
|
28 | + * @var float |
|
29 | + */ |
|
30 | + protected $surplus; |
|
31 | + |
|
32 | + /** |
|
33 | + * State of the candidate (use class constants) |
|
34 | + * |
|
35 | + * @var integer |
|
36 | + */ |
|
37 | + protected $state; |
|
38 | + |
|
39 | + /** |
|
40 | + * Constructor |
|
41 | + */ |
|
42 | + public function __construct(int $id) |
|
43 | + { |
|
44 | + $this->id = $id; |
|
45 | + $this->votes = 0.0; |
|
46 | + $this->surplus = 0.0; |
|
47 | + $this->state = self::RUNNING; |
|
48 | + } |
|
49 | 49 | |
50 | 50 | /** |
51 | 51 | * Gets the Identifier for the candidate. |