<commit_before>class ProjectsController < ApplicationController
  include ResourceHelper

  before_action :set_active_nav
  before_action :check_dependencies, only: [:new]

  def index
    authorize! :read, Project

    state = params.fetch(:state, nil)
    scope = current_account.customers.includes(:projects).references(:projects)
    if state.present? && Project.states.include?(state.to_sym)
      scope = scope.where("projects.state = ?", state)
    else
      scope = scope.where("projects.state = ?", :active)
    end

    @customers = scope.order(sort_column + " " + sort_direction)
                 .page(params.fetch(:page, nil))
                 .per(20)
  end

  def show
    authorize! :read, project
    @project_timers_chart_data = Charts::ProjectTimersService.new(project, project.timers).data
    return if project.budget.zero?
    @project_budget_chart_data = Charts::ProjectBudgetService.new(project, project.invoices.paid).data
  end

  def new
    authorize! :create, Project
    if customer
      @project = customer.projects.new
    else
      @project = Project.new
    end
  end

  def edit
    authorize! :update, project
  end

  def create
    authorize! :create, Project
    if project.save
      redirect_to projects_path, flash: { success: resource_message(:project, :create, :success) }
    else
      flash.now[:alert] = resource_message(:project, :create, :failure)
      render "new"
    end<commit_msg>update project charts<commit_after>class ProjectsController < ApplicationController
  include ResourceHelper

  before_action :set_active_nav
  before_action :check_dependencies, only: [:new]

  def index
    authorize! :read, Project

    state = params.fetch(:state, nil)
    scope = current_account.customers.includes(:projects).references(:projects)
    if state.present? && Project.states.include?(state.to_sym)
      scope = scope.where("projects.state = ?", state)
    else
      scope = scope.where("projects.state = ?", :active)
    end

    @customers = scope.order(sort_column + " " + sort_direction)
                 .page(params.fetch(:page, nil))
                 .per(20)
  end

  def show
    authorize! :read, project
    @project_timers_chart_data = Charts::ProjectTimersService.new(project, project.timers).data
    return if project.budget.zero?
    @project_budget_chart_data = Charts::ProjectBudgetService.new(project, project.invoices.paid_or_charged).data
  end

  def new
    authorize! :create, Project
    if customer
      @project = customer.projects.new
    else
      @project = Project.new
    end
  end

  def edit
    authorize! :update, project
  end

  def create
    authorize! :create, Project
    if project.save
      redirect_to projects_path, flash: { success: resource_message(:project, :create, :success) }
    else
      flash.now[:alert] = resource_message(:project, :create, :failure)
      render "new"
    end
{'fraction_non_alphanumeric': 0.10424577148774594, 'fraction_numerical': 0.001380738695201933, 'mean_word_length': 3.3060921248142643, 'pattern_counts': {'":': 0, '<': 5, '<?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': '4137050', 'n_tokens_mistral': 878, 'n_tokens_neox': 854, 'n_words': 193}