<commit_before>module EventsHelper
  include TimeRangeHelper # provides normalize_time

  def today_tomorrow_or_weekday(record)
    if record.ongoing?
      "Started #{record.start_time.strftime('%A')}"
    else
      record.start_time.strftime('%A')
    end
  end

# calculate rowspans for an array of events
# argument:  array of events
# returns:  rowspans, an array in which each entry corresponds to an event in events;
# each entry is number of rows spanned by today_tomorrow_weekday entry, if any, to left of event
# entry will be > 0 for first event of day, 0 for other events
  def calculate_rowspans(events)
    previous_start_time = nil
    rowspans = Array.new(events.size, 0)
    first_event_of_day = 0

    events.each_with_index do |event, index|
      new_day = previous_start_time.nil? || (previous_start_time.to_date != event.start_time.to_date)
      if new_day
        first_event_of_day = index
      end
      rowspans[first_event_of_day] += 1
      previous_start_time = event.start_time
    end

    return rowspans
  end

  def google_maps_url(address)
    return "http://maps.google.com/maps?q=#{cgi_escape(address)}"
  end

  #---[ Event sorting ]----------------------------------------------------

  # Return a link for sorting by +key+ (e.g., "name").
  def events_sort_link(key)
    if key.present?
      link_to(sorting_label_for(key, @tag.present?), url_for(params.merge(:order => key)))
    else
      link_to('Default', url_for(params.tap { |o| o.delete :order }))
    end
  end

  # Return a human-readable label describing what the sorting +key+ is.
  def events_sort_label(key)
    if key.present? or @tag.present?
      sanitize " by <strong>#{sorting_label_for(key, @tag.present?)}.</strong>"
    else
      nil
    end
  end

  #---[ Google Calendar export ]--------------------------------------------

  # Time format used for Google Calendar exports
  GOOGLE_TIME_FORMAT = "%Y%m%dT%H%M%SZ"

  # Return a time span using Google Calendar's export format.
  def format_google_timespan(event)
    end_time = event.end_time || event.start_time
    "#{event.start_time.utc.strftime(GOOGLE_TIME_FORMAT)}/#{end_time.utc.strftime(GOOGLE_TIME_FORMAT)}"
  end

  # Return a Google Calendar export URL.

  def google_event_export_link(event)
    GoogleEventExportLink.new(event, self).render
  end

  class GoogleEventExportLink < Struct.new(:event, :context)
    def render
      truncate(url + query)
    end

    private

    def url
      "http://www.google.com/calendar/event?action=TEMPLATE&trp=true&"
    end

    def query
      params.collect do |key, value|
        value.to_query(key)
      end.compact.join("&")
    end

    def params
      {
        text: text,
        dates: dates,
        location: location,
        sprop: sprop,
        details: details,
      }
    end

    def text
      event.title
    end
<commit_msg>hash is overkill, let's use an array.<commit_after>module EventsHelper
  include TimeRangeHelper # provides normalize_time

  def today_tomorrow_or_weekday(record)
    if record.ongoing?
      "Started #{record.start_time.strftime('%A')}"
    else
      record.start_time.strftime('%A')
    end
  end

# calculate rowspans for an array of events
# argument:  array of events
# returns:  rowspans, an array in which each entry corresponds to an event in events;
# each entry is number of rows spanned by today_tomorrow_weekday entry, if any, to left of event
# entry will be > 0 for first event of day, 0 for other events
  def calculate_rowspans(events)
    previous_start_time = nil
    rowspans = Array.new(events.size, 0)
    first_event_of_day = 0

    events.each_with_index do |event, index|
      new_day = previous_start_time.nil? || (previous_start_time.to_date != event.start_time.to_date)
      if new_day
        first_event_of_day = index
      end
      rowspans[first_event_of_day] += 1
      previous_start_time = event.start_time
    end

    return rowspans
  end

  def google_maps_url(address)
    return "http://maps.google.com/maps?q=#{cgi_escape(address)}"
  end

  #---[ Event sorting ]----------------------------------------------------

  # Return a link for sorting by +key+ (e.g., "name").
  def events_sort_link(key)
    if key.present?
      link_to(sorting_label_for(key, @tag.present?), url_for(params.merge(:order => key)))
    else
      link_to('Default', url_for(params.tap { |o| o.delete :order }))
    end
  end

  # Return a human-readable label describing what the sorting +key+ is.
  def events_sort_label(key)
    if key.present? or @tag.present?
      sanitize " by <strong>#{sorting_label_for(key, @tag.present?)}.</strong>"
    else
      nil
    end
  end

  #---[ Google Calendar export ]--------------------------------------------

  # Time format used for Google Calendar exports
  GOOGLE_TIME_FORMAT = "%Y%m%dT%H%M%SZ"

  # Return a time span using Google Calendar's export format.
  def format_google_timespan(event)
    end_time = event.end_time || event.start_time
    "#{event.start_time.utc.strftime(GOOGLE_TIME_FORMAT)}/#{end_time.utc.strftime(GOOGLE_TIME_FORMAT)}"
  end

  # Return a Google Calendar export URL.

  def google_event_export_link(event)
    GoogleEventExportLink.new(event, self).render
  end

  class GoogleEventExportLink < Struct.new(:event, :context)
    def render
      truncate(url + query)
    end

    private

    def url
      "http://www.google.com/calendar/event?action=TEMPLATE&trp=true&"
    end

    def query
      fields.collect do |field|
        send(field).to_query(field)
      end.compact.join("&")
    end

    def fields
      [:text, :dates, :location, :sprop, :details]
    end

    def text
      event.title
    end

{'fraction_non_alphanumeric': 0.13083948015454866, 'fraction_numerical': 0.0017562346329469617, 'mean_word_length': 2.7467105263157894, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '4597884', 'n_tokens_mistral': 1890, 'n_tokens_neox': 1805, 'n_words': 470}