rosemariafontana commited on
Commit
dc2d686
·
verified ·
1 Parent(s): 1c50651

Update script_for_automation.py

Browse files
Files changed (1) hide show
  1. script_for_automation.py +10 -1
script_for_automation.py CHANGED
@@ -341,6 +341,15 @@ def format_json(json_data, truncate_length=500):
341
  # If it's not valid JSON, return the string as it is
342
  return json_data[:truncate_length] + "..." if len(json_data) > truncate_length else json_data
343
 
 
 
 
 
 
 
 
 
 
344
 
345
  def sanitize_json_for_yaml(data):
346
  if isinstance(data, dict):
@@ -416,7 +425,7 @@ def generate_markdown_output(df):
416
  markdown += f"\n### Recipe ID: {row['Recipe_ID']}\n"
417
  for key in ["planting", "interactions", "trials"]:
418
  gold = json.dumps(row['Gold_Standard_JSON'].get(key, {}), indent=2)
419
- machine = json.dumps(row['Machine_Generated_JSON'].get(key, {}), indent=2)
420
  markdown += f"#### {key.capitalize()}\n"
421
  markdown += f"**Gold Standard JSON**:\n```json\n{gold}\n```\n"
422
  markdown += f"**Machine Generated JSON**:\n```json\n{machine}\n```\n"
 
341
  # If it's not valid JSON, return the string as it is
342
  return json_data[:truncate_length] + "..." if len(json_data) > truncate_length else json_data
343
 
344
+ # Custom method to handle all objects
345
+ def custom_serializer(obj):
346
+ if isinstance(obj, Enum):
347
+ return obj.name # Or obj.value, depending on what you need
348
+ if isinstance(obj, Soil):
349
+ return obj.to_dict()
350
+ if isinstance(obj, Yield):
351
+ return obj.to_dict()
352
+ return obj.__dict__ # Default case: use the __dict__ method for other custom objects
353
 
354
  def sanitize_json_for_yaml(data):
355
  if isinstance(data, dict):
 
425
  markdown += f"\n### Recipe ID: {row['Recipe_ID']}\n"
426
  for key in ["planting", "interactions", "trials"]:
427
  gold = json.dumps(row['Gold_Standard_JSON'].get(key, {}), indent=2)
428
+ machine = json.dumps(row['Machine_Generated_JSON'].get(key, {}), default=custom_serializer, indent=2)
429
  markdown += f"#### {key.capitalize()}\n"
430
  markdown += f"**Gold Standard JSON**:\n```json\n{gold}\n```\n"
431
  markdown += f"**Machine Generated JSON**:\n```json\n{machine}\n```\n"