<commit_before><% page_title "Import of #{@import.original_filename}" %>

<%= content_tag_for :div, @import do %>
  <h1>Import of <%= @import.original_filename %></h1>
  <p>Created: <%= render_datetime_microformat(@import, :created_at) { @import.created_at.to_s(:long)} %></p>
  <p>Imported by <%= linked_author @import.creator %></p>

  <% if @import.status == :new %>
    <h2 class="summary">New import</h2>
    <p><%= @import.rows.size %> rows</p>
    <%= button_to "Run", run_admin_import_path(@import), class: "btn btn-large btn-primary" %>
  <% elsif @import.status == :queued %>
    <h2 class="summary">Queued</h2>
    <p>Queued: <%= render_datetime_microformat(@import, :import_enqueued_at) { @import.import_enqueued_at.to_s(:long)} %></p>

  <% elsif @import.status == :running %>
    <p>Queued: <%= render_datetime_microformat(@import, :import_enqueued_at) { @import.import_enqueued_at.to_s(:long)} %></p>
    <p>Started: <%= render_datetime_microformat(@import, :import_started_at) { @import.import_started_at.to_s(:long)} %></p>

    <p class="summary">Import running (row <%= @import.current_row %> / <%= @import.total_rows %></p>
  <% elsif @import.status == :failed %>
    <p>Queued: <%= render_datetime_microformat(@import, :import_enqueued_at) { @import.import_enqueued_at.to_s(:long)} %></p>
    <p>Started: <%= render_datetime_microformat(@import, :import_started_at) { @import.import_started_at.to_s(:long)} %></p>
    <p>Finished: <%= render_datetime_microformat(@import, :import_finished_at) { @import.import_finished_at.to_s(:long)} %></p>

    <h2 class="summary">Import failed with <%= pluralize(@import.import_errors.count, "error") %></h2>
    <%= link_to "Download annotated CSV", annotated_admin_import_path(@import), class:"download" %>

    <table id="errors">
      <thead>
        <tr>
          <th>Row Number</th>
          <th>Message</th>
        </tr>
      </thead>
      <tbody>
        <% @import.import_errors.each do |import_error| %>
          <tr class="import_error">
            <td class="row_number"><%= import_error[:row_number] %></td>
            <td class="message"><pre><%= import_error[:message] %></pre></td>
          </tr>
        <% end %>
      </tbody>
    </table>

    <h2>Log</h2>
    <p class="log"><pre><%= @import.log %></pre></p>

  <% else %>
    <h2 class="summary">Imported successfully</h2>
    <p>Queued: <%= render_datetime_microformat(@import, :import_enqueued_at) { @import.import_enqueued_at.to_s(:long)} %></p>
    <p>Started: <%= render_datetime_microformat(@import, :import_started_at) { @import.import_started_at.to_s(:long)} %></p>
    <p>Finished: <%= render_datetime_microformat(@import, :import_finished_at) { @import.import_finished_at.to_s(:long)} %></p>

    <h2 id="success">Documents added</h2>
    <% if @import.document_sources.any? %>
      <ul class="added">
        <% @import.document_sources.each do |document_source| %>
          <li><%= link_to document_source.document.latest_edition.title, admin_edition_path(document_source.document.latest_edition) %> imported from <%= link_to document_source.url, document_source.url %></li>
        <% end %>
      </ul>
    <% else %>
      <p class="added">None</p>
    <% end %>

    <h2 id="already_imported">Already imported</h2>
    <% if @import.already_imported.any? %>
      <ul class="already_imported">
        <% @import.already_imported.each do |already_imported| %>
          <% document_source = DocumentSource.find_by_url(already_imported[:url]) %>
          <% edition = document_source.document.latest_edition %>
          <li>
            <% if edition %>
              <%= link_to edition.title, admin_edition_path(edition) %>
              imported from
              <%= link_to document_source.url, document_source.url %>
              (
                <% if document_source.import_id %>
                  <%= link_to "Import ##{document_source.import_id}", admin_import_path(document_source.import_id) %>
                <% else %>
                  orginal import job not recorded
                <% end %>
              )
            <% else %>
              <em>imported edition has been deleted</em>
            <% end %>
          </li>
        <% end %>
      </ul>
    <% else %>
      <p class="already_imported">None</p>
    <% end %>

    <h2 id="log">Log</h2>
    <p class="log"><pre><%= @import.log %></pre></p>



  <% end %>
<% end %><commit_msg>Don't crash if a row is missing<commit_after><% page_title "Import of #{@import.original_filename}" %>

<%= content_tag_for :div, @import do %>
  <h1>Import of <%= @import.original_filename %></h1>
  <p>Created: <%= render_datetime_microformat(@import, :created_at) { @import.created_at.to_s(:long)} %></p>
  <p>Imported by <%= linked_author @import.creator %></p>

  <% if @import.status == :new %>
    <h2 class="summary">New import</h2>
    <p><%= @import.rows.size %> rows</p>
    <%= button_to "Run", run_admin_import_path(@import), class: "btn btn-large btn-primary" %>
  <% elsif @import.status == :queued %>
    <h2 class="summary">Queued</h2>
    <p>Queued: <%= render_datetime_microformat(@import, :import_enqueued_at) { @import.import_enqueued_at.to_s(:long)} %></p>

  <% elsif @import.status == :running %>
    <p>Queued: <%= render_datetime_microformat(@import, :import_enqueued_at) { @import.import_enqueued_at.to_s(:long)} %></p>
    <p>Started: <%= render_datetime_microformat(@import, :import_started_at) { @import.import_started_at.to_s(:long)} %></p>

    <p class="summary">Import running (row <%= @import.current_row %> / <%= @import.total_rows %></p>
  <% elsif @import.status == :failed %>
    <p>Queued: <%= render_datetime_microformat(@import, :import_enqueued_at) { @import.import_enqueued_at.to_s(:long)} %></p>
    <p>Started: <%= render_datetime_microformat(@import, :import_started_at) { @import.import_started_at.to_s(:long)} %></p>
    <p>Finished: <%= render_datetime_microformat(@import, :import_finished_at) { @import.import_finished_at.to_s(:long)} %></p>

    <h2 class="summary">Import failed with <%= pluralize(@import.import_errors.count, "error") %></h2>
    <%= link_to "Download annotated CSV", annotated_admin_import_path(@import), class:"download" %>

    <table id="errors">
      <thead>
        <tr>
          <th>Row Number</th>
          <th>Message</th>
        </tr>
      </thead>
      <tbody>
        <% @import.import_errors.each do |import_error| %>
          <tr class="import_error">
            <td class="row_number"><%= import_error[:row_number] %></td>
            <td class="message"><pre><%= import_error[:message] %></pre></td>
          </tr>
        <% end %>
      </tbody>
    </table>

    <h2>Log</h2>
    <p class="log"><pre><%= @import.log %></pre></p>

  <% else %>
    <h2 class="summary">Imported successfully</h2>
    <p>Queued: <%= render_datetime_microformat(@import, :import_enqueued_at) { @import.import_enqueued_at.to_s(:long)} %></p>
    <p>Started: <%= render_datetime_microformat(@import, :import_started_at) { @import.import_started_at.to_s(:long)} %></p>
    <p>Finished: <%= render_datetime_microformat(@import, :import_finished_at) { @import.import_finished_at.to_s(:long)} %></p>

    <h2 id="success">Documents added</h2>
    <% if @import.document_sources.any? %>
      <ul class="added">
        <% @import.document_sources.each do |document_source| %>
          <li><%= link_to document_source.document.latest_edition.title, admin_edition_path(document_source.document.latest_edition) %> imported from <%= link_to document_source.url, document_source.url %></li>
        <% end %>
      </ul>
    <% else %>
      <p class="added">None</p>
    <% end %>

    <h2 id="already_imported">Already imported</h2>
    <% if @import.already_imported.any? %>
      <ul class="already_imported">
        <% @import.already_imported.each do |already_imported| %>
          <% document_source = DocumentSource.find_by_url(already_imported[:url]) %>
          <% edition = document_source && document_source.document.latest_edition %>
          <li>
            <% if edition %>
              <%= link_to edition.title, admin_edition_path(edition) %>
              imported from
              <%= link_to document_source.url, document_source.url %>
              (
                <% if document_source.import_id %>
                  <%= link_to "Import ##{document_source.import_id}", admin_import_path(document_source.import_id) %>
                <% else %>
                  orginal import job not recorded
                <% end %>
              )
            <% elsif document_source %>
              <em>imported edition has been deleted</em>
            <% else %>
              <em>edition not found: <code><%= already_imported[:url] %></code></em>
            <% end %>
          </li>
        <% end %>
      </ul>
    <% else %>
      <p class="already_imported">None</p>
    <% end %>

    <h2 id="log">Log</h2>
    <p class="log"><pre><%= @import.log %></pre></p>



  <% end %>
<% end %>
{'fraction_non_alphanumeric': 0.18317051509769094, 'fraction_numerical': 0.003996447602131439, 'mean_word_length': 3.211781206171108, 'pattern_counts': {'":': 0, '<': 293, '<?xml version=': 0, '>': 293, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1196739', 'n_tokens_mistral': 3267, 'n_tokens_neox': 2956, 'n_words': 489}