<commit_before>class TermController < ApplicationController


  # get all terms
  def all_terms
    ActiveRecord::Base.include_root_in_json = false
    t = EnrollmentTerm.find(:all, :select => select_fields, :conditions => ["workflow_state = 'active' AND (root_account_id = 2)"])
    respond_to do |format|
      format.json {render :json => t}
    end
    ActiveRecord::Base.include_root_in_json = true
  end

  # get specific term by sis id
  def term_by_sis_id
    ActiveRecord::Base.include_root_in_json = false
    t = EnrollmentTerm.find(:all, :select => select_fields, :conditions => ["workflow_state = 'active' AND (root_account_id = 2) AND (sis_source_id = '#{params[:sis_id]}')"])
    respond_to do |format|
      format.json {render :json => t}
    end
    ActiveRecord::Base.include_root_in_json = true
  end

  # get current term
  def current_term
    ActiveRecord::Base.include_root_in_json = false
    t = EnrollmentTerm.find(:all, :select => select_fields, :conditions => ["workflow_state = 'active' AND (root_account_id = 2) AND (:date BETWEEN start_at AND end_at) AND (sis_source_id IS NOT NULL)", {:date => DateTime.now}]).first
    respond_to do |format|
      format.json {render :json => t}
    end
    ActiveRecord::Base.include_root_in_json = true
  end

  # get next n term(s)
  def next_terms
    ActiveRecord::Base.include_root_in_json = false
    t = EnrollmentTerm.find(:all, :select => select_fields, :conditions => ["workflow_state = 'active' AND (start_at > :date) AND (sis_source_id IS NOT NULL)", {:date => DateTime.now}], :order => "sis_source_id", :limit => params[:num_terms])
    respond_to do |format|
      format.json {render :json => t}
    end
    ActiveRecord::Base.include_root_in_json = true
  end

  # get prev n term(s)
  def prev_terms(num_terms=1)
    ActiveRecord::Base.include_root_in_json = false
    t = EnrollmentTerm.find(:all, :select => select_fields, :conditions => ["workflow_state = 'active' AND (end_at < :date) AND (sis_source_id IS NOT NULL)", {:date => DateTime.now}], :order => "sis_source_id DESC", :limit => params[:num_terms])
    respond_to do |format|
      format.json {render :json => t}
    end
    ActiveRecord::Base.include_root_in_json = true
  end

  private
  def select_fields
    "name, sis_source_id, start_at, end_at"
  end

end<commit_msg>add term id to json response<commit_after>class TermController < ApplicationController


  # get all terms
  def all_terms
    ActiveRecord::Base.include_root_in_json = false
    t = EnrollmentTerm.find(:all, :select => select_fields, :conditions => ["workflow_state = 'active' AND (root_account_id = 2)"])
    respond_to do |format|
      format.json {render :json => t}
    end
    ActiveRecord::Base.include_root_in_json = true
  end

  # get specific term by sis id
  def term_by_sis_id
    ActiveRecord::Base.include_root_in_json = false
    t = EnrollmentTerm.find(:all, :select => select_fields, :conditions => ["workflow_state = 'active' AND (root_account_id = 2) AND (sis_source_id = '#{params[:sis_id]}')"])
    respond_to do |format|
      format.json {render :json => t}
    end
    ActiveRecord::Base.include_root_in_json = true
  end

  # get current term
  def current_term
    ActiveRecord::Base.include_root_in_json = false
    t = EnrollmentTerm.find(:all, :select => select_fields, :conditions => ["workflow_state = 'active' AND (root_account_id = 2) AND (:date BETWEEN start_at AND end_at) AND (sis_source_id IS NOT NULL)", {:date => DateTime.now}]).first
    respond_to do |format|
      format.json {render :json => t}
    end
    ActiveRecord::Base.include_root_in_json = true
  end

  # get next n term(s)
  def next_terms
    ActiveRecord::Base.include_root_in_json = false
    t = EnrollmentTerm.find(:all, :select => select_fields, :conditions => ["workflow_state = 'active' AND (start_at > :date) AND (sis_source_id IS NOT NULL)", {:date => DateTime.now}], :order => "sis_source_id", :limit => params[:num_terms])
    respond_to do |format|
      format.json {render :json => t}
    end
    ActiveRecord::Base.include_root_in_json = true
  end

  # get prev n term(s)
  def prev_terms(num_terms=1)
    ActiveRecord::Base.include_root_in_json = false
    t = EnrollmentTerm.find(:all, :select => select_fields, :conditions => ["workflow_state = 'active' AND (end_at < :date) AND (sis_source_id IS NOT NULL)", {:date => DateTime.now}], :order => "sis_source_id DESC", :limit => params[:num_terms])
    respond_to do |format|
      format.json {render :json => t}
    end
    ActiveRecord::Base.include_root_in_json = true
  end

  private
  def select_fields
    "id, name, sis_source_id, start_at, end_at"
  end

end
{'fraction_non_alphanumeric': 0.12277694450396401, 'fraction_numerical': 0.0017141632740518534, 'mean_word_length': 4.135313531353136, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 49, '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': '3630038', 'n_tokens_mistral': 1572, 'n_tokens_neox': 1535, 'n_words': 397}