<commit_before>module Kaui
  class AnalyticsController < Kaui::EngineController
    def index
      @slugs = []
      begin
        catalog = Kaui::KillbillHelper::get_full_catalog()
        catalog['products'].each do |product|
          product['plans'].each do |plan|
            name = plan['name']
            plan['phases'].each do |phase|
              type = phase['type']
              @slugs << "#{name.downcase}-#{type.downcase}"
            end
          end
        end
        @product_type = catalog['name']
      rescue => e
        flash[:error] = "Error while retrieving catalog: #{as_string(e)}"
      end
    end

    def account_snapshot
      begin
        @account = Kaui::KillbillHelper::get_account(params[:account_id])
        @snapshot = Kaui::KillbillHelper::get_account_snapshot(params[:account_id])
      rescue => e
        flash[:error] = "Error while retrieving account snapshot: #{as_string(e)}"
        redirect_to :analytics
      end
    end

    def refresh_account
      begin
        Kaui::KillbillHelper::refresh_account(params[:account_id])
        flash[:notice] = "Account successfully refreshed!"
      rescue => e
        flash[:error] = "Error while refreshing account: #{as_string(e)}"
      end
      redirect_to :account_snapshot, :account_id => params[:account_id]
    end

    def accounts_over_time
      begin
        @accounts = Analytics.accounts_over_time
      rescue => e
        flash[:error] = "Error while retrieving data: #{as_string(e)}"
        @accounts = Kaui::TimeSeriesData.empty
      end<commit_msg>analytics: fix param issue in redirection after refresh call<commit_after>module Kaui
  class AnalyticsController < Kaui::EngineController
    def index
      @slugs = []
      begin
        catalog = Kaui::KillbillHelper::get_full_catalog()
        catalog['products'].each do |product|
          product['plans'].each do |plan|
            name = plan['name']
            plan['phases'].each do |phase|
              type = phase['type']
              @slugs << "#{name.downcase}-#{type.downcase}"
            end
          end
        end
        @product_type = catalog['name']
      rescue => e
        flash[:error] = "Error while retrieving catalog: #{as_string(e)}"
      end
    end

    def account_snapshot
      begin
        @account = Kaui::KillbillHelper::get_account(params[:account_id])
        @snapshot = Kaui::KillbillHelper::get_account_snapshot(params[:account_id])
      rescue => e
        flash[:error] = "Error while retrieving account snapshot: #{as_string(e)}"
        redirect_to :analytics
      end
    end

    def refresh_account
      begin
        Kaui::KillbillHelper::refresh_account(params[:account_id])
        flash[:notice] = "Account successfully refreshed!"
      rescue => e
        flash[:error] = "Error while refreshing account: #{as_string(e)}"
      end
      redirect_to account_snapshot_path(:account_id => params[:account_id])
    end

    def accounts_over_time
      begin
        @accounts = Analytics.accounts_over_time
      rescue => e
        flash[:error] = "Error while retrieving data: #{as_string(e)}"
        @accounts = Kaui::TimeSeriesData.empty
      end
{'fraction_non_alphanumeric': 0.11250391726731432, 'fraction_numerical': 0.0, 'mean_word_length': 2.5231788079470197, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 13, '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': '1359377', 'n_tokens_mistral': 926, 'n_tokens_neox': 909, 'n_words': 204}