<commit_before>class TripsRunsController < ApplicationController
  before_action :authorization

  def index
    Date.beginning_of_week= :sunday
    filters_hash = runs_trips_params || {}
    update_sessions(filters_hash.except(:start, :end))

    # by default, select all trip results
    unless session[:trip_result_id].present?
      session[:trip_result_id] = [TripResult::UNSCHEDULED_ID, TripResult::SHOW_ALL_ID] + TripResult.pluck(:id).uniq
    end
    
    query_trips_runs
    
    @run_trip_day    = Utility.new.parse_date(session[:run_trip_day])

    base_runs = @runs
    base_runs = add_cab_run(base_runs) if current_provider.try(:cab_enabled?)

    @runs_for_dropdown = add_unscheduled_run(base_runs).collect {|r| [r.label, r.id]}

    respond_to do |format|
      format.html
    end
  end

  def schedule
    @run = Run.find_by_id params[:run_id]
    @prev_run = Run.find_by_id(params[:prev_run_id]) if params[:prev_run_id].present?
    if @run
      @scheduler = TripScheduler.new(params[:trip_id], params[:run_id])
      @scheduler.execute

      query_trips_runs
    end
  end

  def unschedule
    @prev_run = Run.find_by_id(params[:prev_run_id])
    @target_trips = Trip.where(id: params[:trip_ids].split(','))
    if @target_trips.any?
      case params[:run_id]
      when Run::STANDBY_RUN_ID
        #TODO: standby
      when Run::CAB_RUN_ID
        @target_trips.update_all(cab: true)
      end

      @target_trips.update_all(run_id: nil)

      query_trips_runs
    end
  end

  # Ajax to update Run filter given a new date
  def runs_by_date
    @runs = Run.for_date(Utility.new.parse_date(params[:run_trip_day])).order(:name)
  end

  def run_trips
    @run = Run.find_by_id params[:run_id]
  end

  def cancel_run
    @run = Run.find_by_id params[:run_id]
    @run.cancel! if @run

    query_trips_runs
  end
  
  private<commit_msg>Fix conflicts<commit_after>class TripsRunsController < ApplicationController
  before_action :authorization

  def index
    Date.beginning_of_week= :sunday
    filters_hash = runs_trips_params || {}
    update_sessions(filters_hash.except(:start, :end))

    # by default, select all trip results
    unless session[:trip_result_id].present?
      session[:trip_result_id] = [TripResult::UNSCHEDULED_ID, TripResult::SHOW_ALL_ID] + TripResult.pluck(:id).uniq
    end
    
    query_trips_runs
    
    @run_trip_day    = Utility.new.parse_date(session[:run_trip_day])

    base_runs = @runs
    base_runs = add_cab_run(base_runs) if current_provider.try(:cab_enabled?)

    @runs_for_dropdown = add_unscheduled_run(base_runs).collect {|r| [r.label, r.id]}

    respond_to do |format|
      format.html
    end
  end

  def schedule
    @run = Run.find_by_id params[:run_id]
    @prev_run = Run.find_by_id(params[:prev_run_id]) if params[:prev_run_id].present?
    if @run
      @scheduler = TripScheduler.new(params[:trip_id], params[:run_id])
      @scheduler.execute

      query_trips_runs
    end
  end

  def unschedule
    @prev_run = Run.find_by_id(params[:prev_run_id])
    @target_trips = Trip.where(id: params[:trip_ids].split(','))
    if @target_trips.any?
      case params[:run_id]
      when Run::STANDBY_RUN_ID
        #TODO: standby
      when Run::CAB_RUN_ID
        @target_trips.update_all(cab: true)
      end

      @target_trips.update_all(run_id: nil)

      query_trips_runs
    end
  end

  # Ajax to update Run filter given a new date
  def runs_by_date
    @runs = Run.for_provider(current_provider_id).for_date(Utility.new.parse_date(params[:run_trip_day])).order(:name)
  end

  def run_trips
    @run = Run.find_by_id params[:run_id]
  end

  def cancel_run
    @run = Run.find_by_id params[:run_id]
    @run.cancel! if @run

    query_trips_runs
  end
  
  private
{'fraction_non_alphanumeric': 0.10351250665247472, 'fraction_numerical': 0.0, 'mean_word_length': 3.5126050420168067, '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': '5987918', 'n_tokens_mistral': 1430, 'n_tokens_neox': 1373, 'n_words': 240}