PHP code example of mieuxvoter / majority-judgment
1. Go to this page and download the library: Download mieuxvoter/majority-judgment library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
mieuxvoter / majority-judgment example snippets
use MieuxVoter\MajorityJudgment\MajorityJudgment;
use MieuxVoter\MajorityJudgment\Model\Tally\ArrayPollTally;
$grades = [
"to reject",
"insufficient",
"passable",
"somewhat good",
"good",
"very good",
"excellent",
];
$proposals = [
"Arancini",
"Burger",
"Chips",
];
$meritProfiles = [
[1, 1, 4, 3, 7, 4, 1], // for each proposal, tally the
[2, 2, 5, 5, 5, 0, 2], // amount of judgments for each grade
[0, 1, 2, 1, 6, 7, 4], // from "worst" grade to "best" grade
];
$pollTally = new ArrayPollTally($meritProfiles);
$mj = new MajorityJudgment();
$result = $mj->deliberate($pollTally);
foreach($result->getProposalResultsRanked() as $proposalResult) {
// … Do something, for example:
print(sprintf(
"#%d %s (%s)\n",
$proposalResult->getRank(),
$proposals[$proposalResult->getIndex()],
$grades[$proposalResult->getMedian()],
));
}
// #1 Chips (very good)
// #2 Arancini (good)
// #3 Burger (somewhat good)