<commit_before>class RunFilter 

  attr_reader :runs, :filters

  def initialize(runs, filters = {})
    @runs = runs
    @filters = filters
  end

  def filter!
    filter_by_pickup_time!
    filter_by_days_of_week!
    filter_by_vehicle!
    filter_by_driver!
    filter_by_result!

    @runs
  end

  private 

  def filter_by_pickup_time!
    utility = Utility.new
    t_start = utility.parse_date(@filters[:start]) 
    t_end = utility.parse_date(@filters[:end]) 

    if !t_start && !t_end
      time    = Time.now
      t_start = time.beginning_of_week.to_date.in_time_zone
      t_end   = t_start + 6.days
    elsif !t_end
      t_end   = t_start + 6.days
    elsif !t_start
      t_start   = t_end - 6.days
    end
    
    @runs = @runs.
      where("date >= '#{t_start.beginning_of_day.utc.strftime "%Y-%m-%d %H:%M:%S"}'").
      where("date <= '#{t_end.end_of_day.utc.strftime "%Y-%m-%d %H:%M:%S"}'").order(:date)
    
    @filters[:start] = t_start.to_i
    @filters[:end] = t_end.to_i
  end

  def filter_by_days_of_week!
    days_of_week = @filters[:days_of_week].blank? ? "0,1,2,3,4,5,6" : @filters[:days_of_week]
    @runs = @runs.where('extract(dow from date) in (?)', days_of_week.split(','))
    @filters[:days_of_week] = days_of_week
  end

  def filter_by_vehicle!
    if @filters[:vehicle_id].present?  
      @runs = @runs.includes(:vehicle).references(:vehicle).where(vehicle_id: @filters[:vehicle_id]) 
    end
  end

  def filter_by_driver!<commit_msg>[#108642956] Only compare day part in runs filtering<commit_after>class RunFilter 

  attr_reader :runs, :filters

  def initialize(runs, filters = {})
    @runs = runs
    @filters = filters
  end

  def filter!
    filter_by_pickup_time!
    filter_by_days_of_week!
    filter_by_vehicle!
    filter_by_driver!
    filter_by_result!

    @runs
  end

  private 

  def filter_by_pickup_time!
    utility = Utility.new
    t_start = utility.parse_date(@filters[:start]) 
    t_end = utility.parse_date(@filters[:end]) 

    if !t_start && !t_end
      time    = Time.now
      t_start = time.beginning_of_week.to_date.in_time_zone
      t_end   = t_start + 6.days
    elsif !t_end
      t_end   = t_start + 6.days
    elsif !t_start
      t_start   = t_end - 6.days
    end
    
    @runs = @runs.
      where("date >= '#{t_start.strftime "%Y-%m-%d"}'").
      where("date <= '#{t_end.strftime "%Y-%m-%d"}'").order(:date)
    
    @filters[:start] = t_start.to_i
    @filters[:end] = t_end.to_i
  end

  def filter_by_days_of_week!
    days_of_week = @filters[:days_of_week].blank? ? "0,1,2,3,4,5,6" : @filters[:days_of_week]
    @runs = @runs.where('extract(dow from date) in (?)', days_of_week.split(','))
    @filters[:days_of_week] = days_of_week
  end

  def filter_by_vehicle!
    if @filters[:vehicle_id].present?  
      @runs = @runs.includes(:vehicle).references(:vehicle).where(vehicle_id: @filters[:vehicle_id]) 
    end
  end

  def filter_by_driver!
{'fraction_non_alphanumeric': 0.13897383622154263, 'fraction_numerical': 0.009853890587835541, 'mean_word_length': 3.134831460674157, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '1651553', 'n_tokens_mistral': 1197, 'n_tokens_neox': 1137, 'n_words': 190}