File size: 1,716 Bytes
119f7b3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# area_calculator.py
# 計算建蔽面積、基準容積、獎勵容積、住家面積等

def get_missing_keys(data, required_keys=["site_area", "FAR", "BCR"]):
    """檢查缺少哪些欄位"""
    return [key for key in required_keys if key not in data or data[key] is None]

def calculate_area(data):
    result = {}

    # 取得基本參數
    site_area = data.get("site_area")
    far = data.get("FAR")
    bcr = data.get("BCR")
    bonus_far = data.get("bonus_far", 0)  # 預設為 0(無獎勵)

    # 防呆檢查
    if site_area is None or far is None:
        print("⚠️ 缺少 site_area 或 FAR,無法計算")
        return {}

    # ✅ 計算建蔽面積(選配)
    buildable_area = site_area * (bcr / 100)
    result["buildable_area"] = round(buildable_area, 2)

    # ✅ 計算基準容積(平方公尺)
    base_volume = site_area * (far / 100)
    result["base_volume"] = round(base_volume, 2)

    # ✅ 計算獎勵容積(平方公尺)
    bonus_volume = base_volume * (bonus_far / 100)
    result["bonus_volume"] = round(bonus_volume, 2)

    # ✅ 計算總住家面積(黃色區域)
    total_living_area = base_volume + bonus_volume
    result["residential_area"] = round(total_living_area, 2)

    # ✅ summary 回應文字(for chatbot)
    result["summary"] = (
        f"🏗️ 基準容積為 {result['base_volume']} 平方公尺,"
        f"容積獎勵為 {result['bonus_volume']} 平方公尺,"
        f"總可規劃住家面積為 {result['residential_area']} 平方公尺。"
    )

    # ✅ 額外 log
    print("✅ 建築面積計算完成")
    print(result["summary"])

    return result