Class: CPEE::Transformation::Source::Beautiful

Inherits:
Object
  • Object
show all
Defined in:
lib/cpee/transformation/beautiful.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(text) ⇒ Beautiful

{{{



32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/cpee/transformation/beautiful.rb', line 32

def initialize(text) #{{{
  Node.class_variable_set(:@@niceid,  {})

  @tree = Tree.new
  @start = nil

  @dataelements = {}
  @endpoints = {}
  @graph = Graph.new

  extract_log(text)

  @traces = Traces.new [[@start]]
end

Instance Attribute Details

#dataelementsObject (readonly)

Returns the value of attribute dataelements.



30
31
32
# File 'lib/cpee/transformation/beautiful.rb', line 30

def dataelements
  @dataelements
end

#endpointsObject (readonly)

Returns the value of attribute endpoints.



30
31
32
# File 'lib/cpee/transformation/beautiful.rb', line 30

def endpoints
  @endpoints
end

#graphObject (readonly)

Returns the value of attribute graph.



30
31
32
# File 'lib/cpee/transformation/beautiful.rb', line 30

def graph
  @graph
end

#startObject (readonly)

Returns the value of attribute start.



30
31
32
# File 'lib/cpee/transformation/beautiful.rb', line 30

def start
  @start
end

#tracesObject (readonly)

Returns the value of attribute traces.



30
31
32
# File 'lib/cpee/transformation/beautiful.rb', line 30

def traces
  @traces
end

#treeObject (readonly)

Returns the value of attribute tree.



30
31
32
# File 'lib/cpee/transformation/beautiful.rb', line 30

def tree
  @tree
end

Instance Method Details

#extract_log(text) ⇒ Object

{{{



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
# File 'lib/cpee/transformation/beautiful.rb', line 62

def extract_log(text) #{{{
  first = nil
  decisions = {}
  decisions_join = {}
  loops = []
  loops_end = []
  parallel_joins = []
  @start = Node.new(0,SecureRandom.uuid,:startEvent,'start',0,1)
  @graph.add_node @start
  last = @start
  cond = nil
  text.each_line do |line|
    if line =~ /^\s*beautiful_pipeline_end_check\s-\s(\d+)\s-\s(\d+)/ #{{{
      key = $1
      if decisions[key]
        decisions_join[key] << last
      end
      lid = SecureRandom.uuid
      n1 = Node.new(0,lid,:exclusiveGateway,'xor end',0,0)
      graph.add_node n1
      decisions_join[key].each do |e|
        graph.add_link Link.new(e.id,lid,nil)
      end
      last = n1
      decisions_join.delete(key)
      decisions.delete(key) #}}}
    elsif line =~ /^\s*beautiful_pipeline_check\s-\s(\d+)\s-\s(\d+)/ #{{{
      key = $1
      if decisions[key]
        decisions_join[key] << last
        last = decisions[key]
      else
        lid = SecureRandom.uuid
        n1 = Node.new(0,lid,:exclusiveGateway,'xor otherwise',0,0)
        graph.add_node n1
        graph.add_link Link.new(last.id,lid,nil)
        last = n1
        decisions[key] = n1
        decisions_join[key] = []
      end #}}}
    elsif line =~ /^\s*beautiful_pipeline_check\s-\s(\d+)\s-\s(.*)\s-\s(\d+)/ #{{{
      key = $1
      if decisions[key]
        decisions_join[key] << last
        last = decisions[key]
      else
        lid = SecureRandom.uuid
        cond = $2
        n1 = Node.new(0,lid,:exclusiveGateway,'xor',0,0)
        graph.add_link Link.new(last.id,lid,nil)
        graph.add_node n1
        last = n1
        decisions[key] = n1
        decisions_join[key] = []
      end #}}}
    elsif line =~ /^\s*beautiful_pipeline_loop\s-\s(.*)\s-\s(\d+)/ #{{{
      lid1 = SecureRandom.uuid
      lid2 = SecureRandom.uuid
      cond = $1
      n1 = Node.new(0,lid1,:exclusiveGateway,'loope',0,0)
      n2 = Node.new(0,lid2,:exclusiveGateway,'loops',0,0)
      graph.add_link Link.new(last.id,lid1,nil)
      graph.add_link Link.new(lid1,lid2,nil)
      graph.add_node n1
      graph.add_node n2
      last = n2
      loops << n1
      loops_end << n2 #}}}
    elsif line =~ /^\s*beautiful_pipeline_end_loop\s-\s(\d+)/ #{{{
      graph.add_link Link.new(last.id,loops.last.id,nil)
      last = n1
      loops << n1
      last = loops_end.pop
      loops.pop #}}}
    elsif line =~ /^\s*beautiful_pipeline_continue\s-\s(\d+)/ #{{{
      graph.add_link Link.new(last.id,loops.last.id,nil) #}}}
    elsif line =~ /^\s*beautiful_pipeline_break\s-\s(\d+)/ #{{{
      lid = SecureRandom.uuid
      n1 = Node.new(0,lid,:break,'break',0,0)
      graph.add_node n1
      graph.add_link Link.new(last.id,lid,nil)
      last = n1 #}}}
    elsif line =~ /^\s*beautiful_pipeline_parallel\s-\s(\d+)/ #{{{
      lid = SecureRandom.uuid
      n1 = Node.new(0,lid,:parallelGateway,'parallel_start',0,0)
      parallel_joins << [ n1, {} ]
      last = n1 #}}}
    elsif line =~ /^\s*beautiful_pipeline_end_parallel\s-\s(\d+)/ #{{{
      lay = $1
      lid = SecureRandom.uuid
      n1 = Node.new(0,lid,:parallelGateway,'parallel_join',0,0)
      start, list = parallel_joins.pop
      list.each do |e|
        graph.add_link Link.new(e.id,lid,nil)
      end #}}}
    elsif line =~ /^\s*(\{.*\})\s-\s(\d+)/ #{{{
      pj = parallel_joins.last
      pid = $2
      j = JSON::parse($1.gsub(/'/,'"'))
      lid = SecureRandom.uuid
      n1 = Node.new(0,lid,:task,j.dig('name'),0,0)
      graph.add_node n1
      if pj.nil? || pj[1].has_key?(pid)
        graph.add_link Link.new(last.id,lid,cond.nil? ? nil : cond)
      else
        graph.add_link Link.new(pj[0].id,lid,cond.nil? ? nil : cond)
      end
      cond = nil
      last = n1
      pj[1][pid] = n1 if pj
    end #}}}
  end
end