rosemariafontana commited on
Commit
75acc99
·
verified ·
1 Parent(s): 1b9c64b

Update script_for_automation.py

Browse files
Files changed (1) hide show
  1. script_for_automation.py +35 -10
script_for_automation.py CHANGED
@@ -3,6 +3,9 @@ from jsondiff import diff
3
  import yaml
4
  import pandas as pd
5
  import os
 
 
 
6
 
7
  # The purpose of this script is to automate running a bunch of tests
8
  # This script will take an input folder
@@ -382,9 +385,8 @@ def drive_process():
382
  # },
383
 
384
  output_rows = []
385
- output_folder = "output_files"
386
- if not os.path.exists(output_folder)
387
- os.makedirs(output_folder)
388
 
389
  for recipe_dict in my_recipes:
390
  for key, input_chunks in input_data.items():
@@ -437,13 +439,36 @@ def drive_process():
437
  df = pd.DataFrame(output_rows)
438
 
439
  markdown_output = generate_markdown_output(df)
440
- output_file = f"/output/recipe_run_{recipe_id}_{key}.md"
441
- output_file_path = os.path.join(output_folder, output_file_name)
442
-
443
- with open(output_file_path, "w") as file:
444
- file.write(markdown_output)
445
-
446
- print(f"Markdown file saved at {output_file_path}")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
447
 
448
  return output_folder
449
 
 
3
  import yaml
4
  import pandas as pd
5
  import os
6
+ import shutil
7
+ import json
8
+ from datetime import datetime
9
 
10
  # The purpose of this script is to automate running a bunch of tests
11
  # This script will take an input folder
 
385
  # },
386
 
387
  output_rows = []
388
+ output_folder = "output_results_" +datetime.now().strftime("%Y%m%d_%H%M%S")
389
+ os.makedirs(output_folder, exist_ok=True)
 
390
 
391
  for recipe_dict in my_recipes:
392
  for key, input_chunks in input_data.items():
 
439
  df = pd.DataFrame(output_rows)
440
 
441
  markdown_output = generate_markdown_output(df)
442
+ recipe_folder = os.path.join(output_folder, f"recipe_{recipe_dict['recipe_id']}")
443
+ os.makedirs(recipe_folder, exist_ok=True)
444
+
445
+ # Save markdown to file
446
+ markdown_file = os.path.join(recipe_folder, f"recipe_{recipe_dict['recipe_id']}_data_{key}_output.md")
447
+ with open(markdown_file, 'w') as f:
448
+ f.write(markdown_output)
449
+
450
+ # Save JSON files
451
+ json_file_gold = os.path.join(recipe_folder, f"recipe_{recipe_dict['recipe_id']}_data_{key}_gold_standard.json")
452
+ json_file_generated = os.path.join(recipe_folder, f"recipe_{recipe_dict['recipe_id']}_data_{key}_generated.json")
453
+ with open(json_file_gold, 'w') as f:
454
+ json.dump(gold_standard_json, f, indent=2)
455
+ with open(json_file_generated, 'w') as f:
456
+ json.dump(completed_json, f, indent=2)
457
+
458
+ # Optionally save differences as a separate file
459
+ differences_file = os.path.join(recipe_folder, f"recipe_{recipe_dict['recipe_id']}_data_{key}_differences.json")
460
+ with open(differences_file, 'w') as f:
461
+ json.dump(differences, f, indent=2)
462
+
463
+ # Zip the entire output folder
464
+ zip_filename = f"{output_folder}.zip"
465
+ shutil.make_archive(output_folder, 'zip', output_folder)
466
+
467
+ # Cleanup by removing the unzipped folder after zipping it
468
+ shutil.rmtree(output_folder)
469
+
470
+ # Return the zip file for downloading
471
+ return zip_filename
472
 
473
  return output_folder
474