2025年4月5日 星期六

依照水井USR目標實作Python模組並計算SROI

水井村智慧減碳節水三生一體社會實踐計畫的整體發展目標是通過低碳智慧養殖、生態節水、以及三生共好永續發展平台的整合,實現水井村的生態環境保護、生產效率提升及生活品質改善,具體目標包括:

  • 環境生態保護:減少碳排放和水資源浪費,發展淨水技術,改善當地生態環境,保護水下和陸上生物。
  • 生產效率提升:發展低成本、低碳和節水的智慧養殖技術,提高養殖業的生產效率和品質,促進當地經濟發展。
  • 生活品質改善:用藝文提高村民的生活品質,通過智慧科技教育和工藝產品設計技術提升水井村的品牌形象。
🌱 一、環境生態保護模組WaterPurificationSyste
 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
class WaterPurificationSystem:
    def __init__(self, dirty_water_liters):
        self.dirty_water = dirty_water_liters
        self.clean_water = 0
        self.energy_used = 0  # kWh
    
    def purify(self, method='biological'):
        if method == 'biological':
            efficiency = 0.7
            energy = 0.2  # per liter
        elif method == 'filtration':
            efficiency = 0.85
            energy = 0.4
        else:
            efficiency = 0.5
            energy = 0.3
        
        purified = self.dirty_water * efficiency
        self.clean_water += purified
        self.energy_used += purified * energy
        self.dirty_water -= purified
        print(f"使用 {method} 淨化方式,產出 {purified:.2f} 公升的淨水")

# 示例
system = WaterPurificationSystem(100)
system.purify('biological')
system.purify('filtration')

執行結果:
使用 biological 淨化方式,產出 70.00 公升的淨水
使用 filtration 淨化方式,產出 25.50 公升的淨水

🐟 二、生產效率提升模組:SmartAquacultureTank

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
class SmartAquacultureTank:
    def __init__(self, fish_count, water_temp):
        self.fish_count = fish_count
        self.water_temp = water_temp  # °C
        self.feeding_amount = 0  # grams
        self.energy_usage = 0  # kWh

    def feed(self, grams):
        self.feeding_amount += grams
        self.energy_usage += 0.1  # 每次投餵耗能
        print(f"餵食 {grams} 克魚飼料,目前總餵食量:{self.feeding_amount} 克")

    def adjust_temperature(self, target_temp):
        energy_needed = abs(self.water_temp - target_temp) * 0.5
        self.water_temp = target_temp
        self.energy_usage += energy_needed
        print(f"水溫調整至 {self.water_temp}°C,耗能 {energy_needed:.2f} kWh")

# 示例
tank = SmartAquacultureTank(50, 26)
tank.feed(300)
tank.adjust_temperature(28)

執行結果:
餵食 300 克魚飼料,目前總餵食量:300 克
水溫調整至 28°C,耗能 1.00 kWh

🎨 三、生活品質改善模組:CraftProduct

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
class CraftProduct:
    def __init__(self, name, material, eco_friendly=True):
        self.name = name
        self.material = material
        self.eco_friendly = eco_friendly
        self.price = 0

    def set_price(self, base_price):
        self.price = base_price * (0.9 if self.eco_friendly else 1.2)
        print(f"{self.name} 的定價為 NT${self.price:.0f}")

    def describe(self):
        type_text = "環保材料" if self.eco_friendly else "一般材料"
        print(f"{self.name} 使用 {type_text} 製成,主要材質:{self.material}")

# 示例
flower_lamp = CraftProduct("玉米籜彩燈", "玉米籜")
flower_lamp.set_price(300)
flower_lamp.describe()

執行結果:
玉米籜彩燈 的定價為 NT$270
玉米籜彩燈 使用 環保材料 製成,主要材質:玉米籜

🌏 「智慧村落模擬器」專案:smart_village_simulator.py

 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
class WaterPurificationSystem:
    def __init__(self, dirty_water_liters):
        self.dirty_water = dirty_water_liters
        self.clean_water = 0
        self.energy_used = 0

    def purify(self, method='biological'):
        if method == 'biological':
            efficiency = 0.7
            energy = 0.2
        elif method == 'filtration':
            efficiency = 0.85
            energy = 0.4
        else:
            efficiency = 0.5
            energy = 0.3

        purified = self.dirty_water * efficiency
        self.clean_water += purified
        self.energy_used += purified * energy
        self.dirty_water -= purified
        print(f"[環境] 使用 {method} 淨化方式,產出 {purified:.2f} 公升淨水。")


class SmartAquacultureTank:
    def __init__(self, fish_count, water_temp):
        self.fish_count = fish_count
        self.water_temp = water_temp
        self.feeding_amount = 0
        self.energy_usage = 0

    def feed(self, grams):
        self.feeding_amount += grams
        self.energy_usage += 0.1
        print(f"[生產] 餵食 {grams} 克,總餵食量:{self.feeding_amount} 克")

    def adjust_temperature(self, target_temp):
        energy_needed = abs(self.water_temp - target_temp) * 0.5
        self.water_temp = target_temp
        self.energy_usage += energy_needed
        print(f"[生產] 水溫調整至 {self.water_temp}°C,耗能 {energy_needed:.2f} kWh")


