class Evoc::Scenario
Attributes
aggregator[RW]
algorithm[RW]
case_id[RW]
granularity[RW]
max_size[RW]
measures[RW]
model_age[RW]
model_size[RW]
opts[RW]
permutation[RW]
query[RW]
scenario_id[RW]
stats[RW]
tx[RW]
tx_id[RW]
tx_index[RW]
Public Class Methods
new(opts = Hash.new)
click to toggle source
# File lib/evoc/scenario.rb, line 22 def initialize(opts = Hash.new) logger.debug "Initialized new scenario with configuration: #{opts}" self.opts = opts self.scenario_id = opts.hash self.tx_id = opts[:tx_id] self.model_age = opts[:model_age] opts.each do |attribute,value| self.send("#{attribute}=", value) end end
Public Instance Methods
<=>(other)
click to toggle source
<=> defines how to compare two Query objects
# File lib/evoc/scenario.rb, line 37 def <=> other return nil unless other.is_a?(Query) comparison = 0 # first we compare the tx id if (self.tx_id <=> other.tx_id) == 0 # if we also have the same query if (self.query.sort <=> other.query.sort) == 0 # use history size as comparator comparison = (self.model_size <=> other.model_size) else # use the query comparison = (self.query.sort <=> other.query.sort) end else # use the tx id comparison = (self.tx_id <=> other.tx_id) end comparison end
expected_outcome()
click to toggle source
@return [Array] the list of expected items
# File lib/evoc/scenario.rb, line 213 def expected_outcome expected_outcome = (self.tx.items - self.query) if expected_outcome.empty? logger.warn "The expected outcome was empty" end return expected_outcome end
expected_outcome_size()
click to toggle source
@return [Integer] the size of the expected outcome
# File lib/evoc/scenario.rb, line 223 def expected_outcome_size self.expected_outcome.size end
max_size=(value)
click to toggle source
# File lib/evoc/scenario.rb, line 168 def max_size=(value) if !value.nil? if value.respond_to?(:to_i) @max_size = value.to_i else raise ArgumentError.new, "value for max_size could not be converted to integer, value was: #{value}" end end end
measures=(measures)
click to toggle source
Custom setter for measures
# File lib/evoc/scenario.rb, line 199 def measures=(measures) if !measures.nil? # internally, all interestingness measures are # represented as :m_measurename (symbols), so we concatinate # 'm_' and symbolize the list of given measures if measures.is_a?(String) measures = measures.split(',') end @measures = measures.map {|m| (/\Am_/ =~ m).nil? ? ('m_'+m).to_sym : m.to_sym} end end
model_end()
click to toggle source
@return [Integer] the index in the history where the model ends
# File lib/evoc/scenario.rb, line 140 def model_end value = (self.tx_index - 1 - self.model_age.to_i) if value < 0 raise ArgumentError, "The model end index was negative (model_size:#{self.model_size}, tx_index:#{self.tx_index})" elsif value < self.model_start raise ArgumentError, "The model end was before the model start (start: #{self.model_start}, end: #{value})" end return value end
model_hours()
click to toggle source
@return [Integer] the time between the first and last transaction in the model
# File lib/evoc/scenario.rb, line 152 def model_hours model_end_tx = Evoc::HistoryStore.base_history.get_tx(id: self.model_end) model_start_tx = Evoc::HistoryStore.base_history.get_tx(id: self.model_start) return TimeDifference.between(model_start_tx.date,model_end_tx.date).in_hours end
model_percentage()
click to toggle source
@return [Float] the percentage of the whole history that is used in the model
# File lib/evoc/scenario.rb, line 109 def model_percentage self.model_size.to_i == 0 ? 100 : ((self.model_size.to_f/self.tx_index)*100).round(2) end
model_size=(size)
click to toggle source
Sets the model size in this scenario
If set to 0 (zero), the maximum possible size is calculated In this case, model age will be taken into account
@param [Integer] the size of the model
# File lib/evoc/scenario.rb, line 120 def model_size=(size) if size.to_i == 0 @model_size = (self.model_age.nil? ? self.tx_index : self.tx_index - self.model_age) else @model_size = size.to_i end end
model_start()
click to toggle source
@return [Integer] the index in the history where the model starts
# File lib/evoc/scenario.rb, line 130 def model_start value = self.tx_index - self.model_size.to_i - self.model_age.to_i if value < 0 raise ArgumentError, "Model out of bound" end return value end
query=(query)
click to toggle source
custom setter for query
# File lib/evoc/scenario.rb, line 180 def query=(query) if !query.nil? raise ArgumentError, "Query must be an array" unless query.is_a?(Array) @query = query # convert to list of integers @query.map!(&:to_i) if !self.tx.nil? if @query.size >= (self.tx.size) $stderr.warn "The query was larger than or equal to the size of the transaction (Qs: #{@query.size}, Tx size: #{self.tx.size})" end end if @query.empty? raise ArgumentError, "The query was empty" end end end
query_percentage()
click to toggle source
# File lib/evoc/scenario.rb, line 160 def query_percentage total_items = self.query.size.to_i + self.expected_outcome.size (self.query.size.to_f/total_items*100).round end
query_size()
click to toggle source
@return [Integer] the size of the query
# File lib/evoc/scenario.rb, line 103 def query_size self.query.size end
recommendation?()
click to toggle source
# File lib/evoc/scenario.rb, line 74 def recommendation? Evoc::RecommendationCache.recommendation_cached?(algorithm: self.algorithm, query: self.query, model_start: self.model_start, model_end: self.model_end, max_size: self.max_size) end
to_h()
click to toggle source
# File lib/evoc/scenario.rb, line 58 def to_h fields = %w(case_id granularity scenario_id tx_id tx_index tx_size query_size query_percentage expected_outcome_size model_size model_hours model_age max_size algorithm aggregator measures stats) hash = Hash.new fields.each do |key| value = self.method(key).call if value.is_a?(Array) hash[key] = value.join(',') elsif value.is_a?(Hash) hash.merge!(value) else hash[key] = value end end return hash end
to_s()
click to toggle source
# File lib/evoc/scenario.rb, line 82 def to_s self.opts end
tx_size()
click to toggle source
@return [Integer] the size of this scenarios transaction
# File lib/evoc/scenario.rb, line 235 def tx_size self.tx.size end