Example #1
0
            $cands[$cand] = 1;
        }
    }
    return array_keys($cands);
}
function runElections()
{
    $years = array();
    $condorcets = array();
    foreach (new DirectoryIterator('elections') as $fileInfo) {
        if ($fileInfo->isDot()) {
            continue;
        } else {
            $filepath = 'elections/' . $fileInfo->getFilename();
            $cands = getCandidates($filepath);
            $data = json_decode(file_get_contents($filepath), 1);
            $year = $data['ELECTION']['id'];
            print $year . "\n";
            $ballots = $data['BALLOTS'];
            $cprobs = runBallots($year, $cands, $ballots);
            $years[$year] = $cprobs;
        }
    }
    return $years;
}
$PRINT = 0;
$years = runElections();
$json_result = json_encode($years);
file_put_contents('result_' . time() . '.json', $json_result);
print $json_result;
print "\n\n\n";
Example #2
0
}
$aggregs = array();
$PRINT = 0;
$start = microtime(1);
$iters = 100;
foreach (range(0, $iters) as $i) {
    $now = microtime(1);
    $num_done = $i + 1;
    $per_iter = ($now - $start) / $num_done;
    $left_to_do = $iters - $num_done;
    $time_remaining = round($per_iter * $left_to_do / 60);
    if (0 == $i % 5) {
        print $i . " iterations completed ";
        print $time_remaining . " minutes to go\n";
    }
    $condorcets = runElections();
    foreach ($condorcets as $y => $cw) {
        if (!isset($aggregs[$y])) {
            $aggregs[$y] = array();
        }
        if (!isset($aggregs[$y][$cw])) {
            $aggregs[$y][$cw] = 0;
        }
        $aggregs[$y][$cw] += 1;
    }
}
ksort($aggregs);
$json_result = json_encode($aggregs);
file_put_contents('result_' . time() . '.json', $json_result);
print $json_result;
print "\n\n\n";