Buckets:
| from argparse import ArgumentParser | |
| import os | |
| import json | |
| from pathlib import Path | |
| import sys | |
| from typing import Dict, List, Tuple | |
| import configs.token_key_session as configs | |
| # Import Notion utility functions | |
| from notion_client import Client | |
| from utils.evaluation.retry import grade_with_retry | |
| def extract_task_information_from_database(database_entries: List[Dict]) -> List[Dict]: | |
| """Extract task information from Notion database entries""" | |
| tasks = [] | |
| for entry in database_entries: | |
| task_info = { | |
| 'Task Name': '', | |
| 'Task Status': '', | |
| 'Implementor': '' | |
| } | |
| # Extract properties | |
| properties = entry.get('properties', {}) | |
| for prop_name, prop_data in properties.items(): | |
| prop_type = prop_data.get('type', '') | |
| prop_name_clean = prop_name.strip() | |
| if prop_type == 'title': | |
| # Usually the task name | |
| title_parts = prop_data.get('title', []) | |
| text = ''.join([part.get('text', {}).get('content', '') for part in title_parts]) | |
| text = text.strip() | |
| if prop_name_clean == 'Task Name' or 'task' in prop_name_clean.lower(): | |
| task_info['Task Name'] = text | |
| elif prop_type == 'rich_text': | |
| rich_text = prop_data.get('rich_text', []) | |
| text = ''.join([part.get('text', {}).get('content', '') for part in rich_text]) | |
| text = text.strip() | |
| if prop_name_clean == 'Task Name': | |
| task_info['Task Name'] = text | |
| elif prop_type == 'select': | |
| select_value = prop_data.get('select', {}) | |
| if select_value: | |
| text = select_value.get('name', '').strip() | |
| if prop_name_clean == 'Task Status': | |
| task_info['Task Status'] = text | |
| elif prop_type == 'multi_select': | |
| select_value = prop_data.get('multi_select', {})[0] | |
| if select_value: | |
| text = select_value.get('name', '').strip() | |
| if prop_name_clean == 'Implementor': | |
| task_info['Implementor'] = text | |
| # Only add if we have essential information (at least task name) | |
| if task_info['Task Name']: | |
| tasks.append(task_info) | |
| return tasks | |
| def compare_with_local_excel(notion_tasks: List[Dict], groundtruth_workspace) -> Tuple[bool, List[str]]: | |
| """Compare Notion database with local Excel file""" | |
| try: | |
| import pandas as pd | |
| excel_path = f"{groundtruth_workspace}/notion_table_after.xlsx" | |
| # Read Excel file | |
| df_excel = pd.read_excel(excel_path) | |
| # Convert to list of dictionaries | |
| excel_tasks = df_excel.to_dict('records') | |
| issues = [] | |
| # Check column names | |
| expected_columns = set(df_excel.columns) | |
| if len(notion_tasks) > 0: | |
| notion_columns = set(notion_tasks[0].keys()) | |
| if expected_columns != notion_columns: | |
| issues.append(f"Column mismatch. Expected: {expected_columns}, Got: {notion_columns}") | |
| # Check shape (number of rows) | |
| if len(notion_tasks) != len(excel_tasks): | |
| issues.append(f"Row count mismatch. Expected: {len(excel_tasks)}, Got: {len(notion_tasks)}") | |
| # Create lookup dictionaries for comparison | |
| notion_lookup = {task['Task Name'].strip().lower(): task for task in notion_tasks if task['Task Name']} | |
| excel_lookup = {str(task['Task Name']).strip().lower(): task for task in excel_tasks if pd.notna(task['Task Name'])} | |
| # Check that all Excel rows are found in Notion | |
| for excel_task_name, excel_task in excel_lookup.items(): | |
| if excel_task_name not in notion_lookup: | |
| issues.append(f"Excel task '{excel_task['Task Name']}' not found in Notion database") | |
| continue | |
| notion_task = notion_lookup[excel_task_name] | |
| # Compare each field | |
| for col in expected_columns: | |
| excel_val = str(excel_task.get(col, '')).strip() if pd.notna(excel_task.get(col)) else '' | |
| notion_val = str(notion_task.get(col, '')).strip() | |
| if excel_val != notion_val: | |
| issues.append(f"Task '{excel_task['Task Name']}', column '{col}': Excel='{excel_val}', Notion='{notion_val}'") | |
| # Check for extra tasks in Notion | |
| for notion_task_name in notion_lookup: | |
| if notion_task_name not in excel_lookup: | |
| issues.append(f"Extra task in Notion: '{notion_lookup[notion_task_name]['Task Name']}'") | |
| return len(issues) == 0, issues | |
| except Exception as e: | |
| return False, [f"Error comparing with Excel: {str(e)}"] | |
| def check_notion_database(groundtruth_workspace) -> Tuple[bool, str]: | |
| """Check Notion database in Task Tracker page under Notion Eval Page""" | |
| try: | |
| # Get Notion token | |
| notion_token = configs.all_token_key_session.notion_integration_key | |
| if not notion_token: | |
| return False, "❌ No Notion token provided" | |
| from notion_client import Client | |
| client = Client(auth=notion_token) | |
| # Read Task Tracker page ID from file | |
| script_dir = Path(__file__).parent | |
| page_id_file = script_dir / "../files/duplicated_page_id.txt" | |
| if not page_id_file.exists(): | |
| return False, f"❌ Page ID file not found: {page_id_file}" | |
| task_tracker_page_id = page_id_file.read_text().strip() | |
| print(f"✅ Read Task Tracker page ID from file: {task_tracker_page_id}") | |
| # Look for database in Task Tracker page | |
| print("🔍 Searching for database in Task Tracker page...") | |
| task_tracker_children = client.blocks.children.list(block_id=task_tracker_page_id) | |
| task_database = None | |
| for child in task_tracker_children.get('results', []): | |
| if child.get('type') == 'child_database': | |
| task_database = child | |
| break | |
| if not task_database: | |
| return False, "❌ No database found in Task Tracker page" | |
| database_id = task_database['id'] | |
| print(f"✅ Found database in Task Tracker page (ID: {database_id})") | |
| # Get database entries with pagination | |
| print("📊 Retrieving database entries...") | |
| all_entries = [] | |
| has_more = True | |
| start_cursor = None | |
| page_count = 0 | |
| while has_more: | |
| page_count += 1 | |
| print(f" 📄 Fetching page {page_count}...") | |
| if start_cursor: | |
| database_response = client.databases.query( | |
| database_id=database_id, | |
| start_cursor=start_cursor | |
| ) | |
| else: | |
| database_response = client.databases.query(database_id=database_id) | |
| page_entries = database_response.get('results', []) | |
| all_entries.extend(page_entries) | |
| has_more = database_response.get('has_more', False) | |
| start_cursor = database_response.get('next_cursor') | |
| print(f" 📊 Page {page_count}: {len(page_entries)} entries") | |
| print(f"📈 Total entries retrieved: {len(all_entries)} across {page_count} pages") | |
| entries_list = all_entries | |
| # Extract task information | |
| print("🔍 Extracting task information...") | |
| notion_tasks = extract_task_information_from_database(entries_list) | |
| print(f"✅ Extracted {len(notion_tasks)} tasks from database") | |
| # Debug: Show first few tasks | |
| print("\n=== Sample of Tasks from Notion Database ===") | |
| for i, task in enumerate(notion_tasks[:3]): | |
| print(f"{i+1}. Task Name: '{task['Task Name']}', Task Status: '{task['Task Status']}', Implementor: '{task['Implementor']}'") | |
| # Compare with local Excel | |
| print("\n🔍 Comparing with local Excel file...") | |
| comparison_success, comparison_issues = compare_with_local_excel(notion_tasks, groundtruth_workspace) | |
| if not comparison_success: | |
| error_msg = f"❌ Database comparison failed:\n\n" | |
| error_msg += f"Found {len(notion_tasks)} tasks in Notion database.\n\n" | |
| error_msg += "Issues found:\n" | |
| for issue in comparison_issues[:10]: # Show first 10 issues | |
| error_msg += f" • {issue}\n" | |
| if len(comparison_issues) > 10: | |
| error_msg += f" • ... and {len(comparison_issues) - 10} more issues\n" | |
| return False, error_msg | |
| # Success! | |
| success_msg = f"✅ Notion database validation passed!\n" | |
| success_msg += f" • Found 'Task Tracker' page under 'Notion Eval Page'\n" | |
| success_msg += f" • Database contains {len(notion_tasks)} tasks\n" | |
| success_msg += f" • All columns match Excel file (Task Name, Task Status, Implementor)\n" | |
| success_msg += f" • All rows from Excel found in Notion database\n" | |
| success_msg += f" • No extra or missing tasks detected" | |
| return True, success_msg | |
| except Exception as e: | |
| return False, f"❌ Failed to check Notion database: {str(e)}" | |
| def check_github_finalpool_tasks(groundtruth_workspace) -> Tuple[bool, str]: | |
| """Check GitHub finalpool branch contains only implemented tasks with required files""" | |
| try: | |
| from utils.general.helper import fork_repo, run_command, print_color | |
| from configs.token_key_session import all_token_key_session | |
| from utils.app_specific.github.api import ( | |
| github_get_login, github_delete_repo, | |
| github_create_user_repo, github_get_latest_commit | |
| ) | |
| github_token = all_token_key_session.github_token | |
| # Resolve dynamic namespaces/logins | |
| github_owner = github_get_login(github_token) | |
| github_repo = f"{github_owner}/BenchTasksCollv3" | |
| # Get GitHub token and check the repository | |
| github_token = configs.all_token_key_session.github_token | |
| # Use GitHub API to check the repository | |
| import requests | |
| headers = { | |
| 'Authorization': f'token {github_token}', | |
| 'Accept': 'application/vnd.github.v3+json' | |
| } | |
| # Check if finalpool branch exists | |
| branches_url = f"https://api.github.com/repos/{github_repo}/branches" | |
| response = requests.get(branches_url, headers=headers) | |
| if response.status_code != 200: | |
| return False, f"❌ Failed to get branches from GitHub repository: {response.status_code}" | |
| branches = response.json() | |
| finalpool_branch_exists = any(branch['name'] == 'finalpool' for branch in branches) | |
| if not finalpool_branch_exists: | |
| return False, "❌ 'finalpool' branch does not exist in the repository" | |
| print(f"✅ Found 'finalpool' branch in repository: {github_repo}") | |
| # Check if tasks/finalpool directory exists | |
| contents_url = f"https://api.github.com/repos/{github_repo}/contents/tasks/finalpool?ref=finalpool" | |
| response = requests.get(contents_url, headers=headers) | |
| if response.status_code == 404: | |
| return False, "❌ tasks/finalpool directory does not exist in finalpool branch" | |
| elif response.status_code != 200: | |
| return False, f"❌ Failed to check tasks/finalpool directory: {response.status_code}" | |
| finalpool_contents = response.json() | |
| if not isinstance(finalpool_contents, list): | |
| return False, "❌ tasks/finalpool is not a directory" | |
| # Get list of tasks in finalpool | |
| finalpool_tasks = [item['name'] for item in finalpool_contents if item['type'] == 'dir'] | |
| print(f"📁 Found {len(finalpool_tasks)} task directories in tasks/finalpool") | |
| # Read local Excel to get implemented tasks | |
| import pandas as pd | |
| excel_path = f"{groundtruth_workspace}/notion_table_after.xlsx" | |
| df_excel = pd.read_excel(excel_path) | |
| # Get implemented tasks from Excel | |
| implemented_tasks = set() | |
| for _, row in df_excel.iterrows(): | |
| if pd.notna(row['Task Status']) and str(row['Task Status']).strip().lower() == 'implemented': | |
| if pd.notna(row['Task Name']): | |
| implemented_tasks.add(str(row['Task Name']).strip()) | |
| print(f"📋 Expected {len(implemented_tasks)} implemented tasks from Excel") | |
| print(f" Implemented tasks: {sorted(list(implemented_tasks))}") | |
| issues = [] | |
| # Check that all implemented tasks are in finalpool | |
| finalpool_tasks_set = set(finalpool_tasks) | |
| for implemented_task in implemented_tasks: | |
| if implemented_task not in finalpool_tasks_set: | |
| issues.append(f"Implemented task '{implemented_task}' missing from tasks/finalpool") | |
| # Check that no extra tasks are in finalpool | |
| for finalpool_task in finalpool_tasks: | |
| if finalpool_task not in implemented_tasks: | |
| issues.append(f"Task '{finalpool_task}' in finalpool but not marked as implemented in Excel") | |
| # Check required files for each task in finalpool | |
| valid_tasks_count = 0 | |
| for task_name in finalpool_tasks: | |
| print(f"🔍 Checking task: {task_name}") | |
| # Check for docs/task.md | |
| docs_task_url = f"https://api.github.com/repos/{github_repo}/contents/tasks/finalpool/{task_name}/docs/task.md?ref=finalpool" | |
| docs_response = requests.get(docs_task_url, headers=headers) | |
| has_docs_task = docs_response.status_code == 200 | |
| # Check for evaluation/main.py | |
| eval_main_url = f"https://api.github.com/repos/{github_repo}/contents/tasks/finalpool/{task_name}/evaluation/main.py?ref=finalpool" | |
| eval_response = requests.get(eval_main_url, headers=headers) | |
| has_eval_main = eval_response.status_code == 200 | |
| if not has_docs_task: | |
| issues.append(f"Task '{task_name}': missing docs/task.md") | |
| if not has_eval_main: | |
| issues.append(f"Task '{task_name}': missing evaluation/main.py") | |
| if has_docs_task and has_eval_main: | |
| valid_tasks_count += 1 | |
| print(f" ✅ Valid task structure") | |
| else: | |
| print(f" ❌ Missing required files") | |
| if len(issues) > 0: | |
| error_msg = f"❌ GitHub finalpool validation failed:\n\n" | |
| error_msg += f"Found {len(finalpool_tasks)} tasks in finalpool, expected {len(implemented_tasks)} implemented tasks.\n\n" | |
| error_msg += "Issues found:\n" | |
| for issue in issues[:15]: # Show first 15 issues | |
| error_msg += f" • {issue}\n" | |
| if len(issues) > 15: | |
| error_msg += f" • ... and {len(issues) - 15} more issues\n" | |
| return False, error_msg | |
| # Success! | |
| success_msg = f"✅ GitHub finalpool validation passed!\n" | |
| success_msg += f" • Found 'finalpool' branch\n" | |
| success_msg += f" • tasks/finalpool contains exactly {len(implemented_tasks)} implemented tasks\n" | |
| success_msg += f" • All {valid_tasks_count} tasks have required files:\n" | |
| success_msg += f" - docs/task.md\n" | |
| success_msg += f" - evaluation/main.py\n" | |
| success_msg += f" • No extra or missing tasks detected" | |
| return True, success_msg | |
| except Exception as e: | |
| return False, f"❌ Error checking GitHub finalpool tasks: {str(e)}" | |
| def run_complete_evaluation(agent_workspace, groundtruth_workspace): | |
| """Run the complete evaluation workflow with new logic""" | |
| print("🚀 Starting Complete Task Tracker Evaluation") | |
| print("=" * 80) | |
| all_success = True | |
| results = [] | |
| # Step 1: Check Notion Database vs Excel File | |
| print("\n📊 STEP 1: Checking Notion Database vs Local Excel File...") | |
| try: | |
| notion_success, notion_message = grade_with_retry( | |
| lambda: check_notion_database(groundtruth_workspace), | |
| max_attempts=4, | |
| ) | |
| print(notion_message) | |
| results.append(f"Notion Database Check: {'✅ PASSED' if notion_success else '❌ FAILED'}") | |
| if not notion_success: | |
| all_success = False | |
| print(f"❌ Notion database check failed") | |
| except Exception as e: | |
| all_success = False | |
| error_msg = f"❌ Notion database error: {str(e)}" | |
| print(error_msg) | |
| results.append(f"Notion Database Check: ❌ FAILED - {str(e)}") | |
| # Step 2: Check GitHub Finalpool Tasks | |
| print("\n🐙 STEP 2: Checking GitHub Finalpool Tasks...") | |
| try: | |
| github_success, github_message = check_github_finalpool_tasks(groundtruth_workspace) | |
| print(github_message) | |
| results.append(f"GitHub Finalpool Check: {'✅ PASSED' if github_success else '❌ FAILED'}") | |
| if not github_success: | |
| all_success = False | |
| print(f"❌ GitHub finalpool check failed") | |
| except Exception as e: | |
| all_success = False | |
| error_msg = f"❌ GitHub finalpool error: {str(e)}" | |
| print(error_msg) | |
| results.append(f"GitHub Finalpool Check: ❌ FAILED - {str(e)}") | |
| # Generate final report | |
| print("\n" + "="*80) | |
| print("EVALUATION SUMMARY") | |
| print("="*80) | |
| for result in results: | |
| print(f" {result}") | |
| if all_success: | |
| success_report = [ | |
| "", | |
| "🎉" * 20, | |
| "COMPLETE EVALUATION SUCCESS!", | |
| "🎉" * 20, | |
| "", | |
| "All checks passed:", | |
| "✅ Notion database structure and content validated", | |
| "✅ All Excel data found in Notion database", | |
| "✅ Column names and shapes match perfectly (Task Name, Task Status, Implementor)", | |
| "✅ GitHub finalpool branch contains only implemented tasks", | |
| "✅ All required files (docs/task.md, evaluation/main.py) present", | |
| "✅ No extra or missing tasks detected", | |
| "", | |
| "The task tracker agent performed correctly!" | |
| ] | |
| return True, "\n".join(success_report) | |
| else: | |
| failure_report = [ | |
| "", | |
| "❌" * 20, | |
| "EVALUATION FAILED!", | |
| "❌" * 20, | |
| "", | |
| "One or more checks failed. See details above.", | |
| "", | |
| "The task tracker agent did not complete all requirements successfully." | |
| ] | |
| return False, "\n".join(failure_report) | |
| if __name__ == "__main__": | |
| parser = ArgumentParser() | |
| parser.add_argument("--agent_workspace", required=False, default=".") | |
| parser.add_argument("--groundtruth_workspace", required=False) | |
| parser.add_argument("--res_log_file", required=False) | |
| parser.add_argument("--launch_time", required=False, help="Launch time") | |
| args = parser.parse_args() | |
| try: | |
| success, message = run_complete_evaluation(args.agent_workspace, args.groundtruth_workspace) | |
| print("\n" + "="*80) | |
| print("FINAL EVALUATION RESULT") | |
| print("="*80) | |
| print(message) | |
| if success: | |
| print("\n✅ EVALUATION PASSED") | |
| sys.exit(0) | |
| else: | |
| print("\n❌ EVALUATION FAILED") | |
| sys.exit(1) | |
| except Exception as e: | |
| print(f"❌ Critical evaluation error: {e}") | |
| import traceback | |
| traceback.print_exc() | |
| sys.exit(1) |
Xet Storage Details
- Size:
- 19.5 kB
- Xet hash:
- 01c34e9c2fe25ef460b4ebe358431c5403517e854fc1e9119a10dacda8bb1ac1
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.