File size: 3,378 Bytes
9b24c4d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""
Simple test to verify format conversion logic
"""

# Test the conversion logic without dependencies
def test_legacy_conversion():
    """Test that legacy format gets converted correctly"""
    
    # Simulate legacy request
    risk_data = {
        "location": {
            "name": "Manila",
            "coordinates": {"latitude": 14.5995, "longitude": 120.9842}
        },
        "hazards": {"seismic": {}, "volcanic": {}, "hydrometeorological": {}}
    }
    building_type = "residential_single_family"
    recommendations = {"general_guidelines": ["Test"]}
    
    # Simulate the conversion logic from main.py
    construction_data = {
        "building_type": building_type,
        "risk_data": risk_data
    }
    
    if recommendations:
        construction_data["recommendations"] = recommendations
    
    if isinstance(risk_data, dict) and "location" in risk_data:
        construction_data["location"] = risk_data["location"]
    
    # Generate prompt
    building_descriptions = {
        "residential_single_family": "single-family home",
        "residential_multi_family": "multi-family residential building",
        "residential_high_rise": "high-rise apartment building",
        "commercial_office": "modern office building",
        "commercial_retail": "retail shopping center",
        "industrial_warehouse": "industrial warehouse facility",
        "institutional_school": "school building",
        "institutional_hospital": "hospital or healthcare facility",
        "infrastructure_bridge": "bridge structure",
        "mixed_use": "mixed-use development"
    }
    building_desc = building_descriptions.get(building_type, "building")
    prompt = f"Generate an architectural visualization of a {building_desc} in the Philippines with disaster-resistant features"
    
    # Verify conversion
    print("Legacy Format Conversion Test")
    print("=" * 60)
    print(f"Input:")
    print(f"  - building_type: {building_type}")
    print(f"  - risk_data: {bool(risk_data)}")
    print(f"  - recommendations: {bool(recommendations)}")
    print()
    print(f"Output:")
    print(f"  - prompt: {prompt}")
    print(f"  - construction_data keys: {list(construction_data.keys())}")
    print()
    
    # Assertions
    assert prompt is not None, "Prompt should be generated"
    assert "single-family home" in prompt, "Prompt should contain building description"
    assert "Philippines" in prompt, "Prompt should mention Philippines"
    assert "disaster-resistant" in prompt, "Prompt should mention disaster-resistant"
    
    assert "building_type" in construction_data, "construction_data should have building_type"
    assert "risk_data" in construction_data, "construction_data should have risk_data"
    assert "recommendations" in construction_data, "construction_data should have recommendations"
    assert "location" in construction_data, "construction_data should have location"
    
    print("✅ All assertions passed!")
    print("   Legacy format successfully converts to new format")
    print("=" * 60)
    
    return True


if __name__ == "__main__":
    try:
        test_legacy_conversion()
    except AssertionError as e:
        print(f"❌ Test failed: {e}")
        exit(1)
    except Exception as e:
        print(f"❌ Unexpected error: {e}")
        import traceback
        traceback.print_exc()
        exit(1)