<commit_before>class MailingListsController < ApplicationController
  load_and_authorize_resource
  skip_load_resource :only => [:create]

  # GET /mailing_lists
  def index
    @mailing_lists = MailingList.all
  end

  # GET /mailing_lists/1
  def show
    @subscriptions = @mailing_list.subscriptions.page(params[:page]).per(params[:per]||10)

    respond_to do |format|
      format.html
      format.json {
        active_sum=0
        render json: [
            {name: "Active", data: @mailing_list.active_subscriptions.group_by_month(:created_at).order("month asc").count.map { |x,y| { x => (active_sum += y)} }.reduce({}, :merge)},
            {name: "Unsubscribed", data: @mailing_list.subscriptions.where(subscribed: false).group_by_month(:updated_at).order("month asc").count}
          ]

      }
    end
  end

  # GET /mailing_lists/new
  def new
    @mailing_list = MailingList.new
  end

  def import
    if request.patch?
      res = @mailing_list.import(params[:mailing_list][:csv_file])

      if res[:status].eql?(:error)
        flash[:error] = res[:message]
      else
        redirect_to @mailing_list, :notice => "Subscribers are importing"
      end
    end
  end

  # GET /mailing_lists/1/edit
  def edit
  end

  # POST /mailing_lists<commit_msg>chart only last year for subscriptions and do it by week<commit_after>class MailingListsController < ApplicationController
  load_and_authorize_resource
  skip_load_resource :only => [:create]

  # GET /mailing_lists
  def index
    @mailing_lists = MailingList.all
  end

  # GET /mailing_lists/1
  def show
    @subscriptions = @mailing_list.subscriptions.page(params[:page]).per(params[:per]||10)

    respond_to do |format|
      format.html
      format.json {
        active_sum=0
        render json: [
            {name: "Active", data: @mailing_list.active_subscriptions.where("created_at > ?", 1.year.ago).group_by_week(:created_at).order("month asc").count.map { |x,y| { x => (active_sum += y)} }.reduce({}, :merge)},
            {name: "Unsubscribed", data: @mailing_list.subscriptions.where("created_at > ?", 1.year.ago).where(subscribed: false).group_by_month(:updated_at).order("month asc").count}
          ]

      }
    end
  end

  # GET /mailing_lists/new
  def new
    @mailing_list = MailingList.new
  end

  def import
    if request.patch?
      res = @mailing_list.import(params[:mailing_list][:csv_file])

      if res[:status].eql?(:error)
        flash[:error] = res[:message]
      else
        redirect_to @mailing_list, :notice => "Subscribers are importing"
      end
    end
  end

  # GET /mailing_lists/1/edit
  def edit
  end

  # POST /mailing_lists
{'fraction_non_alphanumeric': 0.1256583897667419, 'fraction_numerical': 0.004514672686230248, 'mean_word_length': 3.135303265940902, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, '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': '6529738', 'n_tokens_mistral': 906, 'n_tokens_neox': 877, 'n_words': 173}