Class: TrafficPatterns

Inherits:
SlowActions
  • Object
show all
Defined in:
lib/traffic_patterns.rb

Instance Method Summary collapse

Instance Method Details

#find_exitsObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/traffic_patterns.rb', line 10

def find_exits
  sessions.each do |s|
    s.log_entries.inject do |previous, current|
      previous.action.exits ||= []
      p_exit = previous.action.exits.detect{|e| 
        e.destination == current.action
      }
      unless p_exit
        p_exit = TrafficPattern::Exit.new
        p_exit.frequency = 0
        p_exit.destination = current.action
        previous.action.exits << p_exit
      end
      p_exit.frequency += 1
      previous = current
    end
  end

  actions.each do |a|
    a.exits ||= []
    total_freq = a.exits.inject(0){|sum, e| sum += e.frequency}
    a.exits.each do |e|
      e.probability = e.frequency.to_f / total_freq.to_f
    end
  end
end

#parse_file(*args) ⇒ Object



5
6
7
8
# File 'lib/traffic_patterns.rb', line 5

def parse_file(*args)
  super(*args)
  find_exits
end

#to_png(file_path) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/traffic_patterns.rb', line 37

def to_png(file_path)    
  tp = self
  YUML::useCaseDiagram( :scruffy, :scale => 100 ) {
    tp.actions.each do |a|
      a.exits.each do |e|
        source = a.controller.name+"#"+a.name
        target = e.destination.controller.name+"#"+e.destination.name
        midpoint = "#{source}_#{target}_#{e.probability}"
        _(source) > _(midpoint)
        _(midpoint) >_(target)
      end
    end
  }.to_png( file_path )
end