class CraftProduct:
    def __init__(self, name, material, eco_friendly=True):
        self.name = name
        self.material = material
        self.eco_friendly = eco_friendly
        self.price = 0

    def set_price(self, base_price):
        self.price = base_price * (0.9 if self.eco_friendly else 1.2)
        print(f"[生活] 工藝品 {self.name} 定價:NT${self.price:.0f}")

    def describe(self):
        type_text = "環保材料" if self.eco_friendly else "一般材料"
        print(f"[生活] {self.name} 使用 {type_text} 製成,主要材質:{self.material}")


class SmartVillageSimulator:
    def __init__(self):
        self.water_system = WaterPurificationSystem(200)
        self.aqua_tank = SmartAquacultureTank(100, 25)
        self.craft_products = []

    def run_simulation(self):
        print("📍 模擬啟動:水井村智慧三生實踐")

        # 環境模組
        self.water_system.purify('biological')

        # 生產模組
        self.aqua_tank.feed(500)
        self.aqua_tank.adjust_temperature(27)

        # 生活模組
        lamp = CraftProduct("玉米殼花燈", "玉米殼")
        lamp.set_price(350)
        lamp.describe()
        self.craft_products.append(lamp)

        self.summary()

    def summary(self):
        print("\n📊 【模擬總結】")
        print(f"淨水量:{self.water_system.clean_water:.2f} 公升")
        print(f"淨水耗能:{self.water_system.energy_used:.2f} kWh")
        print(f"養殖耗能:{self.aqua_tank.energy_usage:.2f} kWh")
        print(f"工藝產品數量:{len(self.craft_products)} 項")


# 主程式執行
if __name__ == "__main__":
    sim = SmartVillageSimulator()
    sim.run_simulation()

執行結果:
📍 模擬啟動:水井村智慧三生實踐
[環境] 使用 biological 淨化方式,產出 140.00 公升淨水。
[生產] 餵食 500 克,總餵食量:500 克
[生產] 水溫調整至 27°C,耗能 1.00 kWh
[生活] 工藝品 玉米殼花燈 定價:NT$315
[生活] 玉米殼花燈 使用 環保材料 製成,主要材質:玉米殼

📊 【模擬總結】
淨水量:140.00 公升
淨水耗能:28.00 kWh
養殖耗能:1.10 kWh
工藝產品數量:1 項

五、計算SROI值
SROI = (總社會效益價值 - 投入成本) / 投入成本


 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
class SROICalculator:
    def __init__(self):
        self.inputs = {}       # 成本投入(項目:金額)
        self.outcomes = {}     # 效益產出(項目:金額)
    
    def add_input(self, item, amount):
        self.inputs[item] = self.inputs.get(item, 0) + amount

    def add_outcome(self, item, amount):
        self.outcomes[item] = self.outcomes.get(item, 0) + amount

    def calculate_sroi(self):
        total_input = sum(self.inputs.values())
        total_outcome = sum(self.outcomes.values())
        if total_input == 0:
            return float('inf')  # 無投入代表SROI無限大
        sroi = (total_outcome - total_input) / total_input
        return round(sroi, 2)

    def summary(self):
        print("📦 成本投入項目:")
        for k, v in self.inputs.items():
            print(f"  - {k}: NT${v}")
        print("\n🎯 效益產出項目:")
        for k, v in self.outcomes.items():
            print(f"  - {k}: NT${v}")
        print(f"\n💡 SROI = {self.calculate_sroi()}")

# 實例:水井村案例模擬
sroi_calc = SROICalculator()

# 📦 成本投入
sroi_calc.add_input("IoT設備與感測器", 120000)
sroi_calc.add_input("水質淨化系統", 80000)
sroi_calc.add_input("教學與培訓費用", 100000)
sroi_calc.add_input("工藝材料與推廣", 50000)

# 🎯 效益(將社會效益轉換為估算金額)
sroi_calc.add_outcome("節省水資源成本", 50000)
sroi_calc.add_outcome("減碳社會效益(估算)", 70000)
sroi_calc.add_outcome("智慧養殖提升產值", 150000)
sroi_calc.add_outcome("地方品牌提升與觀光收益", 60000)
sroi_calc.add_outcome("居民生活與文化參與提升(估算)", 30000)

# ⏱️ 輸出結果
sroi_calc.summary()

執行結果:
📦 成本投入項目:
  - IoT設備與感測器: NT$120000
  - 水質淨化系統: NT$80000
  - 教學與培訓費用: NT$100000
  - 工藝材料與推廣: NT$50000

🎯 效益產出項目:
  - 節省水資源成本: NT$50000
  - 減碳社會效益(估算): NT$70000
  - 智慧養殖提升產值: NT$150000
  - 地方品牌提升與觀光收益: NT$60000
  - 居民生活與文化參與提升(估算): NT$30000

💡 SROI = 0.03

註:表示每投入 1 元,社會可獲得 1.18 元的價值回報。

沒有留言:

張貼留言