baakaani commited on
Commit
6b51487
·
1 Parent(s): e571083

changes to dashboard

Browse files
Files changed (1) hide show
  1. utils/config_fabric.py +58 -32
utils/config_fabric.py CHANGED
@@ -274,20 +274,31 @@ def set_generator_experiments(generator_params):
274
 
275
  if __name__ == '__main__':
276
  play_header()
 
 
277
  config_layout = json.load(open("config_files/config_layout.json"))
278
- type(config_layout)
279
- step_candidates = ["instance_augmentation","event_logs_generation","feature_extraction","benchmark_test"]
 
 
 
280
  pipeline_steps = st.multiselect(
281
  "Choose pipeline step",
282
  step_candidates,
283
  ["event_logs_generation"]
284
  )
 
285
  step_configs = []
286
  set_col, view_col = st.columns([3, 2])
 
 
287
  for pipeline_step in pipeline_steps:
288
- step_config = [d for d in config_layout if d['pipeline_step'] == pipeline_step][0]
 
289
  with set_col:
290
  st.header(pipeline_step)
 
 
291
  for step_key in step_config.keys():
292
  if step_key == "generator_params":
293
  st.subheader("Set-up experiments")
@@ -295,64 +306,79 @@ if __name__ == '__main__':
295
  elif step_key == "feature_params":
296
  layout_features = list(step_config[step_key]['feature_set'])
297
  step_config[step_key]["feature_set"] = st.multiselect(
298
- "features to extract",
299
- layout_features)
 
300
  elif step_key != "pipeline_step":
301
  step_config[step_key] = st.text_input(step_key, step_config[step_key])
 
302
  with view_col:
303
  st.write(step_config)
 
304
  step_configs.append(step_config)
 
 
305
  config_file = json.dumps(step_configs, indent=4)
 
 
306
  output_path = st.text_input("Output file path", "config_files/experiment_config.json")
 
 
307
  os.makedirs(os.path.dirname(output_path), exist_ok=True)
 
 
308
  save_labels = ["Save config file", "Save and run config_file"]
309
- #save_labels = ["Save configuration file"]
310
  create_button, create_run_button = multi_button(save_labels)
311
- #create_button = multi_button(save_labels)
312
 
313
  if create_button or create_run_button:
 
314
  with open(output_path, "w") as f:
315
  f.write(config_file)
 
316
  st.write("Saved configuration in ", output_path, ". Run command:")
317
- create_button = False
318
  var = f"python -W ignore main.py -a {output_path}"
319
  st.code(var, language='bash')
320
 
321
  if create_run_button:
 
322
  command = var.split()
323
- progress_bar = st.progress(0) # Initialize the progress bar
324
-
 
325
  directory = Path(step_config['output_path']).parts
326
  path = os.path.join(directory[0], 'features', *directory[1:])
327
- if os.path.exists(path): shutil.rmtree(path)
328
 
329
- # Simulate running the command with a loop and updating the progress bar
 
 
 
 
330
  for i in range(95):
331
- time.sleep(0.2) # Simulate the time taken for each step
332
  progress_bar.progress(i + 1)
333
 
334
  # Run the actual command
335
  result = subprocess.run(command, capture_output=True, text=True)
 
336
  st.write("## Results")
337
- # st.write(*step_config['generator_params']['experiment'][0].keys(), "log name", "target similarity")
338
 
339
- directory = Path(step_config['output_path']).parts
340
- path = os.path.join(directory[0], 'features', *directory[1:])
 
 
 
 
 
 
 
 
 
 
 
 
341
 
342
- dataframes = []
343
- # Walk through all directories and files
344
- for root, dirs, files in os.walk(path):
345
- feature_files = [os.path.join(root, file) for file in files]
346
- for feature_file in feature_files:
347
-
348
- df_temp = pd.read_json(feature_file,lines=True)
349
- dataframes.append(df_temp)
350
- # Print the contents of the JSON file
351
- # st.write(*config_targets.values(), data['log'], data['target_similarity'])
352
- dataframes = pd.concat(dataframes, ignore_index=True)
353
- # dataframes = dataframes.sort_values(by=['log'])
354
- dataframes = dataframes.set_index('log')
355
- col1, col2 = st.columns([2, 3]) # Adjust the ratio as needed
356
 
357
  with col1:
358
  st.dataframe(dataframes)
@@ -366,5 +392,5 @@ if __name__ == '__main__':
366
  plt.tight_layout()
367
  st.pyplot(plt)
