openaustralia/publicwhip

View on GitHub
app/views/policies/how_the_number_is_calculated/_other.html.haml

Summary

Maintainability
Test Coverage
%p
  They Vote For You gives each vote a score based on whether the MP voted in agreement with the policy or not. These scores are then
  averaged with a weighting across all votes that the MP could have voted on relevant to the policy. The overall average score is then converted to a simple
  english language phrase based on the range of values it's within.

%p
  When an MP votes in agreement with a policy the vote is scored as
  #{fraction_to_percentage_display(Distance.score(:same))}.
  When they vote against the policy it is scored as
  = fraction_to_percentage_display(Distance.score(:differ))
  and
  when they are absent it is scored half way between the two at
  #{fraction_to_percentage_display(Distance.score(:absent))}.
  The half way point effectively says "we don't know whether they are for or against this policy".

%p
  The overall agreement score for the policy is worked out by
  a weighted average of the scores for each vote. The weighting has been chosen so that the most important votes have a weighting
  = Distance::STRONG_FACTOR
  times that of the less important votes. Also, absent votes on less important votes are weighted
  = Distance::ABSENT_FACTOR
  times less again to not penalise MPs for not attending the less important votes. Pressure of other work means MPs or
  Senators are not always available to vote – it does not always mean they've abstained.

%table.table
  %thead
    %tr.headings
      %th{colspan: 2} Type of vote
      %th Agreement score (s)
      %th Weight (w)
      %th No of votes (n)
  %tbody
    %tr
      %th{rowspan: 3, scope: "rowgroup"} Most important votes
      %td MP voted with policy
      = render "policies/how_the_number_is_calculated/cells", policy_person_distance: policy_person_distance, type: :samestrong
    %tr
      %td MP voted against policy
      = render "policies/how_the_number_is_calculated/cells", policy_person_distance: policy_person_distance, type: :differstrong
    %tr
      %td MP absent
      = render "policies/how_the_number_is_calculated/cells", policy_person_distance: policy_person_distance, type: :absentstrong
    %tr
      %th{rowspan: 3, scope: "rowgroup"} Less important votes
      %td MP voted with policy
      = render "policies/how_the_number_is_calculated/cells", policy_person_distance: policy_person_distance, type: :same
    %tr
      %td MP voted against policy
      = render "policies/how_the_number_is_calculated/cells", policy_person_distance: policy_person_distance, type: :differ
    %tr
      %td MP absent
      = render "policies/how_the_number_is_calculated/cells", policy_person_distance: policy_person_distance, type: :absent

%p
  The final agreement score is a weighted average
  (#{link_to "weighted arithmetic mean", "https://en.wikipedia.org/wiki/Weighted_arithmetic_mean"})
  of the scores of the individual votes.

%p
  Average agreement score =
  sum(n×w×s) / sum(n×w) =
  #{policy_person_distance.sum_weighted_scores} / #{policy_person_distance.sum_weights}
  \=
  = succeed "." do
    %b= fraction_to_percentage_display(policy_person_distance.agreement_fraction)

%p
  And then this average agreement score

%ul
  - PolicyPersonDistance.category_range_mapping.each do |category, range|
    %li
      = optional_strong(category == policy_person_distance.category) do
        between
        = fraction_to_percentage_display(range.min)
        and
        = fraction_to_percentage_display(range.max)
        becomes
        "#{category_words_sentence(category)}"