<commit_before>class MainController < ApplicationController
  layout 'capacitor'
  def index
    @candidates ||= []

    @sla              = CloudCapacitor::Settings.capacitor["sla"]             
    @cpu_limit        = CloudCapacitor::Settings.capacitor["cpu_limit"]       
    @mem_limit        = CloudCapacitor::Settings.capacitor["mem_limit"]       
    @low_deviation    = CloudCapacitor::Settings.capacitor["low_deviation"]   
    @medium_deviation = CloudCapacitor::Settings.capacitor["medium_deviation"]

    @workload_attitude      ||= :optimistic    
    @configuration_attitude ||= :optimistic

  end

  def eval_performance
    @workloadlist = params[:workloadlist].map!{|x| x.to_i}
    @workload_attitude = params[:workload_attitude].to_sym
    @configuration_attitude = params[:configuration_attitude].to_sym
    
    CloudCapacitor::Settings.capacitor["sla"]              = params[:sla].to_i              if !params[:sla].empty?
    CloudCapacitor::Settings.capacitor["cpu_limit"]        = params[:cpu_limit].to_f        if !params[:cpu_limit].empty?
    CloudCapacitor::Settings.capacitor["mem_limit"]        = params[:mem_limit].to_f        if !params[:mem_limit].empty?
    CloudCapacitor::Settings.capacitor["low_deviation"]    = params[:low_deviation].to_f    if !params[:low_deviation].empty?
    CloudCapacitor::Settings.capacitor["medium_deviation"] = params[:medium_deviation].to_f if !params[:medium_deviation].empty?

    @sla              = CloudCapacitor::Settings.capacitor.sla
    @cpu_limit        = CloudCapacitor::Settings.capacitor.cpu_limit
    @mem_limit        = CloudCapacitor::Settings.capacitor.mem_limit
    @low_deviation    = CloudCapacitor::Settings.capacitor.low_deviation
    @medium_deviation = CloudCapacitor::Settings.capacitor.medium_deviation

    capacitor = CloudCapacitor::Capacitor.new
    capacitor.executor = CloudCapacitor::Executors::DummyExecutor.new
    capacitor.strategy = CloudCapacitor::Strategies::MCG_Strategy.new

    capacitor.strategy.attitude workload: @workload_attitude, 
                                config:   @configuration_attitude

    capacitor.run_for(*@workloadlist)
    
    @candidates = capacitor.candidates
    @cost = capacitor.run_cost
    @executions = capacitor.executions
    @trace = capacitor.execution_trace
    @full_trace = capacitor.results_trace

    @configs = capacitor.deployment_space.configs_by_price.clone
    @configs.sort_by! { |c| [c.category, c.price] }
    @reference = ReferenceResult.load
    
    evaluate_results_precision<commit_msg>Use new capacitor way of returning candidate configs<commit_after>class MainController < ApplicationController
  layout 'capacitor'
  def index
    @candidates ||= []

    @sla              = CloudCapacitor::Settings.capacitor["sla"]             
    @cpu_limit        = CloudCapacitor::Settings.capacitor["cpu_limit"]       
    @mem_limit        = CloudCapacitor::Settings.capacitor["mem_limit"]       
    @low_deviation    = CloudCapacitor::Settings.capacitor["low_deviation"]   
    @medium_deviation = CloudCapacitor::Settings.capacitor["medium_deviation"]

    @workload_attitude      ||= :optimistic    
    @configuration_attitude ||= :optimistic

  end

  def eval_performance
    @workloadlist = params[:workloadlist].map!{|x| x.to_i}
    @workload_attitude = params[:workload_attitude].to_sym
    @configuration_attitude = params[:configuration_attitude].to_sym
    
    CloudCapacitor::Settings.capacitor["sla"]              = params[:sla].to_i              if !params[:sla].empty?
    CloudCapacitor::Settings.capacitor["cpu_limit"]        = params[:cpu_limit].to_f        if !params[:cpu_limit].empty?
    CloudCapacitor::Settings.capacitor["mem_limit"]        = params[:mem_limit].to_f        if !params[:mem_limit].empty?
    CloudCapacitor::Settings.capacitor["low_deviation"]    = params[:low_deviation].to_f    if !params[:low_deviation].empty?
    CloudCapacitor::Settings.capacitor["medium_deviation"] = params[:medium_deviation].to_f if !params[:medium_deviation].empty?

    @sla              = CloudCapacitor::Settings.capacitor.sla
    @cpu_limit        = CloudCapacitor::Settings.capacitor.cpu_limit
    @mem_limit        = CloudCapacitor::Settings.capacitor.mem_limit
    @low_deviation    = CloudCapacitor::Settings.capacitor.low_deviation
    @medium_deviation = CloudCapacitor::Settings.capacitor.medium_deviation

    capacitor = CloudCapacitor::Capacitor.new
    capacitor.executor = CloudCapacitor::Executors::DummyExecutor.new
    capacitor.strategy = CloudCapacitor::Strategies::MCG_Strategy.new

    capacitor.strategy.attitude workload: @workload_attitude, 
                                config:   @configuration_attitude

    @candidates = capacitor.run_for(*@workloadlist)
    
    @cost = capacitor.run_cost
    @executions = capacitor.executions
    @trace = capacitor.execution_trace
    @full_trace = capacitor.results_trace

    @configs = capacitor.deployment_space.configs_by_price.clone
    @configs.sort_by! { |c| [c.category, c.price] }
    @reference = ReferenceResult.load
    
    evaluate_results_precision
{'fraction_non_alphanumeric': 0.10782778864970646, 'fraction_numerical': 0.0, 'mean_word_length': 3.6633211678832116, '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': '503284', 'n_tokens_mistral': 1614, 'n_tokens_neox': 1572, 'n_words': 191}