Elect a candidate after they've passed the threshold.

@param Candidate $candidate
500220
protected function electCandidate(Candidate $candidate)
    {
        $this->logger->notice("Electing a candidate: $candidate");

        $candidate->setState(Candidate::ELECTED);
        ++$this->electedCandidates;
        --$this->candidatesToElect;

        if ($this->electedCandidates < $this->election->getWinnersCount()) {
            $surplus = $candidate->getVotes() - $this->quota;
            if ($surplus > 0) {
                $this->transferSurplusVotes($surplus, $candidate);
            } else {
                $this->logger->notice("No surplus votes from $candidate to reallocate");
            }
        }

        return;
    }
23965
protected function checkCandidates(array $candidates): bool
    {
        $elected = false;
        $candidatesToElect = [];

        $this->logger->info('Checking if candidates have passed quota');

        if (empty($candidates)) {
            throw new LogicException('There are no more candidates left');
        }

        foreach ($candidates as $i => $candidate) {
            if ($candidate->getState() !== Candidate::RUNNING) {
                throw new LogicException('Candidate is not marked as not running but has not been excluded');
            }

            $votes = $candidate->getVotes();

            $this->logger->debug("Checking candidate ($candidate) with $votes", ['candidate' => $candidate]);

            // p. 48(1)
            // Immediately elect a candidate if they hit the quota
            // We check all the candidates, see who has hit the quota,
            // add them to a queue, then elect those who have hit the quota to prevent
            // surplus allocations pushing a candidate over the quota early.
            if ($votes >= $this->quota) {
                $candidatesToElect[] = $candidate;
                $elected = true;
            }
        }

        // TODO: Put this in a try, and catch the RuntimeError.
        // Then sort by the surplus, and fill available seats.
        // If have same surplus then select randomly (Contary to Scottish STV)
        // p. 50
        $this->electCandidates($candidatesToElect);

        $this->logger->info(('Candidate checking complete. Elected: '.count($candidatesToElect)));

        return $elected;
    }
474908
public function remove($item)
    {
        foreach ($this->currentList as $index => $candidate) {
            if ($candidate === $item) {
                unset($this->currentList[$index]);
            }
        }
    }
1182733
protected static function after(Element $element, string $phpExpression): void
    {
        $element->insertAfterSelf(
            static::toPhp($phpExpression)
        );
    }
983257
public function assignResultIDs($candidates)
    {
        foreach ($this->chained as $chid => $chained) {
            $chainedEvidence = $chained->getEvidence();
            $chainedExtid    = $chained->getRecordID();
            if (is_array($chainedExtid)) { //if there are more IDs
                foreach ($chainedExtid as $extId) { //find external ID in format ext:.....
                    if (stripos($extId, 'ext:') === 0) {
                        $chainedExtid = $extId;
                        break;
                    }
                }
            }
            $chained->getData();
            if (isset($candidates[$chainedEvidence][$chainedExtid])) {
                $chained->setMyKey($candidates[$chainedEvidence][$chainedExtid]);
                $chained->setDataValue('external-ids', [$chainedExtid]);
            }
            if (count($this->chained[$chid]->chained)) {
                $this->chained[$chid]->assignResultIDs($candidates);
            }
        }
    }
483020
public function setThreshold($threshold)
    {
        if (is_numeric($threshold)) {
            $this->threshold = $threshold;
            $this->svm->setOptions(
                array(
                    \SVM::OPT_PROBABILITY => true
                )
            );
            if ($this->model->isPrepared()) {
                $this->model->setPrepared(false);
            }
        } else {
            throw new \InvalidArgumentException("Threshold must be a float value between 0-1");
        }
    }
266208
public function onAfterStoreUser(AnEvent $event)
    {
        if(!$event->isnew && $event->success){
            AnRequest::set('session.invite_token', null);
        }
    }
