<commit_before>defmodule EspiDni.ArticleViewCountNotifier do

  require Logger
  import Ecto.Query
  alias EspiDni.{
    Repo,
    ViewCount,
    Article,
    ArticleSlackMessenger
  }

  @minimum_increase 10
  @increase_threshold_percentage 25

  def notify_if_spike(article, team) do
    latest_counts = last_two_counts(article)

    if view_count_spike?(latest_counts, team) do
      ArticleSlackMessenger.send_view_spike_message(article, count_increase(latest_counts))
    end
  end

  defp last_two_counts(article) do
    Repo.all(
      from view_count in ViewCount,<commit_msg>Refactor for cleaner method calls<commit_after>defmodule EspiDni.ArticleViewCountNotifier do

  import Ecto.Query
  alias EspiDni.{
    Repo,
    ViewCount,
    Article,
    ArticleSlackMessenger
  }
  require Logger

  @minimum_increase 10
  @increase_threshold_percentage 25

  def notify_if_spike(article, team) do
    latest_counts = last_two_counts(article)

    if view_count_spike?(latest_counts, team) do
      ArticleSlackMessenger.send_view_spike_message(article, count_increase(latest_counts))
    end
  end

  defp last_two_counts(article) do
    Repo.all(
      from view_count in ViewCount,
{'fraction_non_alphanumeric': 0.05723905723905724, 'fraction_numerical': 0.006734006734006734, 'mean_word_length': 4.192139737991266, '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': '4142178', 'n_tokens_mistral': 439, 'n_tokens_neox': 407, 'n_words': 81}