<commit_before>class EventTweetService
  def self.tweet_approved_event
    events = Event.open.approved.order("deadline ASC").ids
    unpublished = Tweet.where(published: false).pluck(:event_id)
    remaining_events = events - unpublished

    return if remaining_events.empty?

    if Tweet.last
      return if Tweet.where(published: true).last == remaining_events.last
      last_tweet = Event.find_by(id: Tweet.where(published: true).last.event_id).id
      event_index = remaining_events.index(last_tweet) + 1
    else
      event_index = 0
    end
    event_to_announce = Event.find(remaining_events[event_index])
    TwitterWorker.announce_event(event_to_announce)
  end<commit_msg>Refactors event tweet service with more variables so is easier to understand<commit_after>class EventTweetService
  def self.tweet_approved_event
    events = Event.open.approved.order("deadline ASC").ids
    unpublished = Tweet.where(published: false).pluck(:event_id)
    remaining_events = events - unpublished

    return if remaining_events.empty?

    if Tweet.last
      last_tweet = Tweet.where(published: true).last
      return if last_tweet == remaining_events.last
      last_event_tweeted_id = Event.find_by(id: last_tweet.event_id).id
      event_index = remaining_events.index(last_event_tweeted_id) + 1
    else
      event_index = 0
    end
    event_to_announce = Event.find(remaining_events[event_index])
    TwitterWorker.announce_event(event_to_announce)
  end
{'fraction_non_alphanumeric': 0.08163265306122448, 'fraction_numerical': 0.0027210884353741495, 'mean_word_length': 4.143356643356643, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '7539007', 'n_tokens_mistral': 472, 'n_tokens_neox': 455, 'n_words': 87}