顯示具有 USR 標籤的文章。 顯示所有文章
顯示具有 USR 標籤的文章。 顯示所有文章

2025年6月3日 星期二

水井村USR導覽暨測驗系統

元件:micro:bitSmart AI LensMP3 PlayerIoT擴充板

接線:MP3 Player接在第1支腳、Smart AI Lens接在第19、20支腳
積木式程式:

Python程式:


 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
def RightWrong(num: number, ans: str):
    global Number2
    if answer[num] == ans:
        mp3Player.set_tracking(8, mp3Player.repeatList.NO)
        basic.show_icon(IconNames.YES)
    else:
        mp3Player.set_tracking(9, mp3Player.repeatList.NO)
        basic.show_icon(IconNames.NO)
    basic.pause(5000)
    Number2 = (Number2 + 1) % 5
    mp3Player.set_tracking(Number2 + 14, mp3Player.repeatList.NO)
    basic.pause(2000)
    basic.show_icon(IconNames.SQUARE)
Number2 = 0
answer: List[str] = []
basic.show_leds("""
    . # . # .
    # # # # #
    . # . # .
    # # # # #
    . # . # .
    """)
basic.pause(500)
mp3Player.mp3_set_serial(SerialPin.P1)
mp3Player.set_volume(25)
PlanetX_AILens.init_module()
PlanetX_AILens.switchfunc(PlanetX_AILens.FuncList.CARD)
basic.show_leds("""
    . . # # #
    . . . # #
    . . . . #
    # # . . .
    # # . . .
    """)
# 0:介紹、1測驗
mode = 0
answer = ["B", "C", "C", "D", "D"]

def on_forever():
    global mode, Number2
    PlanetX_AILens.camera_image()
    if mode == 0 and PlanetX_AILens.number_card(PlanetX_AILens.numberCards.ZERO):
        mp3Player.set_tracking(1, mp3Player.repeatList.NO)
    elif mode == 0 and PlanetX_AILens.number_card(PlanetX_AILens.numberCards.ONE):
        mp3Player.set_tracking(2, mp3Player.repeatList.NO)
    elif mode == 0 and PlanetX_AILens.number_card(PlanetX_AILens.numberCards.TWO):
        mp3Player.set_tracking(3, mp3Player.repeatList.NO)
    elif mode == 0 and PlanetX_AILens.number_card(PlanetX_AILens.numberCards.THREE):
        mp3Player.set_tracking(4, mp3Player.repeatList.NO)
    elif mode == 0 and PlanetX_AILens.number_card(PlanetX_AILens.numberCards.FOUR):
        mp3Player.set_tracking(5, mp3Player.repeatList.NO)
    elif mode == 0 and PlanetX_AILens.number_card(PlanetX_AILens.numberCards.FIVE):
        mp3Player.set_tracking(7, mp3Player.repeatList.NO)
        mode = 1
        Number2 = 0
        basic.pause(5000)
        mp3Player.set_tracking(14, mp3Player.repeatList.NO)
        basic.show_icon(IconNames.SQUARE)
    elif mode == 1 and PlanetX_AILens.letter_card(PlanetX_AILens.letterCards.A):
        mp3Player.set_tracking(10, mp3Player.repeatList.NO)
        RightWrong(Number2, "A")
    elif mode == 1 and PlanetX_AILens.letter_card(PlanetX_AILens.letterCards.B):
        mp3Player.set_tracking(11, mp3Player.repeatList.NO)
        RightWrong(Number2, "B")
    elif mode == 1 and PlanetX_AILens.letter_card(PlanetX_AILens.letterCards.C):
        mp3Player.set_tracking(12, mp3Player.repeatList.NO)
        RightWrong(Number2, "C")
    elif mode == 1 and PlanetX_AILens.letter_card(PlanetX_AILens.letterCards.D):
        mp3Player.set_tracking(13, mp3Player.repeatList.NO)
        RightWrong(Number2, "D")
    elif mode == 1 and PlanetX_AILens.letter_card(PlanetX_AILens.letterCards.E):
        mp3Player.set_tracking(6, mp3Player.repeatList.NO)
        mode = 0
        basic.show_leds("""
            . . # # #
            . . . # #
            . . . . #
            # # . . .
            # # . . .
            """)
    basic.pause(2500)
