openaustralia/publicwhip

View on GitHub
app/views/members/_possible_friends.html.haml

Summary

Maintainability
Test Coverage
%section.page-section#friends
  %h2
    Compare
    = @member.name
    with someone else

  %p
    Shows people in order of those who voted always the same as
    = person.name
    (100% agreement) to those who never voted the same (0% agreement).
  %p
    We only compare those votes where both people attended.

    This may reveal relationships between people that were previously unsuspected. Or it may be nonsense.

  %table.table
    %thead
      %tr.headings
        %th Agreement
        %th Name
    %tbody
      - if person.possible_friends.empty?
        %tr
          %td{colspan: "4"} No results found
      - else
        - possible_friends = person.possible_friends.includes(person2: :members).sort_by{|pd| [pd.distance_b, pd.person2.currently_in_parliament? ? 0 : 1, pd.person2.last_name, pd.person2.first_name]}
        - possible_friends = possible_friends[0..4] if !all_friends
        - possible_friends.each do |person_distance|
          %tr
            %td= link_to fraction_to_percentage_display(person_distance.agreement_fraction_without_absences), compare_member_path_simple(person.latest_member, person_distance.person2.latest_member)
            %td= link_to person_distance.person2.name, compare_member_path_simple(person.latest_member, person_distance.person2.latest_member)
            %td= member_type_party_place_sentence(person_distance.person2.latest_member)
  - unless all_friends
    = link_to "More people to compare with #{person.name}", friends_member_path_simple(person.latest_member), class: 'btn btn-default btn-sm'
  - if person.best_friends.count >= 5 && !all_friends
    (#{pluralize(person.best_friends.count, "other person")} voted exactly the same as this one)