<html>

<head>
  <title>Credo Debug Log</title>

  <script src="https://code.jquery.com/jquery-3.3.1.min.js" integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8="
    crossorigin="anonymous"></script>

  <style>
    * {
      box-sizing: border-box;
      font-family: Arial, sans-serif;
    }
    code {
      font-family: 'Courier New', Courier, monospace;
      color: #c55953;
    }
  </style>
</head>

<body>

  <h1>Experimental Credo Debug Log</h1>

  <p>
    Analysis in
    <code>
      <%= File.cwd!() %>
    </code> took
    <strong><%= @time_total %> ms</strong> (<%= @time_load %> ms to load, <%= @time_run %> ms running checks)
  </p>

  <h2>Timings</h2>
  <p>
    Please note that these are cumulative timings across all cores, therefore an individual file or check can account for more time than the overall time spent.
  </p>

  <table border="1" cellpadding="4">
    <tr>
      <td></td>
      <th align=left>Check</th>
      <th align=left>File</th>
      <th align=left>Time (ms)</th>
    </tr>
    <tr>
      <th align=left valign=top rowspan="<%= Enum.min([15, Enum.count(@file_timings)]) %>">Slowest Files</th>
      <%= for {filename, time} <- Enum.take(@file_timings, 15) do %>
      <td></td>
        <td><%= filename %></td>
        <td align=right><%= floor(time / 1000) %></td>
      </tr>
      <tr>
      <% end %>
    </tr>
    <tr>
      <th align=left valign=top rowspan="<%= Enum.min([15, Enum.count(@check_timings)]) %>">Slowest Checks</th>
      <%= for {check, time} <- Enum.take(@check_timings, 15) do %>
        <td><%= check |> to_string() |> String.replace(~r/^Elixir./, "") %></td>
        <td></td>
        <td align=right><%= floor(time / 1000) %></td>
      </tr>
      <tr>
      <% end %>
    </tr>
    <tr>
      <th align=left valign=top rowspan="<%= Enum.min([15, Enum.count(@check_file_timings)]) %>">Slowest Checks/Files</th>
      <%= for {{check, filename}, time} <- Enum.take(@check_file_timings, 15) do %>
        <td><%= check |> to_string() |> String.replace(~r/^Elixir./, "") %></td>
        <td><%= filename %></td>
        <td align=right><%= floor(time / 1000) %></td>
      </tr>
      <tr>
      <% end %>
    </tr>

    <tr>
      <th align=left valign=top rowspan="<%= Enum.min([15, Enum.count(@check_file_timings)]) %>">Fastest Checks/Files</th>
      <%= for {{check, filename}, time} <- Enum.take(Enum.reverse(@check_file_timings), 15) do %>
        <td><%= check |> to_string() |> String.replace(~r/^Elixir./, "") %></td>
        <td><%= filename %></td>
        <td align=right><%= floor(time / 1000) %></td>
      </tr>
      <tr>
      <% end %>
    </tr>
  </table>

</body>

</html>
