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

Function diagnose_task_file_issues

RealChart2Code_eval/evaluate_task3.py:144–201  ·  view source on GitHub ↗
(task_file: Path)

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 1

find_data_filesFunction · 0.70

Tested by

no test coverage detected