<% content_for :title, "Suspicious Votes" %>

<h1>Suspicious Voting Patterns</h1>
<p>This page lists voting patterns identified as suspicious by an automated algorithm that is run once a day for every
  user. It lists the casting and receiving users, as well as the numbers of suspicious and total votes. Lastly, there's
  a 'certainty factor' calculated by the algorithm - lower values are more suspicious.</p>

<table class="table">
  <thead>
    <tr>
      <th>Voting User</th>
      <th>Recieving User</th>
      <th>Suspicious/Total Votes</th>
      <th>Certainty Factor</th>
      <th></th>
    </tr>
  </thead>
  <tbody>
    <% @suspicious_votes.each do |sv| %>
      <% next unless sv.from_user.present? && sv.to_user.present? %>
      <tr>
        <td><a href="/mod/votes/user/<%= sv.from_user.id %>"><%= sv.from_user.username %></a></td>
        <td><a href="/mod/votes/user/<%= sv.to_user.id %>"><%= sv.to_user.username %></a></td>
        <td><%= sv.suspicious_count %>/<%= sv.total_count %></td>
        <td><%= (sv.total_count.to_f / sv.suspicious_count.to_f ** 2).round(5) %></td>
        <td><%= link_to "Done", url_for(controller: :suspicious_votes, action: :investigated, id: sv.id), class: 'sv button is-outlined', method: :patch, remote: true %></td>
      </tr>
    <% end %>
  </tbody>
</table>
