mysociety /
theyworkforyou
| 1 | <?php |
||
| 2 | |||
| 3 | include '../www/includes/easyparliament/init.php'; |
||
| 4 | # include INCLUDESPATH . 'easyparliament/member.php'; |
||
| 5 | |||
| 6 | $db = new ParlDB(); |
||
| 7 | |||
| 8 | $q = $db->query('select count(*) as c from hansard where major=3 and minor=2')->first(); |
||
| 9 | $answers = $q['c']; |
||
| 10 | |||
| 11 | # Done directly as storing everything in an array as $db->query() does runs out of memory, unsurprisingly |
||
| 12 | $q = mysql_query( |
||
| 13 | 'select section.body, gid, yes_votes, no_votes |
||
| 14 | from hansard |
||
| 15 | inner join epobject as section on hansard.section_id = section.epobject_id |
||
| 16 | left join anonvotes on hansard.epobject_id = anonvotes.epobject_id |
||
| 17 | where |
||
| 18 | major = 3 and minor = 2 |
||
| 19 | ' |
||
| 20 | ); |
||
| 21 | |||
| 22 | #$rows = mysql_num_rows($q); |
||
| 23 | #echo "Number of answers with votes: $rows\n"; |
||
| 24 | #echo "Number of answers in system: $answers\n"; |
||
| 25 | |||
| 26 | $votes = []; |
||
| 27 | while ($row = mysql_fetch_assoc($q)) { |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 28 | $dept = $row['body']; |
||
| 29 | if (!isset($votes[$dept])) { |
||
| 30 | $votes[$dept] = [ |
||
| 31 | 'verymoreyes' => 0, 'moreyes' => 0, 'verymoreno' => 0, 'moreno' => 0, 'same' => 0, 'none' => 0, |
||
| 32 | ]; |
||
| 33 | } |
||
| 34 | $yes = $row['yes_votes']; |
||
| 35 | $no = $row['no_votes']; |
||
| 36 | $gid = $row['gid']; |
||
| 37 | if (is_null($yes)) { |
||
| 38 | $votes[$dept]['none']++; |
||
| 39 | } else { |
||
| 40 | if ($no > $yes + 10) { |
||
| 41 | $votes[$dept]['verymoreno']++; |
||
| 42 | } elseif ($no > $yes) { |
||
| 43 | $votes[$dept]['moreno']++; |
||
| 44 | } elseif ($no + 10 < $yes) { |
||
| 45 | $votes[$dept]['verymoreyes']++; |
||
| 46 | } elseif ($no < $yes) { |
||
| 47 | $votes[$dept]['moreyes']++; |
||
| 48 | } else { |
||
| 49 | $votes[$dept]['same']++; |
||
| 50 | } |
||
| 51 | } |
||
| 52 | } |
||
| 53 | |||
| 54 | print "Department,11+ more yes votes than no,1-10 more yes votes than no,11+ more no votes than yes,1-10 more no votes than yes,Same votes yes/no,No votes\n"; |
||
| 55 | foreach ($votes as $dept => $v) { |
||
| 56 | #if (!$v['moreyes'] && !$v['moreno'] && !$v['same']) continue; |
||
| 57 | if (strstr($dept, ',')) { |
||
| 58 | $dept = "\"$dept\""; |
||
| 59 | } |
||
| 60 | print "$dept,$v[verymoreyes],$v[moreyes],$v[verymoreno],$v[moreno],$v[same],$v[none]\n"; |
||
| 61 | } |
||
| 62 |