BenjiELCA commited on
Commit
fbe29b3
·
1 Parent(s): 51efe27

vizi handle mix path

Browse files
Files changed (2) hide show
  1. modules/dataset_loader.py +1 -1
  2. modules/toWizard.py +89 -13
modules/dataset_loader.py CHANGED
@@ -285,7 +285,7 @@ def resize_and_pad(image, target, new_size=(1333, 800)):
285
  pad_bottom = new_size[1] - new_scaled_size[1] - pad_top
286
 
287
  # Pad the resized image to make it exactly the desired size
288
- image = F.pad(image, (pad_left, pad_top, pad_right, pad_bottom), fill=0, padding_mode='constant')
289
 
290
  # Adjust bounding boxes
291
  target['boxes'] = resize_boxes(target['boxes'], original_size, new_scaled_size)
 
285
  pad_bottom = new_size[1] - new_scaled_size[1] - pad_top
286
 
287
  # Pad the resized image to make it exactly the desired size
288
+ image = F.pad(image, (pad_left, pad_top, pad_right, pad_bottom), fill=250, padding_mode='constant')
289
 
290
  # Adjust bounding boxes
291
  target['boxes'] = resize_boxes(target['boxes'], original_size, new_scaled_size)
modules/toWizard.py CHANGED
@@ -46,12 +46,13 @@ def create_BPMN_id(data):
46
 
47
  return data
48
 
49
- def check_end(val):
50
- if val[1] is None:
51
  return True
52
  return False
53
 
54
  def connect(data, text_mapping, i):
 
55
  target_idx = data['links'][i][1]
56
  # Check if the target index is valid
57
  if target_idx==None or target_idx >= len(data['links']):
@@ -61,7 +62,12 @@ def connect(data, text_mapping, i):
61
  current_id = data['BPMN_id'][i]
62
  next_idx = data['links'][target_idx][1]
63
  next_id = data['BPMN_id'][next_idx]
64
- next_text = text_mapping[next_id]
 
 
 
 
 
65
  current_text = text_mapping[current_id]
66
 
67
  return current_text, next_text
@@ -71,7 +77,44 @@ def check_start(val):
71
  return True
72
  return False
73
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
74
 
 
 
 
 
 
 
 
 
 
75
 
76
  def create_wizard_file(data, text_mapping):
77
  root = ET.Element('methodAndStyleWizard')
@@ -94,24 +137,28 @@ def create_wizard_file(data, text_mapping):
94
  for idx, Bpmn_id in enumerate(data['BPMN_id']):
95
  # Start Event
96
  element_type = Bpmn_id.split('_')[0]
97
- if element_type == 'message':
98
  eventType = 'Message'
99
  elif element_type == 'event':
100
  eventType = 'None'
101
  if idx >= len(data['links']):
102
  continue
103
- if check_start(data['links'][idx]) and (element_type=='event' or element_type=='message'):
104
  startEvent = ET.SubElement(root, 'startEvent', attrib={'name': text_mapping[Bpmn_id], 'eventType': eventType})
105
 
106
  requestMessage = ET.SubElement(root, 'requestMessage')
107
  requester = ET.SubElement(root, 'requester')
108
 
109
  endEvents = ET.SubElement(root, 'endStates')
 
 
 
 
110
  for idx, Bpmn_id in enumerate(data['BPMN_id']):
111
  # End States
112
  if idx >= len(data['links']):
113
  continue
114
- if check_end(data['links'][idx]) and Bpmn_id.split('_')[0] == 'event':
115
  if text_mapping[Bpmn_id] == '':
116
  text_mapping[Bpmn_id] = '(unnamed)'
117
  ET.SubElement(endEvents, 'endState', attrib={'name': text_mapping[Bpmn_id], 'eventType': 'None', 'isRegular': 'False'})
@@ -125,27 +172,56 @@ def create_wizard_file(data, text_mapping):
125
  activity = ET.SubElement(activities, 'activity', attrib={'name': text_mapping.get(activity_name, activity_name), 'performer': ''})
126
  endStates = ET.SubElement(activity, 'endStates')
127
  current_text, next_text = connect(data, text_mapping, idx)
128
- if next_text is not None:
129
- ET.SubElement(endStates, 'endState', attrib={'name': next_text, 'isRegular': 'True'})
130
  ET.SubElement(activity, 'subActivities')
