Advertisement
xrobau

Parse publicResults of 2024 QLD LGA

Mar 21st, 2024
651
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.44 KB | Source Code | 0 0
  1. <?php
  2.  
  3. $x = simplexml_load_file("publicResults.xml");
  4. $d = $x->xpath('//lga[@areaCode=028]//contest[@contestType="councillor"]/districts/district');
  5. $results = [];
  6. foreach ($d as $dist) {
  7.   $a = $dist->attributes();
  8.   $seats = (string) $dist->numElectedCandidates;
  9.   $ccount = (string) $dist->candidates->attributes()->count;
  10.   $distname = (string) $a->districtName;
  11.   $rollPct = (string) $a->percentRollCounted;
  12.   $rounds = [];
  13.   print "District $distname\n Last updated at ".$a->lastUpdated."\n";
  14.   print "  $ccount nominees running for $seats seats\n";
  15.   print "  ($rollPct percent maximum number of possible votes counted)\n";
  16.   foreach ($dist->countRound as $r) {
  17.     $a = $r->attributes();
  18.     $total = $r->totalBallots;
  19.     $formal = $r->totalFormalBallots->count;
  20.     $rname = (string) $a->countName;
  21.     $rounds[$rname] = [];
  22.     print "  Count round ".$a->id." is $rname\n   $total ballots cast of ($formal were formal)\n";
  23.     foreach ($r->primaryVoteResults->candidate as $c) {
  24.       $count = (int) $c->count;
  25.       $catt = (array) $c->attributes();
  26.       $rounds[$rname][$count] = $catt['@attributes'];
  27.     }
  28.     krsort($rounds[$rname]);
  29.     $ptr = 0;
  30.     foreach ($rounds[$rname] as $c => $att) {
  31.       if ($ptr++ >= $seats) {
  32.         break;
  33.       }
  34.       print "     Position $ptr: ".$att['ballotName']." with $c\n";
  35.     }
  36.     // print json_encode($rounds[$rname])."\n";
  37.   }
  38.   $results[$distname]=$rounds;
  39. }
  40. exit;
  41.  
  42.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement