<commit_before>module PetitionsHelper
  
  def social_media_config
    Rails.configuration.social_media
  end
  
  def petition_to_open_graph(petition)
    { 
      'og:title' => facebook_title(petition), 
      'og:type' => 'cause', 
      'og:description' => strip_tags_except_links(petition.description).squish[0..300],
      'og:url' => petition_url(petition),
      'og:image' => social_media_config[:facebook][:image],
      'og:site_name' => social_media_config[:facebook][:site_name],
      'fb:app_id' => social_media_config[:facebook][:app_id]
    }
  end
  
  def facebook_title(petition)
    facebook_titles = petition.petition_titles.find_all_by_title_type("facebook").map { |fb_title| fb_title.title }
    facebook_title = spin! "petition #{petition.id} facebook title", :petition, facebook_titles
    facebook_title || petition.title
  end

  def counter_size(petition_count)
    counters = [5, 10, 50, 100, 250, 500, 750, 1000, 2000, 5000, 7500, 10000, 15000, 20000, 100000, 1000000]
    for i in counters
      if petition_count < i
        return i
      end
    end
  end
end<commit_msg>Fixed bug where spin happens even when there are no facebook titles to choose from<commit_after>module PetitionsHelper
  
  def social_media_config
    Rails.configuration.social_media
  end
  
  def petition_to_open_graph(petition)
    { 
      'og:title' => facebook_title(petition), 
      'og:type' => 'cause', 
      'og:description' => strip_tags_except_links(petition.description).squish[0..300],
      'og:url' => petition_url(petition),
      'og:image' => social_media_config[:facebook][:image],
      'og:site_name' => social_media_config[:facebook][:site_name],
      'fb:app_id' => social_media_config[:facebook][:app_id]
    }
  end
  
  def facebook_title(petition)
    facebook_titles = petition.petition_titles.find_all_by_title_type("facebook").map { |fb_title| fb_title.title }
    facebook_title = spin! "petition #{petition.id} facebook title", :petition, facebook_titles unless not facebook_titles
    facebook_title || petition.title
  end

  def counter_size(petition_count)
    counters = [5, 10, 50, 100, 250, 500, 750, 1000, 2000, 5000, 7500, 10000, 15000, 20000, 100000, 1000000]
    for i in counters
      if petition_count < i
        return i
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.11438474870017332, 'fraction_numerical': 0.05632582322357019, 'mean_word_length': 3.9127659574468083, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 17, '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': '7224985', 'n_tokens_mistral': 907, 'n_tokens_neox': 736, 'n_words': 160}