131
  ET.SubElement(activity, 'subActivityFlows')
132
  ET.SubElement(activity, 'messageFlows')
 
 
 
 
 
133
 
134
- """activityFlows = ET.SubElement(root, 'activityFlows')
135
  i=0
136
  for i, link in enumerate(data['links']):
137
- if link[0] is None and link[1] is not None and (data['BPMN_id'][i].split('_')[0] == 'event' or data['BPMN_id'][i].split('_')[0] == 'message'):
 
138
  current_text, next_text = connect(data, text_mapping, i)
 
 
139
  if current_text is None or next_text is None:
140
  continue
141
- ET.SubElement(activityFlows, 'activityFlow', attrib={'startEvent': current_text, 'endState': '---', 'target': next_text, 'isMerging': 'False', 'isPredefined': 'True'})
142
  i+=1
 
143
  if link[0] is not None and link[1] is not None and data['BPMN_id'][i].split('_')[0] == 'task':
144
  current_text, next_text = connect(data, text_mapping, i)
145
  if current_text is None or next_text is None:
146
  continue
147
- ET.SubElement(activityFlows, 'activityFlow', attrib={'activity': current_text, 'endState': '---', 'target': next_text, 'isMerging': 'False', 'isPredefined': 'True'})
148
- i+=1"""
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
149
 
150
  ET.SubElement(root, 'participants')
151
 
 
46
 
47
  return data
48
 
49
+ def check_end(link):
50
+ if link[1] is None:
51
  return True
52
  return False
53
 
54
  def connect(data, text_mapping, i):
55
+ next_text = []
56
  target_idx = data['links'][i][1]
57
  # Check if the target index is valid
58
  if target_idx==None or target_idx >= len(data['links']):
 
62
  current_id = data['BPMN_id'][i]
63
  next_idx = data['links'][target_idx][1]
64
  next_id = data['BPMN_id'][next_idx]
65
+ if next_id.split('_')[0] == 'parallelGateway':
66
+ for idx, link in enumerate(data['links']):
67
+ if link[0] == next_idx and link[1] is not None:
68
+ next_text.append(text_mapping[data['BPMN_id'][link[1]]])
69
+ else:
70
+ next_text.append(text_mapping[next_id])
71
  current_text = text_mapping[current_id]
72
 
73
  return current_text, next_text
 
77
  return True
78
  return False
79
 
80
+ def find_merge(bpmn_id, links):
81
+ merge = []
82
+ for idx, link in enumerate(links):
83
+ next_element = link[1]
84
+ if next_element is None:
85
+ merge.append(None)
86
+ continue
87
+ next_object = links[next_element][1]
88
+ if next_object is None:
89
+ merge.append(None)
90
+ continue
91
+ if bpmn_id[next_object].split('_')[0] == 'parallelGateway':
92
+ merge.append(bpmn_id[next_object])
93
+ else:
94
+ merge.append(None)
95
+ merge_elements = merge.copy()
96
+ for idx, element in enumerate(merge):
97
+ if element is None:
98
+ merge_elements[idx] = False
99
+ continue
100
+ #count how many time the element is in the list
101
+ count = merge.count(element)
102
+ if count > 1:
103
+ merge_elements[idx] = True
104
+ else:
105
+ merge_elements[idx] = False
106
+
107
+ return merge_elements
108
 
109
+ def find_end_states(data):
110
+ end_states = {}
111
+ bpmn_id = data['BPMN_id']
112
+ for idx, link in enumerate(data['links']):
113
+ if link[0] is None:
114
+ continue
115
+ if bpmn_id[link[0]].split('_')[0] == 'exclusiveGateway':
116
+ end_states[bpmn_id[idx]] = 'state_'+str(idx)
117
+ return end_states
118
 
119
  def create_wizard_file(data, text_mapping):
120
  root = ET.Element('methodAndStyleWizard')
 
137
  for idx, Bpmn_id in enumerate(data['BPMN_id']):
138
  # Start Event
139
  element_type = Bpmn_id.split('_')[0]
140
+ if element_type == 'messageEvent':
141
  eventType = 'Message'
142
  elif element_type == 'event':
143
  eventType = 'None'
