web/app/models/tag.rb
author Jan Vrany <jan.vrany@fit.cvut.cz>
Sat, 24 Aug 2013 00:18:50 +0100
changeset 177 8e7f0029550d
parent 164 120a4f1e25c0
child 304 91286a87b569
permissions -rw-r--r--
Support for parameters in web app. Parameters are now imported and saved in the DB. Tag-based comparison now can deal with them and correctly displays results with multiple results for same benchmark (but different parameter set)
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
164
120a4f1e25c0 introduce tags
Marcel Hlopko <marcel.hlopko@gmail.com>
parents:
diff changeset
     1
class Tag < ActiveRecord::Base
120a4f1e25c0 introduce tags
Marcel Hlopko <marcel.hlopko@gmail.com>
parents:
diff changeset
     2
120a4f1e25c0 introduce tags
Marcel Hlopko <marcel.hlopko@gmail.com>
parents:
diff changeset
     3
  has_and_belongs_to_many :benchmark_batches
120a4f1e25c0 introduce tags
Marcel Hlopko <marcel.hlopko@gmail.com>
parents:
diff changeset
     4
120a4f1e25c0 introduce tags
Marcel Hlopko <marcel.hlopko@gmail.com>
parents:
diff changeset
     5
  def all_configurations
120a4f1e25c0 introduce tags
Marcel Hlopko <marcel.hlopko@gmail.com>
parents:
diff changeset
     6
    benchmark_batches.map(&:benchmark_configuration).uniq
120a4f1e25c0 introduce tags
Marcel Hlopko <marcel.hlopko@gmail.com>
parents:
diff changeset
     7
  end
120a4f1e25c0 introduce tags
Marcel Hlopko <marcel.hlopko@gmail.com>
parents:
diff changeset
     8
120a4f1e25c0 introduce tags
Marcel Hlopko <marcel.hlopko@gmail.com>
parents:
diff changeset
     9
  def all_benchmark_infos
120a4f1e25c0 introduce tags
Marcel Hlopko <marcel.hlopko@gmail.com>
parents:
diff changeset
    10
    benchmark_batches.
120a4f1e25c0 introduce tags
Marcel Hlopko <marcel.hlopko@gmail.com>
parents:
diff changeset
    11
      flat_map(&:benchmark_results).
120a4f1e25c0 introduce tags
Marcel Hlopko <marcel.hlopko@gmail.com>
parents:
diff changeset
    12
      map(&:benchmark_info).
120a4f1e25c0 introduce tags
Marcel Hlopko <marcel.hlopko@gmail.com>
parents:
diff changeset
    13
      uniq.
120a4f1e25c0 introduce tags
Marcel Hlopko <marcel.hlopko@gmail.com>
parents:
diff changeset
    14
      sort { |a, b| a.name <=> b.name }
120a4f1e25c0 introduce tags
Marcel Hlopko <marcel.hlopko@gmail.com>
parents:
diff changeset
    15
  end
120a4f1e25c0 introduce tags
Marcel Hlopko <marcel.hlopko@gmail.com>
parents:
diff changeset
    16
177
8e7f0029550d Support for parameters in web app.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 164
diff changeset
    17
  def benchmark_batches_latest_for(benchmark_configuration)
8e7f0029550d Support for parameters in web app.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 164
diff changeset
    18
    benchmark_batches.
8e7f0029550d Support for parameters in web app.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 164
diff changeset
    19
      where(benchmark_configuration: benchmark_configuration)
8e7f0029550d Support for parameters in web app.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 164
diff changeset
    20
  end
8e7f0029550d Support for parameters in web app.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 164
diff changeset
    21
8e7f0029550d Support for parameters in web app.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 164
diff changeset
    22
164
120a4f1e25c0 introduce tags
Marcel Hlopko <marcel.hlopko@gmail.com>
parents:
diff changeset
    23
  def latest_results_for(benchmark_info, benchmark_configuration)
120a4f1e25c0 introduce tags
Marcel Hlopko <marcel.hlopko@gmail.com>
parents:
diff changeset
    24
    benchmark_batches.
120a4f1e25c0 introduce tags
Marcel Hlopko <marcel.hlopko@gmail.com>
parents:
diff changeset
    25
      joins(:benchmark_results).
120a4f1e25c0 introduce tags
Marcel Hlopko <marcel.hlopko@gmail.com>
parents:
diff changeset
    26
      where(benchmark_configuration: benchmark_configuration,
120a4f1e25c0 introduce tags
Marcel Hlopko <marcel.hlopko@gmail.com>
parents:
diff changeset
    27
            benchmark_results: { benchmark_info: benchmark_info }).
120a4f1e25c0 introduce tags
Marcel Hlopko <marcel.hlopko@gmail.com>
parents:
diff changeset
    28
      max { |a, b| a.performed_at <=> b.performed_at }.
120a4f1e25c0 introduce tags
Marcel Hlopko <marcel.hlopko@gmail.com>
parents:
diff changeset
    29
      result_for(benchmark_info)
120a4f1e25c0 introduce tags
Marcel Hlopko <marcel.hlopko@gmail.com>
parents:
diff changeset
    30
  end
120a4f1e25c0 introduce tags
Marcel Hlopko <marcel.hlopko@gmail.com>
parents:
diff changeset
    31
120a4f1e25c0 introduce tags
Marcel Hlopko <marcel.hlopko@gmail.com>
parents:
diff changeset
    32
end