368
 
369
- # Optional: Updating the progress bar to indicate completion
370
- progress_bar.progress(100)
 
274
 
275
  if __name__ == '__main__':
276
  play_header()
277
+
278
+ # Load the configuration layout from a JSON file
279
  config_layout = json.load(open("config_files/config_layout.json"))
280
+
281
+ # Define available pipeline steps
282
+ step_candidates = ["instance_augmentation", "event_logs_generation", "feature_extraction", "benchmark_test"]
283
+
284
+ # Streamlit multi-select for pipeline steps
285
  pipeline_steps = st.multiselect(
286
  "Choose pipeline step",
287
  step_candidates,
288
  ["event_logs_generation"]
289
  )
290
+
291
  step_configs = []
292
  set_col, view_col = st.columns([3, 2])
293
+
294
+ # Iterate through selected pipeline steps
295
  for pipeline_step in pipeline_steps:
296
+ step_config = next(d for d in config_layout if d['pipeline_step'] == pipeline_step)
297
+
298
  with set_col:
299
  st.header(pipeline_step)
300
+
301
+ # Iterate through step configuration keys
302
  for step_key in step_config.keys():
303
  if step_key == "generator_params":
304
  st.subheader("Set-up experiments")
 
306
  elif step_key == "feature_params":
307
  layout_features = list(step_config[step_key]['feature_set'])
308
  step_config[step_key]["feature_set"] = st.multiselect(
309
+ "features to extract",
310
+ layout_features
311
+ )
312
  elif step_key != "pipeline_step":
313
  step_config[step_key] = st.text_input(step_key, step_config[step_key])
314
+
315
  with view_col:
316
  st.write(step_config)
317
+
318
  step_configs.append(step_config)
319
+
320
+ # Convert step configurations to JSON
321
  config_file = json.dumps(step_configs, indent=4)
322
+
323
+ # Streamlit input for output file path
324
  output_path = st.text_input("Output file path", "config_files/experiment_config.json")
325
+
326
+ # Ensure output directory exists
327
  os.makedirs(os.path.dirname(output_path), exist_ok=True)
328
+
329
+ # Streamlit multi-button for saving options
330
  save_labels = ["Save config file", "Save and run config_file"]
 
331
  create_button, create_run_button = multi_button(save_labels)
 
332
 
333
  if create_button or create_run_button:
334
+ # Save configuration to the specified output path
335
  with open(output_path, "w") as f:
336
  f.write(config_file)
337
+
338
  st.write("Saved configuration in ", output_path, ". Run command:")
339
+
340
  var = f"python -W ignore main.py -a {output_path}"
341
  st.code(var, language='bash')
342
 
343
  if create_run_button:
344
+ # Split the command for subprocess
345
  command = var.split()
346
+ progress_bar = st.progress(0)
347
+
348
+ # Prepare output path for feature extraction
349
  directory = Path(step_config['output_path']).parts
350
  path = os.path.join(directory[0], 'features', *directory[1:])
 
351
 
352
+ # Clean existing output path if it exists
353
+ if os.path.exists(path):
354
+ shutil.rmtree(path)
355
+
356
+ # Simulate running the command with a loop and update progress
357
  for i in range(95):
358
+ time.sleep(0.2)
359
  progress_bar.progress(i + 1)
360
 
361
  # Run the actual command
362
  result = subprocess.run(command, capture_output=True, text=True)
363
+
364
  st.write("## Results")
 
365
 
366
+ # Collect all file paths from the output directory
367
+ file_paths = [os.path.join(root, file)
368
+ for root, _, files in os.walk(path)
369
+ for file in files]
370
+
371
+ # Read and concatenate all JSON files into a DataFrame
372
+ dataframes = pd.concat([pd.read_json(file, lines=True) for file in file_paths], ignore_index=True)
373
+
374
+ # Reorder columns with 'target_similarity' as the last column
375
+ columns = [col for col in dataframes.columns if col != 'target_similarity'] + ['target_similarity']
376
+ dataframes = dataframes[columns]
377
+
378
+ # Set 'log' as the index
379
+ dataframes.set_index('log', inplace=True)
380
 
381
+ col1, col2 = st.columns([2, 3])
 
 
 
 
 
 
 
 
 
 
 
 
 
382
 
383
  with col1:
384
  st.dataframe(dataframes)
 
392
  plt.tight_layout()
393
  st.pyplot(plt)
394
 
395
+ # Update progress bar to indicate completion
396
+ progress_bar.progress(100)