basic.forever(on_forever)

2025年4月6日 星期日

加入影響力因子重新計算水井USR的SROI

1.加入無謂因子(Deadweight) 的程式:

 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, deadweight=0):
        adjusted_amount = amount * (1 - deadweight)
        self.outcomes[item] = self.outcomes.get(item, 0) + adjusted_amount

    def calculate_sroi(self):
        total_input = sum(self.inputs.values())
        total_outcome = sum(self.outcomes.values())
        if total_input == 0:
            return float('inf')
        return round((total_outcome - total_input) / total_input, 2)

    def summary(self):
        print("📦 成本投入:")
        for k, v in self.inputs.items():
            print(f"  - {k}: NT${v}")
        print("\n🎯 調整後效益(扣除 Deadweight):")
        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)

# 🎯 效益(已考量 Deadweight)
sroi_calc.add_outcome("節省水資源成本", 50000, deadweight=0.15)  # 15%
sroi_calc.add_outcome("減碳社會效益(估算)", 70000, deadweight=0.10)  # 10%
sroi_calc.add_outcome("智慧養殖提升產值", 150000, deadweight=0.25)  # 25%
sroi_calc.add_outcome("地方品牌提升與觀光收益", 60000, deadweight=0.40)  # 40%
sroi_calc.add_outcome("居民生活與文化參與提升(估算)", 30000, deadweight=0.35)  # 35%

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

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

🎯 調整後效益(扣除 Deadweight):
  - 節省水資源成本: NT$42500.0
  - 減碳社會效益(估算): NT$63000.0
  - 智慧養殖提升產值: NT$112500.0
  - 地方品牌提升與觀光收益: NT$36000.0
  - 居民生活與文化參與提升(估算): NT$19500.0

💡 SROI = -0.22

2.再加入歸因因子(Attribution)和衰減因子(Drop-off)的程式(以3年為期):

 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
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, deadweight=0, attribution=0, dropoff=0, years=1):
        adjusted_total = 0
        for year in range(years):
            year_factor = (1 - dropoff) ** year
            adjusted = amount * (1 - deadweight) * (1 - attribution) * year_factor
            adjusted_total += adjusted
        self.outcomes[item] = self.outcomes.get(item, 0) + adjusted_total

    def calculate_sroi(self):
        total_input = sum(self.inputs.values())
        total_outcome = sum(self.outcomes.values())
        if total_input == 0:
            return float('inf')
        return round((total_outcome - total_input) / total_input, 2)

    def summary(self):
        print("📦 成本投入:")
        for k, v in self.inputs.items():
            print(f"  - {k}: NT${v}")
        print("\n🎯 調整後效益(扣除 Deadweight、歸因、遞減):")
        for k, v in self.outcomes.items():
            print(f"  - {k}: NT${round(v, 2)}")
        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)

# 🎯 效益:含 Deadweight、Attribution、Drop-off、years
sroi_calc.add_outcome("節省水資源成本", 50000, deadweight=0.15, attribution=0.1, dropoff=0.05, years=3)
sroi_calc.add_outcome("減碳社會效益(估算)", 70000, deadweight=0.10, attribution=0.1, dropoff=0.05, years=3)
sroi_calc.add_outcome("智慧養殖提升產值", 150000, deadweight=0.25, attribution=0.15, dropoff=0.1, years=3)
sroi_calc.add_outcome("地方品牌提升與觀光收益", 60000, deadweight=0.4, attribution=0.2, dropoff=0.1, years=3)
sroi_calc.add_outcome("居民生活與文化參與提升(估算)", 30000, deadweight=0.35, attribution=0.15, dropoff=0.05, years=3)

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

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

