保存元数据JSON
(self, context: ProcessingContext, output_path: str)
| 999 | self._log(f"可视化已保存: {output_path}") |
| 1000 | |
| 1001 | def save_metadata(self, context: ProcessingContext, output_path: str): |
| 1002 | """保存元数据JSON""" |
| 1003 | import json |
| 1004 | |
| 1005 | metadata = { |
| 1006 | 'image_path': context.image_path, |
| 1007 | 'image_size': { |
| 1008 | 'width': context.canvas_width, |
| 1009 | 'height': context.canvas_height |
| 1010 | }, |
| 1011 | 'total_elements': len(context.elements), |
| 1012 | 'by_group': {}, |
| 1013 | 'by_type': {}, |
| 1014 | 'elements': [] |
| 1015 | } |
| 1016 | |
| 1017 | for elem in context.elements: |
| 1018 | group = getattr(elem, '_source_group', 'unknown') |
| 1019 | if group not in metadata['by_group']: |
| 1020 | metadata['by_group'][group] = [] |
| 1021 | |
| 1022 | elem_type = elem.element_type |
| 1023 | if elem_type not in metadata['by_type']: |
| 1024 | metadata['by_type'][elem_type] = [] |
| 1025 | |
| 1026 | elem_data = elem.to_dict() |
| 1027 | elem_data['source_group'] = group |
| 1028 | |
| 1029 | metadata['by_group'][group].append(elem_data) |
| 1030 | metadata['by_type'][elem_type].append(elem_data) |
| 1031 | metadata['elements'].append(elem_data) |
| 1032 | |
| 1033 | with open(output_path, 'w', encoding='utf-8') as f: |
| 1034 | json.dump(metadata, f, indent=2, ensure_ascii=False) |
| 1035 | self._log(f"Metadata saved: {output_path}") |
| 1036 | |
| 1037 | def get_all_prompts(self) -> Dict[str, List[str]]: |
| 1038 | """Return all prompt groups.""" |
no test coverage detected