| """ |
| Test and demonstrate the retrieval system. |
| |
| Run this script to: |
| 1. Load and normalize the dataset |
| 2. Test retrieval with various config examples |
| 3. Display retrieved results with similarity scores |
| """ |
|
|
| import json |
| from app.services.retrieval import load_games_dataset, normalize_game_record, retrieve_examples |
|
|
| def main(): |
| |
| print("Loading and normalizing dataset...") |
| raw_records = load_games_dataset("app/data/games_dataset.json") |
| normalized_records = [normalize_game_record(r) for r in raw_records] |
| print(f"✓ Loaded {len(normalized_records)} normalized records\n") |
| |
| |
| test_configs = [ |
| { |
| "name": "Scavenger Hunt - Adults - Medium", |
| "config": { |
| "game_type": "scavenger_hunt", |
| "city": "Paris", |
| "area": "free text", |
| "location_type": "mixed", |
| "duration_minutes": 60, |
| "num_players": 4, |
| "difficulty": "medium", |
| "age_group": "adults", |
| "energy_level": "medium", |
| "photo_enabled": True |
| } |
| }, |
| { |
| "name": "Hide and Seek - Kids - Easy", |
| "config": { |
| "game_type": "hide_and_seek", |
| "city": "Paris", |
| "area": "park area", |
| "location_type": "park", |
| "duration_minutes": 45, |
| "num_players": 5, |
| "difficulty": "easy", |
| "age_group": "kids", |
| "energy_level": "high", |
| "photo_enabled": False |
| } |
| }, |
| { |
| "name": "Tag - Teens - Hard", |
| "config": { |
| "game_type": "tag", |
| "city": "Paris", |
| "area": "outdoor spaces", |
| "location_type": "mixed", |
| "duration_minutes": 30, |
| "num_players": 8, |
| "difficulty": "hard", |
| "age_group": "teens", |
| "energy_level": "high", |
| "photo_enabled": False |
| } |
| }, |
| { |
| "name": "Mixed Age - 90 minutes - Medium", |
| "config": { |
| "game_type": "scavenger_hunt", |
| "city": "Paris", |
| "area": "outdoor", |
| "location_type": "mixed", |
| "duration_minutes": 90, |
| "num_players": 6, |
| "difficulty": "medium", |
| "age_group": "mixed", |
| "energy_level": "medium", |
| "photo_enabled": True |
| } |
| } |
| ] |
| |
| |
| for test in test_configs: |
| print("=" * 80) |
| print(f"TEST: {test['name']}") |
| print("=" * 80) |
| config = test['config'] |
| print(f"Query Config:") |
| print(f" Game Type: {config['game_type']}") |
| print(f" Duration: {config['duration_minutes']} min | Players: {config['num_players']}") |
| print(f" Difficulty: {config['difficulty']} | Age Group: {config['age_group']}") |
| print(f" Location Type: {config['location_type']}") |
| |
| |
| retrieved = retrieve_examples(config, normalized_records, k=5) |
| |
| print(f"\nTop 5 Retrieved Examples:") |
| print("-" * 80) |
| |
| for i, example in enumerate(retrieved, 1): |
| print(f"\n{i}. {example['id']} (Score: {example['retrieval_score']:.1f})") |
| print(f" Game Type: {example['game_type']}") |
| print(f" Area: {example['area']}") |
| print(f" Duration: {example['duration_minutes']} min | Difficulty: {example['difficulty']}") |
| print(f" Age Group: {example['age_group']} | Quality: {example['quality_score']}/5") |
| print(f" Rules: {len(example['rules_summary'])} examples") |
| if example['rules_summary']: |
| print(f" • {example['rules_summary'][0][:70]}...") |
| print(f" Tasks: {len(example['task_patterns'])} patterns") |
| for task in example['task_patterns'][:2]: |
| print(f" • {task['task_id']}: {task['points']} pts ({task['proof_type']})") |
| if example['safety_patterns']: |
| print(f" Safety Flags: {example['safety_patterns']}") |
| |
| print("\n") |
| |
| |
| print("=" * 80) |
| print("EXEMPLAR BUNDLE OUTPUT FORMAT") |
| print("=" * 80) |
| |
| sample_config = test_configs[0]["config"] |
| sample_retrieved = retrieve_examples(sample_config, normalized_records, k=2) |
| |
| print("\nJSON Output (first 2 results):") |
| print(json.dumps(sample_retrieved, indent=2)) |
| |
| print("\n" + "=" * 80) |
| print("RETRIEVAL TESTS COMPLETE") |
| print("=" * 80) |
|
|
| if __name__ == "__main__": |
| main() |
|
|