<commit_before>class DetailScreen < PM::TableScreen

  attr_accessor :container, :data, :date

  def on_load
    @data.sort! {|a,b| a.annotation_params[:sort_by] <=> b.annotation_params[:sort_by] }
  end

  def will_appear
    @view_setup ||= begin
      self.setTitle("Details", subtitle:"for #{@date}")
      self.navigationController.navigationBar.barStyle = self.navigationController.toolbar.barStyle = UIBarStyleBlack if Device.ios_version.to_f < 7.0
      self.navigationController.setToolbarHidden(false)

      #Create the labe at the bottom of the view.
      @label = set_attributes UILabel.alloc.initWithFrame(CGRectMake(0, 0, self.navigationController.toolbar.bounds.size.width, self.navigationController.toolbar.bounds.size.height)), {
        background_color: UIColor.clearColor,
        text_color: (Device.ios_version.to_f < 7.0 ? UIColor.whiteColor : "#0F5D14".to_color),
        text_alignment: UITextAlignmentCenter,
        line_break_mode: UILineBreakModeTailTruncation,
        font: UIFont.boldSystemFontOfSize(18),
        minimum_font_size: 10,
        resize: [:width, :left, :right],
        text: "#{count('incident')} Incidents & #{count('arrest')} Arrests"
      }
      item = UIBarButtonItem.alloc.initWithCustomView(@label)
      self.toolbarItems = [item]

      # Done Button
      set_nav_bar_button :right,
        title: "Done",
        action: :close,
        type: UIBarButtonItemStyleDone

      update_table_data
    end
  end

  def table_data
    [{cells:build_cells}]
  end

  def build_cells
    c = []
    @data.each_with_index do |cell,i|
      c << {
        title: cell.title,
        cell_style: UITableViewCellStyleSubtitle,
        subtitle: cell.subtitle,
        selection_style: UITableViewCellSelectionStyleBlue,
        accessory_type: UITableViewCellAccessoryDisclosureIndicator,
        accessory_action: :tapped_crime,
        action: :tapped_crime,
        arguments: {marker_index: i},
        image: pin_image(cell)
      }
    end
    c
  end

  def pin_image(cell)
    cell.annotation_params[:type].downcase == "arrest" ? "pinannotation_red" : "pinannotation_purple"
  end

  def tapped_crime(params = {})
    @container.closeDetailAndZoomToEvent(@data[params[:marker_index]]) unless @container.nil?
  end

  def count(type)
    @data.select { |crime| crime.annotation_params[:type].downcase == type.downcase }.count
  end

end<commit_msg>Better looking detail screen.<commit_after>class DetailScreen < PM::TableScreen

  attr_accessor :container, :data, :date

  def on_load
    @data.sort! {|a,b| a.sort_by <=> b.sort_by }
  end

  def will_appear
    @view_setup ||= begin
      self.setTitle("Details", subtitle:"for #{@date}")
      self.navigationController.navigationBar.barStyle = self.navigationController.toolbar.barStyle = UIBarStyleBlack if Device.ios_version.to_f < 7.0
      self.navigationController.setToolbarHidden(false)

      #Create the labe at the bottom of the view.
      @label = set_attributes UILabel.alloc.initWithFrame(CGRectMake(0, 0, self.navigationController.toolbar.bounds.size.width, self.navigationController.toolbar.bounds.size.height)), {
        background_color: UIColor.clearColor,
        text_color: (Device.ios_version.to_f < 7.0 ? UIColor.whiteColor : "#0F5D14".to_color),
        text_alignment: UITextAlignmentCenter,
        line_break_mode: UILineBreakModeTailTruncation,
        font: UIFont.boldSystemFontOfSize(18),
        minimum_font_size: 10,
        resize: [:width, :left, :right],
        text: "#{count('incident')} Incidents & #{count('arrest')} Arrests"
      }
      item = UIBarButtonItem.alloc.initWithCustomView(@label)
      self.toolbarItems = [item]

      # Done Button
      set_nav_bar_button :right,
        title: "Close",
        action: :close,
        type: UIBarButtonItemStyleDone

      update_table_data
    end
  end

  def table_data
    [{
      title: "Arrests",
      cells: build_cells(:arrest)
    }, {
      title: "Incidents",
      cells: build_cells(:incident)
    }]
  end

  def build_cells(type)
    c = []
    crimes = type == :arrest ? arrests : incidents
    crimes.each_with_index do |cell,i|
      c << {
        title: cell.title,
        cell_style: UITableViewCellStyleSubtitle,
        subtitle: cell.subtitle,
        selection_style: UITableViewCellSelectionStyleBlue,
        accessory_type: UITableViewCellAccessoryDisclosureIndicator,
        accessory_action: :tapped_crime,
        action: :tapped_crime,
        arguments: {marker_index: i, marker_type: type}
      }
    end
    c
  end

  def arrests
    @data.select { |crime| crime.type.downcase == 'arrest' }
  end

  def incidents
    @data.select { |crime| crime.type.downcase == 'incident' }
  end

  def tapped_crime(params = {})
    crimes = params[:marker_type] == :arrest ? arrests : incidents

    @container.closeDetailAndZoomToEvent(crimes[params[:marker_index]]) unless @container.nil?
  end

  def count(type)
    @data.select { |crime| crime.type.downcase == type.downcase }.count
  end

end
{'fraction_non_alphanumeric': 0.1095890410958904, 'fraction_numerical': 0.005558864403414731, 'mean_word_length': 3.2986348122866893, 'pattern_counts': {'":': 0, '<': 15, '<?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': '4597904', 'n_tokens_mistral': 1658, 'n_tokens_neox': 1591, 'n_words': 304}