MCPcopy Create free account
hub / github.com/Speakn0w/RealChart2Code / diagnose_task_file_issues

Function diagnose_task_file_issues

RealChart2Code_eval/evaluate_task2.py:137–194  ·  view source on GitHub ↗
(task_file: Path)

Source from the content-addressed store, hash-verified

135
136
137def diagnose_task_file_issues(task_file: Path) -> Dict[str, any]:
138
139 diagnosis = {
140 'task_file': str(task_file),
141 'exists': task_file.exists(),
142 'readable': False,
143 'has_category': False,
144 'has_instruction': False,
145 'has_files': False,
146 'data_filenames': [],
147 'data_directory': str(task_file.parent),
148 'found_data_files': {},
149 'missing_data_files': [],
150 'errors': []
151 }
152
153 try:
154 if not task_file.exists():
155 diagnosis['errors'].append("task file does not exist")
156 return diagnosis
157
158
159 with open(task_file, 'r', encoding='utf-8') as f:
160 content = f.read()
161 diagnosis['readable'] = True
162
163
164 category_match = re.search(r'## Category\s*\n(.+)', content)
165 if category_match:
166 diagnosis['has_category'] = True
167
168 instruction_match = re.search(r'## Instruction\s*\n(.+?)(?=\n##|\n---|$)', content, re.DOTALL)
169 if instruction_match and instruction_match.group(1).strip():
170 diagnosis['has_instruction'] = True
171
172 files_match = re.search(r'## Files\s*\n(.+?)(?=\n##|\n---|$)', content, re.DOTALL)
173 if files_match:
174 files_text = files_match.group(1).strip()
175 if files_text:
176 diagnosis['has_files'] = True
177 data_files = []
178 for f in files_text.split('\n'):
179 f = f.strip()
180 if f and (f.endswith('.csv') or f.endswith('.xlsx')):
181 data_files.append(f)
182 diagnosis['data_filenames'] = data_files
183
184
185 if diagnosis['data_filenames']:
186 data_directory = task_file.parent
187 found_files = find_data_files(data_directory, diagnosis['data_filenames'])
188 diagnosis['found_data_files'] = {k: str(v) for k, v in found_files.items()}
189 diagnosis['missing_data_files'] = list(set(diagnosis['data_filenames']) - set(found_files.keys()))
190
191 except Exception as e:
192 diagnosis['errors'].append(f"error reading file: {str(e)}")
193
194 return diagnosis

Callers

nothing calls this directly

Calls 1

find_data_filesFunction · 0.70

Tested by

no test coverage detected