<commit_before>require 'csv'

class ReportsController < ApplicationController

  # Access Control
  before_filter :authorize_read_report
  def authorize_read_report() authorize! :read, :report end

  def attendees
    @attendees = Attendee.yr(@year).all
    @attendee_count = @attendees.count
    @user_count = User.yr(@year).count

    # build csv header line
    # the order here must match attendee_to_array() in reports_helper.rb
    cols = []
    if @attendee_count > 0 then
      cols << 'user_email'
      cols << @attendees.first.attribute_names_for_csv
      Plan.yr(@year).order(:name).each { |p| cols << "Plan: " + safe_for_csv(p.name) }
      claimable_discounts = Discount.yr(@year).where('is_automatic = ?', false).order(:name)
      claimable_discounts.each { |d| cols << "Discount: " + safe_for_csv(d.name) }
      Tournament.yr(@year).order(:name).each { |t| cols << "Tournament: " + safe_for_csv(t.name) }
    end
    @csv_header_line = cols.join(',')

    respond_to do |format|
      format.html do render :attendees end
      format.csv do render_csv("usgc_attendees_#{Time.now.strftime("%Y-%m-%d")}") end
    end
  end

  def atn_badges_all
    @attendees = Attendee.yr(@year).where('lower(substr(family_name,1,1)) between ? and ?', params[:min], params[:max])
    @attendees.order('family_name, given_name')
    render :layout => "print"
  end

  def atn_reg_sheets
    @attendee_attr_names = %w[aga_id birth_date comment confirmed email gender phone special_request roomate_request].sort
    @attendees = Attendee.yr(@year).where('lower(substr(family_name,1,1)) between ? and ?', params[:min], params[:max])
    @attendees.order('user_id, family_name, given_name')
    @tmt_names = AttendeeTournament.tmt_names_by_attendee(@year.year)
    render :layout => "print"
  end

  def index
  end

  def invoices
    users = User.yr(@year).all
    @user_count = users.count
    @invoice_total_across_all_users = users.map(&:get_invoice_total).reduce(:+)
  end

  def emails
    @atnd_email_list = ""
    Attendee.yr(@year).each { |a|
      @atnd_email_list += "\"#{a.get_full_name}\" <#{a.email}>, "
      }
  end

  def activities
    @activities = Activity.yr(@year).order :leave_time
    @activities_by_date = @activities.group_by {|activity| activity.leave_time.to_date}
  end

  def outstanding_balances
    @users = User.yr(@year).includes(User::EAGER_LOAD_CONFIG_FOR_INVOICES)
    @users.keep_if { |u| u.balance >= 0.01 }

    # Sort by family_name.  Normally we would do this in the query,
    # but joining on primary_attendee would conflict with our eager
    # loading configuration.
    @users.sort!{|a,b| a.primary_attendee.family_name <=> b.primary_attendee.family_name}
  end

  def transactions
    @transactions = Transaction.yr(@year).all
    @sales = Transaction.yr(@year).where("trantype = ?", "S")<commit_msg>include users who are due refunds<commit_after>require 'csv'

class ReportsController < ApplicationController

  # Access Control
  before_filter :authorize_read_report
  def authorize_read_report() authorize! :read, :report end

  def attendees
    @attendees = Attendee.yr(@year).all
    @attendee_count = @attendees.count
    @user_count = User.yr(@year).count

    # build csv header line
    # the order here must match attendee_to_array() in reports_helper.rb
    cols = []
    if @attendee_count > 0 then
      cols << 'user_email'
      cols << @attendees.first.attribute_names_for_csv
      Plan.yr(@year).order(:name).each { |p| cols << "Plan: " + safe_for_csv(p.name) }
      claimable_discounts = Discount.yr(@year).where('is_automatic = ?', false).order(:name)
      claimable_discounts.each { |d| cols << "Discount: " + safe_for_csv(d.name) }
      Tournament.yr(@year).order(:name).each { |t| cols << "Tournament: " + safe_for_csv(t.name) }
    end
    @csv_header_line = cols.join(',')

    respond_to do |format|
      format.html do render :attendees end
      format.csv do render_csv("usgc_attendees_#{Time.now.strftime("%Y-%m-%d")}") end
    end
  end

  def atn_badges_all
    @attendees = Attendee.yr(@year).where('lower(substr(family_name,1,1)) between ? and ?', params[:min], params[:max])
    @attendees.order('family_name, given_name')
    render :layout => "print"
  end

  def atn_reg_sheets
    @attendee_attr_names = %w[aga_id birth_date comment confirmed email gender phone special_request roomate_request].sort
    @attendees = Attendee.yr(@year).where('lower(substr(family_name,1,1)) between ? and ?', params[:min], params[:max])
    @attendees.order('user_id, family_name, given_name')
    @tmt_names = AttendeeTournament.tmt_names_by_attendee(@year.year)
    render :layout => "print"
  end

  def index
  end

  def invoices
    users = User.yr(@year).all
    @user_count = users.count
    @invoice_total_across_all_users = users.map(&:get_invoice_total).reduce(:+)
  end

  def emails
    @atnd_email_list = ""
    Attendee.yr(@year).each { |a|
      @atnd_email_list += "\"#{a.get_full_name}\" <#{a.email}>, "
      }
  end

  def activities
    @activities = Activity.yr(@year).order :leave_time
    @activities_by_date = @activities.group_by {|activity| activity.leave_time.to_date}
  end

  def outstanding_balances
    @users = User.yr(@year).includes(User::EAGER_LOAD_CONFIG_FOR_INVOICES)

    # Keep users with non-zero balances.  Obviously, we want to see
    # users who owe us money, but it is also useful for the registrar
    # to see people who deserve refunds.
    @users.keep_if { |u| u.balance >= 0.01 || u.balance <= -0.01 }

    # Sort by family_name.  Normally we would do this in the query,
    # but joining on primary_attendee would conflict with our eager
    # loading configuration.
    @users.sort!{|a,b| a.primary_attendee.family_name <=> b.primary_attendee.family_name}
  end

  def transactions
    @transactions = Transaction.yr(@year).all
    @sales = Transaction.yr(@year).where("trantype = ?", "S")
{'fraction_non_alphanumeric': 0.13302907369844488, 'fraction_numerical': 0.003211629479377958, 'mean_word_length': 3.882013201320132, 'pattern_counts': {'":': 0, '<': 30, '<?xml version=': 0, '>': 15, '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': '3815279', 'n_tokens_mistral': 2102, 'n_tokens_neox': 2040, 'n_words': 419}