1123787
def update_or_create_candidate(
        self, candidate, aggregable=True, uncontested=False
    ):
        """"""
        candidate_election, c = CandidateElection.objects.update_or_create(
            candidate=candidate,
            election=self,
            defaults={"aggregable": aggregable, "uncontested": uncontested},
        )

        return candidate_election
1120904
protected static function trimAfterFirstMatch($pattern, $candidate)
    {
        $trailingCharsMatcher = new Matcher($pattern, $candidate);
        if ($trailingCharsMatcher->find()) {
            $startChar = $trailingCharsMatcher->start();
            $candidate = mb_substr($candidate, 0, $startChar);
        }
        return $candidate;
    }
715254
protected function transferSurplusVotes(float $surplus, Candidate $candidate)
    {
        $totalVotes = $candidate->getVotes();
        $candidateId = $candidate->getId();

        $this->logger->info('Transfering surplus votes');

        foreach ($this->ballots as $i => $ballot) {
            if ($ballot->getLastChoice() == $candidateId) {
                $this->allocateVotes($ballot, $surplus, $totalVotes);
            }
        }

        return;
    }
1117275
public function afterSave($event)
    {
        foreach ($this->relationKey as $from => $to) {
            $this->_relation[$to] = $this->owner[$from];
        }
        $this->_relation->save();
    }
744007
public function Reset()
	{
		parent::Reset();
		$this->index = 0;
		if ( ! is_null( $this->candidates ) ) return;
		$this->memberPath = null;
	}
747320
public function remove($candidate)
    {
        $hash = $this->objectHash($candidate);

        $this->candidates = array_filter($this->candidates, function ($known) use ($hash) {
            return $this->objectHash($known) != $hash;
        });

        if (isset($this->candidateIds[$hash])) {
            unset($this->candidateIds[$hash]);
        }

        return $this;
    }
476079
protected function eliminateCandidates(array $candidates): int
    {
        $minimumCandidates = $this->getLowestCandidates($candidates);
        $count = count($minimumCandidates);

        // p. 52(2)(b) - the returning officer shall decide, by lot, which of those
        // candidates is to be excluded.
        // We do not look back on previous rounds at all as per p. 52(2)(a)
        $minimumCandidate = $minimumCandidates[(array_rand($minimumCandidates))];

        $this->logger->notice(sprintf('There were %d joint lowest candidates,
            %d was randomly selected to be eliminated', $count, $minimumCandidate->getId()));

        $this->transferEliminatedVotes($minimumCandidate);
        $minimumCandidate->setState(Candidate::DEFEATED);

        return count($minimumCandidates);
    }
356540
private void evict(Node candidate) {
    if (data.size() > maximumSize) {
      Node victim = policy.findVictim(sentinel, policyStats);
      policyStats.recordEviction();

      boolean admit = admittor.admit(candidate.key, victim.key);
      if (admit) {
        evictEntry(victim);
      } else {
        evictEntry(candidate);
      }
    } else {
      policyStats.recordOperation();
    }
  }
524794
public function onVote(EventInterface $event)
    {
        $repository = $this->repositoryResolver->getRepositoryForEvent($event);

        if (!$repository) {
            return;
        }

        $vote = $repository->countByReferenceAndByIp($event->getReference(), $event->getRequest()->getClientIp());

        if ($vote >= $this->maxNumber) {
            $event->stopPropagation();
        }
    }
1211373
public function afterScenario($event)
    {
        $this->testcaseTimer->stop();
        $code = $event->getTestResult()->getResultCode();
        $testResultString = array(
            TestResult::PASSED    => 'passed',
            TestResult::SKIPPED   => 'skipped',
            TestResult::PENDING   => 'pending',
            TestResult::FAILED    => 'failed',
            TestResult::UNDEFINED => 'undefined',
        );

        $this->testsuiteStats[$code]++;

        $this->currentTestcase->addAttribute('time', \round($this->testcaseTimer->getTime(), 3));
        $this->currentTestcase->addAttribute('status', $testResultString[$code]);
    }