function display_dream_comparison($id, $text, $inverse = false) { global $pw, $output; if (!array_key_exists($id, $output)) { return; } $score = $output[$id]; if ($score == -1) { $pw .= '<li>Has never voted on'; } else { if ($inverse) { $score = 1 - $score; } $pw .= '<li>Voted <strong>' . score_to_strongly($score) . '</strong>'; } $pw .= ' ' . $text . '</li>'; }
function display_dream_comparison($extra_info, $member, $dreamid, $desc, $inverse=false) { $out = ''; if (isset($extra_info["public_whip_dreammp${dreamid}_distance"])) { if ($extra_info["public_whip_dreammp${dreamid}_both_voted"] == 0) { $dmpdesc = 'Has <strong>never voted</strong> on'; } else { $dmpscore = floatval($extra_info["public_whip_dreammp${dreamid}_distance"]); $out .= "<!-- distance $dreamid: $dmpscore -->"; if ($inverse) $dmpscore = 1.0 - $dmpscore; $english = score_to_strongly($dmpscore); # XXX Note special casing of 2nd tuition fee policy here if ($extra_info["public_whip_dreammp${dreamid}_both_voted"] == 1 || $dreamid == 1132) { $english = preg_replace('#(very )?(strongly|moderately) #', '', $english); } $dmpdesc = 'Voted <strong>' . $english . '</strong>'; // How many votes Dream MP and MP both voted (and didn't abstain) in // $extra_info["public_whip_dreammp${dreamid}_both_voted"]; } $out .= "<li>$dmpdesc $desc. <small class='unneededprintlinks'> <a href='http://www.publicwhip.org.uk/mp.php?mpid=$member[member_id]&dmp=$dreamid'>votes</a> </small> </li>"; } return $out; }
private function displayDreamComparison($dreamid, $desc, $inverse = false) { $out = array(); $extra_info = $this->member->extra_info(); if (isset($extra_info["public_whip_dreammp{$dreamid}_distance"])) { if ($extra_info["public_whip_dreammp{$dreamid}_both_voted"] == 0) { $english = 'never voted'; $dmpdesc = 'Has <strong>never voted</strong> on'; } else { $dmpscore = floatval($extra_info["public_whip_dreammp{$dreamid}_distance"]); $score_text = "<!-- distance {$dreamid}: {$dmpscore} -->"; if ($inverse) { $dmpscore = 1.0 - $dmpscore; } $english = score_to_strongly($dmpscore); $dmpdesc = $score_text . ' Voted <strong>' . $english . '</strong>'; // How many votes Dream MP and MP both voted (and didn't abstain) in // $extra_info["public_whip_dreammp${dreamid}_both_voted"]; } $dmpdesc .= ' ' . $desc; $out = array('full_sentence' => $dmpdesc, 'voted' => $english); } return $out; }
function display_dream_comparison($extra_info, $member, $dreamid, $desc, $inverse, $search) { if (isset($extra_info["public_whip_dreammp{$dreamid}_distance"])) { if ($extra_info["public_whip_dreammp{$dreamid}_both_voted"] == 0) { $dmpdesc = 'Has <strong>never voted</strong> on'; } else { $dmpscore = floatval($extra_info["public_whip_dreammp{$dreamid}_distance"]); print "<!-- distance {$dreamid}: {$dmpscore} -->"; if ($inverse) { $dmpscore = 1.0 - $dmpscore; } $dmpdesc = 'Voted <strong>' . score_to_strongly($dmpscore) . '</strong>'; // How many votes Dream MP and MP both voted (and didn't abstain) in // $extra_info["public_whip_dreammp${dreamid}_both_voted"]; } $search_link = WEBPATH . "search/?s=" . urlencode($search) . "&pid=" . $member['person_id'] . "&pop=1"; ?> <li> <?php echo $dmpdesc; ?> <?php echo $desc; ?> . <small class="unneededprintlinks"> <a href="<?php echo PUBLICWHIP_HOST; ?> /mp.php?mpid=<?php echo $member['member_id']; ?> &dmp=<?php echo $dreamid; ?> ">votes</a> </small> </li> <?php return true; } return false; }
public function calculate_policy_position($policy_id, $want_score = false) { // This could be done as a join but it turns out to be // much slower to do that $divisions = $this->db->query("SELECT division_id, policy_vote, division_date\n FROM policydivisions\n WHERE policy_id = :policy_id\n AND house = 'commons'", array(':policy_id' => $policy_id)); $score = 0; $max_score = 0; $num_divs = $divisions->rows; $total_votes = 0; $party_where = 'party = :party'; $params = array(':party' => $this->name); if ($this->name == 'Labour') { $party_where = '( party = :party OR party = :party2 )'; $params = array(':party' => $this->name, ':party2' => 'Labour/Co-operative'); } for ($i = 0; $i < $num_divs; $i++) { $division_id = $divisions->field($i, 'division_id'); $weights = $this->get_vote_scores($divisions->field($i, 'policy_vote')); $params[':division_id'] = $division_id; $votes = $this->db->query("SELECT count(*) as num_votes, vote\n FROM persondivisionvotes\n JOIN member ON persondivisionvotes.person_id = member.person_id\n WHERE\n {$party_where}\n AND member.house = 1\n AND division_id = :division_id\n AND left_house = '9999-12-31'\n GROUP BY vote", $params); $num_votes = 0; for ($j = 0; $j < $votes->rows(); $j++) { $vote_dir = $votes->field($j, 'vote'); if ($vote_dir == '') { continue; } if ($vote_dir == 'tellno') { $vote_dir = 'no'; } if ($vote_dir == 'tellaye') { $vote_dir = 'aye'; } $num_votes += $votes->field($j, 'num_votes'); $score += $votes->field($j, 'num_votes') * $weights[$vote_dir]; } $total_votes += $num_votes; $max_score += $num_votes * max(array_values($weights)); } if ($total_votes == 0) { return null; } // this implies that all the divisions in the policy have a policy // position of absent so we set weight to -1 to indicate we can't // really say what the parties position is. if ($max_score == 0) { $weight = -1; } else { $weight = 1 - $score / $max_score; } $score_desc = score_to_strongly($weight); if ($want_score) { return array($score_desc, $weight); } else { return $score_desc; } }
function display_dream_comparison($extra_info, $member, $dreamid, $desc, $inverse = false) { if (isset($extra_info["public_whip_dreammp{$dreamid}_distance"])) { if ($extra_info["public_whip_dreammp{$dreamid}_both_voted"] == 0) { $dmpdesc = 'Has <strong>never voted</strong> on'; } else { $dmpscore = floatval($extra_info["public_whip_dreammp{$dreamid}_distance"]); print "<!-- distance {$dreamid}: {$dmpscore} -->"; if ($inverse) { $dmpscore = 1.0 - $dmpscore; } $english = score_to_strongly($dmpscore); if ($extra_info["public_whip_dreammp{$dreamid}_both_voted"] == 1) { $english = preg_replace('#(very )?(strongly|moderately) #', '', $english); } $dmpdesc = 'Voted <strong>' . $english . '</strong>'; // How many votes Dream MP and MP both voted (and didn't abstain) in // $extra_info["public_whip_dreammp${dreamid}_both_voted"]; } ?> <li><?php echo $dmpdesc; ?> <?php echo $desc; ?> . <small class="unneededprintlinks"> <a href="http://www.publicwhip.org.uk/mp.php?mpid=<?php echo $member['member_id']; ?> &dmp=<?php echo $dreamid; ?> ">votes</a> </small> </li> <?php return true; } return false; }
/** * displayDreamComparison * * Returns an array with one key: "full_sentence". * * The "full_sentence" element is a string, beginning with a lower case * letter, suitable for either displaying after a person’s name, eg: * * "Lord Lordson consistently voted against [some policy]" * * or being passed into ucfirst() and displayed as a sentence on its * own, where the person's name is implied by context, eg: * * "Consistently voted against [some policy]" * */ private function displayDreamComparison($dreamid, $policy_description, $inverse = false) { $out = array(); $extra_info = $this->member->extra_info(); if (isset($extra_info["public_whip_dreammp{$dreamid}_distance"])) { if ($extra_info["public_whip_dreammp{$dreamid}_both_voted"] == 0) { $consistency = 'has never voted on'; $dmpscore = -1; } else { $dmpscore = floatval($extra_info["public_whip_dreammp{$dreamid}_distance"]); if ($inverse) { $dmpscore = 1.0 - $dmpscore; } $consistency = score_to_strongly($dmpscore); } $has_strong = 0; if (isset($extra_info["public_whip_dreammp{$dreamid}_has_strong_vote"]) && $extra_info["public_whip_dreammp{$dreamid}_has_strong_vote"] == 1) { $has_strong = 1; } $full_sentence = $consistency . ' ' . $policy_description; $out = array('full_sentence' => $full_sentence, 'score' => $dmpscore, 'position' => $consistency, 'has_strong' => $has_strong); } return $out; }