144
  if idx >= len(data['links']):
145
  continue
146
+ if check_start(data['links'][idx]) and (element_type=='event' or element_type=='messageEvent'):
147
  startEvent = ET.SubElement(root, 'startEvent', attrib={'name': text_mapping[Bpmn_id], 'eventType': eventType})
148
 
149
  requestMessage = ET.SubElement(root, 'requestMessage')
150
  requester = ET.SubElement(root, 'requester')
151
 
152
  endEvents = ET.SubElement(root, 'endStates')
153
+
154
+ print('mapping: ', text_mapping)
155
+
156
+ # Add end states event to the collaboration element
157
  for idx, Bpmn_id in enumerate(data['BPMN_id']):
158
  # End States
159
  if idx >= len(data['links']):
160
  continue
161
+ if check_end(data['links'][idx]) and (Bpmn_id.split('_')[0] == 'event' or Bpmn_id.split('_')[0] == 'messageEvent'):
162
  if text_mapping[Bpmn_id] == '':
163
  text_mapping[Bpmn_id] = '(unnamed)'
164
  ET.SubElement(endEvents, 'endState', attrib={'name': text_mapping[Bpmn_id], 'eventType': 'None', 'isRegular': 'False'})
 
172
  activity = ET.SubElement(activities, 'activity', attrib={'name': text_mapping.get(activity_name, activity_name), 'performer': ''})
173
  endStates = ET.SubElement(activity, 'endStates')
174
  current_text, next_text = connect(data, text_mapping, idx)
175
+ if next_text is not None and len(next_text) == 1:
176
+ ET.SubElement(endStates, 'endState', attrib={'name': next_text[0], 'isRegular': 'True'})
177
  ET.SubElement(activity, 'subActivities')
178
  ET.SubElement(activity, 'subActivityFlows')
179
  ET.SubElement(activity, 'messageFlows')
180
+
181
+ endStates_text = find_end_states(data)
182
+ #print(endStates_text)
183
+
184
+ merge_object = find_merge(data['BPMN_id'], data['links'])
185
 
186
+ activityFlows = ET.SubElement(root, 'activityFlows')
187
  i=0
188
  for i, link in enumerate(data['links']):
189
+ # create flow with start event
190
+ if link[0] is None and link[1] is not None and (data['BPMN_id'][i].split('_')[0] == 'event' or data['BPMN_id'][i].split('_')[0] == 'messageEvent'):
191
  current_text, next_text = connect(data, text_mapping, i)
192
+ print('current_text: ', current_text)
193
+ print('next_text: ', next_text)
194
  if current_text is None or next_text is None:
195
  continue
196
+ ET.SubElement(activityFlows, 'activityFlow', attrib={'startEvent': current_text, 'endState': '---', 'target': next_text[0], 'isMerging': 'False', 'isPredefined': 'True'})
197
  i+=1
198
+ # create flow with tasks
199
  if link[0] is not None and link[1] is not None and data['BPMN_id'][i].split('_')[0] == 'task':
200
  current_text, next_text = connect(data, text_mapping, i)
201
  if current_text is None or next_text is None:
202
  continue
203
+
204
+ if merge_object[i] == True:
205
+ merge = 'True'
206
+ else:
207
+ merge = 'False'
208
+
209
+ if len(next_text) > 1:
210
+ for next in next_text:
211
+ ET.SubElement(activityFlows, 'activityFlow', attrib={'activity': current_text, 'endState': '---', 'target': next, 'isMerging': merge, 'isPredefined': 'True'})
212
+ elif len(next_text) == 1:
213
+ ET.SubElement(activityFlows, 'activityFlow', attrib={'activity': current_text, 'endState': '---', 'target': next_text[0], 'isMerging': merge, 'isPredefined': 'True'})
214
+ else:
215
+ ET.SubElement(activityFlows, 'activityFlow', attrib={'activity': current_text, 'endState': '---', 'target': next_text, 'isMerging': merge, 'isPredefined': 'True'})
216
+
217
+
218
+
219
+ """if data['BPMN_id'][i] in endStates_text:
220
+ endState = endStates_text[data['BPMN_id'][i]]
221
+ else:
222
+ endState = '---'"""
223
+
224
+ i+=1
225
 
226
  ET.SubElement(root, 'participants')
227