File size: 5,774 Bytes
7b6b271
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
#!/usr/bin/env python3
"""
Component tests for surf spot finder
Tests individual parts without complex imports
"""

import json
import os
import sys
from geopy.geocoders import Nominatim
from geopy.distance import geodesic

# Add parent directory to path to access the mcp_server modules
sys.path.insert(0, os.path.dirname(os.path.dirname(__file__)))


def test_database():
    """Test surf spots database loading"""
    print("πŸ—„οΈ Testing Database Loading...")
    
    try:
        spots_path = os.path.join(os.path.dirname(__file__), "..", "data", "surf_spots.json")
        with open(spots_path, 'r') as f:
            data = json.load(f)
            spots = data["spots"]
        
        print(f"βœ… Loaded {len(spots)} surf spots:")
        for spot in spots[:3]:  # Show first 3
            print(f"   β€’ {spot['name']} ({spot['location']}) - {spot['latitude']}, {spot['longitude']}")
        
        return spots
    except Exception as e:
        print(f"❌ Database test failed: {e}")
        return []


def test_geocoding():
    """Test location resolution"""
    print("\n🌍 Testing Geocoding...")
    
    try:
        geolocator = Nominatim(user_agent="surf-spot-finder-test")
        
        test_locations = ["Tarifa, Spain", "Lisbon, Portugal"]
        
        for location in test_locations:
            result = geolocator.geocode(location, timeout=10)
            if result:
                print(f"   βœ… {location} β†’ {result.latitude:.3f}, {result.longitude:.3f}")
            else:
                print(f"   ❌ {location} β†’ Failed to resolve")
        
        return True
    except Exception as e:
        print(f"❌ Geocoding test failed: {e}")
        return False


def test_distance_calculation():
    """Test distance calculations"""
    print("\nπŸ“ Testing Distance Calculations...")
    
    try:
        # Test distance between Tarifa and nearby spots
        tarifa = (36.013, -5.605)
        nearby_spots = [
            ("Ericeira, Portugal", 39.001, -9.416),
            ("Mundaka, Spain", 43.407, -2.699)
        ]
        
        for name, lat, lon in nearby_spots:
            distance = geodesic(tarifa, (lat, lon)).kilometers
            print(f"   πŸ“ Tarifa to {name}: {distance:.1f}km")
        
        return True
    except Exception as e:
        print(f"❌ Distance test failed: {e}")
        return False


def test_surf_evaluation():
    """Test basic surf evaluation logic"""
    print("\nπŸ„β€β™‚οΈ Testing Surf Evaluation Logic...")
    
    try:
        # Sample spot data
        spot = {
            "name": "Tarifa",
            "optimal_conditions": {
                "swell_direction": [180, 270],
                "wind_direction": [90, 180],
                "min_wave_height": 0.5,
                "max_wave_height": 4.0
            },
            "characteristics": {
                "skill_level": ["beginner", "intermediate", "advanced"]
            }
        }
        
        # Sample conditions
        conditions = {
            "wave_height": 1.5,
            "wind_speed": 10,
            "wind_direction": 135,
            "swell_direction": 225
        }
        
        # Simple scoring logic
        score = 0
        explanation = []
        
        # Wave height check
        if conditions["wave_height"] >= spot["optimal_conditions"]["min_wave_height"]:
            score += 25
            explanation.append(f"βœ… Wave height {conditions['wave_height']}m is suitable")
        
        # Wind speed check (prefer < 15kt)
        if conditions["wind_speed"] < 15:
            score += 20
            explanation.append(f"βœ… Wind speed {conditions['wind_speed']}kt is manageable")
        
        # Basic direction checks
        swell_dir = conditions["swell_direction"]
        opt_swell = spot["optimal_conditions"]["swell_direction"]
        if opt_swell[0] <= swell_dir <= opt_swell[1]:
            score += 30
            explanation.append(f"βœ… Swell direction {swell_dir}Β° is optimal")
        
        wind_dir = conditions["wind_direction"]  
        opt_wind = spot["optimal_conditions"]["wind_direction"]
        if opt_wind[0] <= wind_dir <= opt_wind[1]:
            score += 25
            explanation.append(f"βœ… Wind direction {wind_dir}Β° is favorable")
        
        print(f"   πŸ† {spot['name']} Score: {score}/100")
        for exp in explanation:
            print(f"      {exp}")
        
        return score > 50
        
    except Exception as e:
        print(f"❌ Evaluation test failed: {e}")
        return False


# Note: Advanced evaluation test with async removed for now
# Will test this as part of integration testing


def main():
    """Run all tests"""
    print("πŸš€ Surf Spot Finder - Component Tests")
    print("=" * 50)
    
    # Run tests
    spots = test_database()
    geocoding_ok = test_geocoding()
    distance_ok = test_distance_calculation()
    evaluation_ok = test_surf_evaluation()
    
    # Summary
    print("\n" + "=" * 50)
    print("πŸ“Š Test Summary:")
    print(f"   Database: {'βœ…' if spots else '❌'}")
    print(f"   Geocoding: {'βœ…' if geocoding_ok else '❌'}")
    print(f"   Distance: {'βœ…' if distance_ok else '❌'}")
    print(f"   Basic Evaluation: {'βœ…' if evaluation_ok else '❌'}")
    
    all_passed = spots and geocoding_ok and distance_ok and evaluation_ok
    
    if all_passed:
        print("\nπŸŽ‰ All basic components working!")
        print("πŸ“‹ Next steps:")
        print("   1. Test API integration (Stormglass)")
        print("   2. Test complete workflow")
        print("   3. Add LLM integration")
    else:
        print("\n⚠️  Some tests failed. Fix issues before proceeding.")
    
    return all_passed


if __name__ == "__main__":
    main()