<commit_before>module Puddy
  class Dashboard
    def transactions_money_total
      Money.new(transactions_query["sum"]).format
    end

    def transactions_count
      transactions_query["count"]
    end

    def transactions_query
      sql = %Q[SELECT SUM("amount_cents"), COUNT(*) FROM "transactions" WHERE "transactions"."success" = 't']
      @transaction_query ||= Transaction.find_by_sql(sql).first
    end

    def transactions_this_week
      Transaction.where(success: true).
        order(:created_at).
        where(created_at: 1.week.ago..Date.today).
        count
    end


    def campers_count
      Camper.confirmed.count
    end

    def campers_this_week
      Camper.confirmed.
        order(:created_at).
        where(created_at: 1.week.ago..Date.today).
        count
    end

    def campers_week_over_week
      two_weeks_ago = Camper.confirmed.
        order(:created_at).
        where(created_at: 2.week.ago..1.weeks.ago).
        count

      week_over_week = campers_this_week - two_weeks_ago
      week_over_week >= 0 ? "+#{week_over_week}" : "#{week_over_week}"<commit_msg>Memoize #campers_this_week<commit_after>module Puddy
  class Dashboard
    def transactions_money_total
      Money.new(transactions_query["sum"]).format
    end

    def transactions_count
      transactions_query["count"]
    end

    def transactions_query
      sql = %Q[SELECT SUM("amount_cents"), COUNT(*) FROM "transactions" WHERE "transactions"."success" = 't']
      @transaction_query ||= Transaction.find_by_sql(sql).first
    end

    def transactions_this_week
      Transaction.where(success: true).
        order(:created_at).
        where(created_at: 1.week.ago..Date.today).
        count
    end


    def campers_count
      Camper.confirmed.count
    end

    def campers_this_week
      @campers_this_week ||= Camper.confirmed.
        order(:created_at).
        where(created_at: 1.week.ago..Date.today).
        count
    end

    def campers_week_over_week
      two_weeks_ago = Camper.confirmed.
        order(:created_at).
        where(created_at: 2.week.ago..1.weeks.ago).
        count

      week_over_week = campers_this_week - two_weeks_ago
      week_over_week >= 0 ? "+#{week_over_week}" : "#{week_over_week}"
{'fraction_non_alphanumeric': 0.1033717834960071, 'fraction_numerical': 0.0044365572315882874, 'mean_word_length': 2.7334437086092715, 'pattern_counts': {'":': 0, '<': 3, '<?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': '2108148', 'n_tokens_mistral': 747, 'n_tokens_neox': 700, 'n_words': 125}