<commit_before>class Sprint < ActiveRecord::Base
  DEFAULT_DURATION = 2.weeks - 1.day

  has_many :tickets
  validates_presence_of :start, :end
  attr_accessible :end, :start

  class << self
    # Returns the current sprint if it's still in progress.
    # If the last sprint has already finished, creates a new one of DEFAULT_DURATION days and returns it.
    def current!
      previous = Sprint.last_one
      return previous if previous.try(:in_progress?)
      Sprint.create_from_previous(previous)
    end

    def last_one
      Sprint.find_by_end(maximum('end'))
    end

    def create_from_previous(previous)
      start_date = previous ? previous.end.tomorrow : Date.today
      end_date = start_date + DEFAULT_DURATION
      Sprint.create!(start: start_date, end: end_date)
    end
  end

  def date_span
    "#{start.to_date} - #{self.end.to_date}"
  end

  def total_hours(conditions = {})
    tickets.where(conditions).complete.collect(&:real_hours).compact.inject(:+)
  end

  def total_estimate(conditions = {})
    tickets.where(conditions).complete.collect(&:points).compact.inject(:+)
  end

  def total_velocity(conditions = {})
    total_estimate(conditions) / total_hours(conditions).to_f
  end

  def name
    "#{start.strftime('%m/%d/%y')} - #{self.end.strftime('%m/%d/%y')}"
  end

  private

  def in_progress?
    Date.today.between?(self.start, self.end)
  end
end<commit_msg>Fix crash in reports screen<commit_after>class Sprint < ActiveRecord::Base
  DEFAULT_DURATION = 2.weeks - 1.day

  has_many :tickets
  validates_presence_of :start, :end
  attr_accessible :end, :start

  class << self
    # Returns the current sprint if it's still in progress.
    # If the last sprint has already finished, creates a new one of DEFAULT_DURATION days and returns it.
    def current!
      previous = Sprint.last_one
      return previous if previous.try(:in_progress?)
      Sprint.create_from_previous(previous)
    end

    def last_one
      Sprint.find_by_end(maximum('end'))
    end

    def create_from_previous(previous)
      start_date = previous ? previous.end.tomorrow : Date.today
      end_date = start_date + DEFAULT_DURATION
      Sprint.create!(start: start_date, end: end_date)
    end
  end

  def date_span
    "#{start.to_date} - #{self.end.to_date}"
  end

  def total_hours(conditions = {})
    tickets.where(conditions).complete.collect(&:real_hours).compact.inject(:+) || 0
  end

  def total_estimate(conditions = {})
    tickets.where(conditions).complete.collect(&:points).compact.inject(:+) || 0
  end

  def total_velocity(conditions = {})
    hours = total_hours(conditions)
    return 0 if hours.zero?
    total_estimate(conditions) / hours.to_f
  end

  def name
    "#{start.strftime('%m/%d/%y')} - #{self.end.strftime('%m/%d/%y')}"
  end

  private

  def in_progress?
    Date.today.between?(self.start, self.end)
  end
end
{'fraction_non_alphanumeric': 0.11485079805690493, 'fraction_numerical': 0.0024288688410825814, 'mean_word_length': 3.4836702954898913, 'pattern_counts': {'":': 0, '<': 9, '<?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': '2316270', 'n_tokens_mistral': 979, 'n_tokens_neox': 931, 'n_words': 213}