<commit_before>require "./lib/human_history"

module HistoryHelper
  def history(changesets)
    content_tag(:div) do
      changesets.collect do |changeset|
        concat content_tag(:div, build_sentence(changeset))
      end
    end
  end

  def history_timeline(changesets)
    content_tag(:section, nil, id: "history-timeline", class: "timeline-container") do
      changesets.collect do |changeset|
        concat history_timeline_block changeset
      end
    end
  end

  def history_timeline_block(changeset)
    content_tag(:div, history_timeline_content(changeset), class: "timeline-block")
  end

  def history_timeline_content(changeset)
    classname = changeset["object"].underscore.dasherize
    image = content_tag(:div, nil, class: "timeline-img timeline-#{classname}") do
      concat content_tag(:i, nil, class: "fa icon-#{classname} fa-fw fa-lg centered")
    end

    content = content_tag(:div, nil, class: "timeline-content") do
      concat content_tag(:h2, "#{changeset["object"].humanize} #{changeset["event"]}d")
      concat history_timeline_list(changeset)
      concat content_tag(:span, changeset["recorded_at"], class: "timeline-date")
    end
    image + content
  end

  def history_timeline_list(changeset)
    structure = tokenize_sentence changeset, merge_strategy: :array
    content_tag(:ul, nil) do
      item = "#{structure[:actor]} #{structure[:event]}"
      [structure[:change]].flatten.each do |change|
        concat content_tag :li, "#{item} #{change}".html_safe
      end
    end
  end<commit_msg>Use omission link to display a subset of the information if it's available<commit_after>require "./lib/human_history"

module HistoryHelper
  def history(changesets)
    content_tag(:div) do
      changesets.collect do |changeset|
        concat content_tag(:div, build_sentence(changeset))
      end
    end
  end

  def history_timeline(changesets)
    content_tag(:section, nil, id: "history-timeline", class: "timeline-container") do
      changesets.collect do |changeset|
        concat history_timeline_block changeset
      end
    end
  end

  def history_timeline_block(changeset)
    content_tag(:div, history_timeline_content(changeset), class: "timeline-block")
  end

  def history_timeline_content(changeset)
    classname = changeset["object"].underscore.dasherize
    image = content_tag(:div, nil, class: "timeline-img timeline-#{classname}") do
      concat content_tag(:i, nil, class: "fa icon-#{classname} fa-fw fa-lg centered")
    end

    content = content_tag(:div, nil, class: "timeline-content") do
      concat content_tag(:h2, "#{changeset["object"].humanize} #{changeset["event"]}d")
      concat history_timeline_list(changeset)
      concat content_tag(:span, changeset["recorded_at"], class: "timeline-date")
    end
    image + content
  end

  def history_timeline_list(changeset)
    structure = tokenize_sentence changeset, merge_strategy: :array
    content_tag(:ul, nil) do
      item = "#{structure[:actor]} #{structure[:event]}"
      [structure[:change]].flatten.each do |change|
        concat content_tag :li, "#{item} #{history_timeline_change(change)}".html_safe
      end
    end
  end

  def history_timeline_change(change)
    timeline_change = change

    from = /(?<=from ")(.*)(?=" to)/.match(change)
    from_attribute = from.nil? ? nil : from[0]
    unless from_attribute.nil?
      if from_attribute.length > 50
        omission_link = omission_link_to from_attribute, "#", data: { behavior: "display-omission" }
        timeline_change = timeline_change.gsub "#{from_attribute}", omission_link
      end
    end

    to = /(?<=to ")(.*)(?="$)/.match(change)
    to_attribute = to.nil? ? nil : to[0]
    unless to_attribute.nil?
      if to_attribute.length > 50
        omission_link = omission_link_to to_attribute, "#", data: { behavior: "display-omission" }
        timeline_change = timeline_change.gsub "#{to_attribute}", omission_link
      end
    end

    timeline_change
  end
{'fraction_non_alphanumeric': 0.1201404564835716, 'fraction_numerical': 0.00200652119388011, 'mean_word_length': 3.845686512758202, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1437331', 'n_tokens_mistral': 1279, 'n_tokens_neox': 1232, 'n_words': 281}