@@ -120,22 +120,70 @@ def feature_by_nodes_and_links features_report
120120 def nodes_and_links feature_report , feature_name
121121 last_node_id = 0
122122 nodes = [ { name : "" , id : "empty" , image : nil } ]
123+ signal_hash = { }
123124 links = [ ]
124125 feature_report . keys . each do |key |
125126 steps = feature_report [ key ]
127+ coming_from_signal = false
128+ last_signal = -1
126129 steps . each_with_index do |step , index |
127130 node_id = last_node_id +1
128- node = { name : step [ :name ] , id : "#{ node_id } " , image : step [ :image ] , status : step [ :status ] }
129- link = {
130- source : ( index == 0 ? 0 : last_node_id ) ,
131- target : node_id ,
132- value : 1 ,
133- owner : key ,
134- owner_model : step [ :device_model ]
135- }
136- nodes << node
137- links << link
138- last_node_id += 1
131+ if isReadSignal ( step [ :name ] ) && step [ :status ] == PASSED
132+ signal = signalContent ( step [ :name ] )
133+ already_created_signal = signal_hash [ signal ] ? true : false
134+ signal_hash [ signal ] = already_created_signal ? signal_hash [ signal ] : { id : "#{ node_id } " , receiver : key }
135+ node = { name : "Signal: #{ signal } , Receiver: #{ step [ :device_model ] } " , id : signal_hash [ signal ] [ :id ] , image : nil , status : step [ :status ] }
136+ if already_created_signal
137+ entry = nodes . select { |node | node [ :id ] == signal_hash [ signal ] [ :id ] } . first
138+ entry [ :name ] = "Signal: #{ signal } , Receiver: #{ step [ :device_model ] } " if entry
139+ end
140+ source = ( coming_from_signal ? last_signal : ( index == 0 ? 0 : last_node_id ) )
141+ link = {
142+ source : source ,
143+ target : signal_hash [ signal ] [ :id ] . to_i ,
144+ value : 1 ,
145+ owner : key ,
146+ owner_model : step [ :device_model ]
147+ }
148+ nodes << node if !already_created_signal
149+ links << link
150+ last_node_id += 1 if !already_created_signal
151+ last_signal = signal_hash [ signal ] [ :id ] . to_i
152+ coming_from_signal = true
153+ elsif isWriteSignal ( step [ :name ] ) && step [ :status ] == PASSED
154+ signal = signalContent ( step [ :name ] )
155+ receiver = signalReceiver ( step [ :name ] )
156+ already_created_signal = signal_hash [ signal ] ? true : false
157+ signal_hash [ signal ] = already_created_signal ? signal_hash [ signal ] : { id : "#{ node_id } " , receiver : receiver }
158+ node = { name : step [ :name ] , id : signal_hash [ signal ] [ :id ] , image : nil , status : step [ :status ] }
159+ source = ( coming_from_signal ? last_signal : ( index == 0 ? 0 : last_node_id ) )
160+ link = {
161+ source : source ,
162+ target : signal_hash [ signal ] [ :id ] . to_i ,
163+ value : 1 ,
164+ owner : key ,
165+ owner_model : step [ :device_model ]
166+ }
167+ nodes << node if !already_created_signal
168+ links << link
169+ last_node_id += 1 if !already_created_signal
170+ last_signal = signal_hash [ signal ] [ :id ] . to_i
171+ coming_from_signal = true
172+ else
173+ node = { name : step [ :name ] , id : "#{ node_id } " , image : step [ :image ] , status : step [ :status ] }
174+ source = ( coming_from_signal ? last_signal : ( index == 0 ? 0 : last_node_id ) )
175+ link = {
176+ source : source ,
177+ target : node_id ,
178+ value : 1 ,
179+ owner : key ,
180+ owner_model : step [ :device_model ]
181+ }
182+ nodes << node
183+ links << link
184+ last_node_id += 1
185+ coming_from_signal = false
186+ end
139187 end
140188 end
141189 return {
@@ -145,6 +193,26 @@ def nodes_and_links feature_report, feature_name
145193 }
146194 end
147195
196+ def isReadSignal step
197+ line = step . split ( ' ' ) [ 1 ..-1 ] . join ( ' ' )
198+ ( line =~ /^I wait for a signal containing "([^\" ]*)"$/ ? true : false ) || ( line =~ /^I wait for a signal containing "([^\" ]*)" for (\d +) seconds$/ ? true : false )
199+ end
200+
201+ def isWriteSignal step
202+ line = step . split ( ' ' ) [ 1 ..-1 ] . join ( ' ' )
203+ line =~ /^I send a signal to user (\d +) containing "([^\" ]*)"$/ ? true : false
204+ end
205+
206+ def signalContent step
207+ line = step . split ( ' ' ) [ 1 ..-1 ] . join ( ' ' )
208+ line . scan ( /"([^\" ]*)"/ ) . first . first if line . scan ( /"([^\" ]*)"/ ) . first
209+ end
210+
211+ def signalReceiver step
212+ line = step . split ( ' ' ) [ 1 ..-1 ] . join ( ' ' )
213+ line . scan ( /(\d +)/ ) . first . first if line . scan ( /(\d +)/ ) . first
214+ end
215+
148216 def generate_features_report features , device
149217 features . each do |feature |
150218 generate_feature_report feature , device
0 commit comments