🎯 調整後效益(扣除 Deadweight、歸因、遞減):
  - 節省水資源成本: NT$109108.12
  - 減碳社會效益(估算): NT$161736.75
  - 智慧養殖提升產值: NT$259143.75
  - 地方品牌提升與觀光收益: NT$78048.0
  - 居民生活與文化參與提升(估算): NT$47280.19

💡 SROI = 0.87

3.再加入移轉因子(Displacement),其程式如下:

 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
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, deadweight=0, attribution=0, displacement=0, dropoff=0, years=1):
        adjusted_total = 0
        for year in range(years):
            year_factor = (1 - dropoff) ** year
            adjusted = amount * (1 - deadweight) * (1 - attribution) * (1 - displacement) * year_factor
            adjusted_total += adjusted
        self.outcomes[item] = self.outcomes.get(item, 0) + adjusted_total

    def calculate_sroi(self):
        total_input = sum(self.inputs.values())
        total_outcome = sum(self.outcomes.values())
        if total_input == 0:
            return float('inf')
        return round((total_outcome - total_input) / total_input, 2)

    def summary(self):
        print("📦 成本投入:")
        for k, v in self.inputs.items():
            print(f"  - {k}: NT${v}")
        print("\n🎯 調整後效益(扣除 Deadweight、歸因、移轉、遞減):")
        for k, v in self.outcomes.items():
            print(f"  - {k}: NT${round(v, 2)}")
        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)

# 🎯 效益(含 Deadweight、Attribution、Displacement、Drop-off、Years)
sroi_calc.add_outcome("節省水資源成本", 50000, deadweight=0.15, attribution=0.1, displacement=0.0, dropoff=0.05, years=3)
sroi_calc.add_outcome("減碳社會效益(估算)", 70000, deadweight=0.10, attribution=0.1, displacement=0.0, dropoff=0.05, years=3)
sroi_calc.add_outcome("智慧養殖提升產值", 150000, deadweight=0.25, attribution=0.15, displacement=0.05, dropoff=0.1, years=3)
sroi_calc.add_outcome("地方品牌提升與觀光收益", 60000, deadweight=0.4, attribution=0.2, displacement=0.3, dropoff=0.1, years=3)
sroi_calc.add_outcome("居民生活與文化參與提升", 30000, deadweight=0.35, attribution=0.15, displacement=0.0, dropoff=0.05, years=3)

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

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

🎯 調整後效益(扣除 Deadweight、歸因、移轉、遞減):
  - 節省水資源成本: NT$109108.12
  - 減碳社會效益(估算): NT$161736.75
  - 智慧養殖提升產值: NT$246186.56
  - 地方品牌提升與觀光收益: NT$54633.6
  - 居民生活與文化參與提升: NT$47280.19

💡 SROI = 0.77

2025年4月5日 星期六

USR教材:用水井三寶設計python類別


參考資料:水井姻緣花1

用水井三寶做為提問ChatGPT,獲得下列程式:

 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
# 定義一個基礎寶物類別
class Treasure:
    def __init__(self, name, meaning, age):
        self.name = name
        self.meaning = meaning
        self.age = age

    def describe(self):
        return f"{self.name}:象徵 {self.meaning},已有 {self.age} 年歷史。"

    def __str__(self):
        return self.describe()

# 三寶:烏龜、白馬、番花

class Turtle(Treasure):
    def __init__(self):
        super().__init__("烏龜", "風水與守護", 300)

class WhiteHorse(Treasure):
    def __init__(self):
        super().__init__("白馬", "信仰與傳說", 150)

class Frangipani(Treasure):  # 雞蛋花的英文名稱
    def __init__(self):
        super().__init__("番花", "歷史與生命", 300)

# 建立物件
turtle = Turtle()
horse = WhiteHorse()
flower = Frangipani()

# 顯示介紹(透過 print(object) 直接呼叫 __str__)
print(turtle)
print(horse)
print(flower)

執行結果:
烏龜:象徵 風水與守護,已有 300 年歷史。
白馬:象徵 信仰與傳說,已有 150 年歷史。
番花:象徵 歷史與生命,已有 300 年歷史。

註:這些歷史時間只是ChatGPT對程式的預設值,需要再考證。