File size: 2,742 Bytes
fc41845
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import requests
import json

def test_dirty_data():
    url = "http://localhost:8000/predict"
    
    # Test cases:
    # 1. Missing fields (should be handled by Pydantic validation)
    # 2. Null/None values (if allowed by Pydantic)
    # 3. Unknown categorical values (should be handled by OneHotEncoder handle_unknown='ignore')
    # 4. Out of range numerical values
    
    test_cases = [
        {
            "name": "Unknown Categorical Values",
            "payload": {
                "City": "Mars city",
                "Neighborhood": "Alien Quarter",
                "Type": "Spaceship",
                "Surface": 5000.0,
                "Rooms": 100,
                "Bedrooms": 50,
                "Standing": "Galactic",
                "Residency": "Moon Base",
                "Orientation": "Vertical",
                "View": "Earth View",
                "Condition": "Futuristic",
                "Floor": -5,
                "Lift": 1,
                "Pool": 1,
                "Garden": 1,
                "Parking_Spots": 100,
                "Proximity_Tram": 0,
                "Proximity_University": 0,
                "Proximity_Mosque": 0
            }
        },
        {
            "name": "Extreme Numerical Values",
            "payload": {
                "City": "Casablanca",
                "Neighborhood": "Anfa",
                "Type": "Appartement",
                "Surface": 999999.0,
                "Rooms": 0,
                "Bedrooms": -1,
                "Standing": "Economique",
                "Residency": "Public / Quartier ouvert",
                "Orientation": "Nord",
                "View": "Vue sur rue",
                "Condition": "A rénover",
                "Floor": 999,
                "Lift": 0,
                "Pool": 0,
                "Garden": 0,
                "Parking_Spots": 0,
                "Proximity_Tram": 0,
                "Proximity_University": 0,
                "Proximity_Mosque": 0
            }
        }
    ]

    for case in test_cases:
        print(f"\n--- Testing: {case['name']} ---")
        try:
            response = requests.post(url, json=case['payload'])
            print(f"Status: {response.status_code}")
            if response.status_code == 200:
                result = response.json()
                print(f"Prediction: {result.get('estimated_price')} {result.get('currency')}")
                print(f"AI Analysis: {result.get('ai_analysis')}")
            else:
                print(f"Error: {response.text}")
        except Exception as e:
            print(f"Connection error: {e}")

if __name__ == "__main__":
    test_dirty_data()