Update app.py
Browse files
app.py
CHANGED
|
@@ -1,137 +1,337 @@
|
|
|
|
|
| 1 |
import gradio as gr
|
| 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 |
return "์ ๋น"
|
| 29 |
-
|
| 30 |
-
if Q < 0.4 * Qn:
|
| 31 |
return "์ ์ ๋"
|
| 32 |
-
|
| 33 |
-
if Q > 1.2 * Qn or rain >= rain_thr:
|
| 34 |
return "๊ณ ์ ๋"
|
| 35 |
-
# ์ ์
|
| 36 |
return "์ ์"
|
| 37 |
|
| 38 |
-
#
|
| 39 |
-
# ๋ชจ๋๋ณ
|
| 40 |
-
#
|
| 41 |
-
def mode_policy(mode, Q,
|
|
|
|
|
|
|
|
|
|
| 42 |
if mode == "์ ์":
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
return
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
eta =
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
return
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 68 |
return f"""
|
| 69 |
-
<div style="
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 74 |
</div>
|
| 75 |
</div>
|
| 76 |
"""
|
| 77 |
|
| 78 |
-
#
|
| 79 |
-
# ์คํ
|
| 80 |
-
#
|
| 81 |
-
def
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
dp_kpa = float(dp_kpa)
|
| 86 |
-
soc_perc = float(soc_perc)
|
| 87 |
-
except:
|
| 88 |
-
return "โ ๏ธ ์
๋ ฅ ์ค๋ฅ", "", ""
|
| 89 |
|
| 90 |
-
|
| 91 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 92 |
|
| 93 |
summary = (
|
| 94 |
f"**ํ์ฌ ๋ชจ๋**: {mode}\n\n"
|
| 95 |
-
f"- ํ์ฌ ์ ๋ Q: {Q_in:.2f} mยณ/s (์ค๊ณ Qโ={Qn} mยณ/s)\n"
|
| 96 |
f"- ๋์ฐจ H: {Hn:.2f} m\n"
|
| 97 |
-
f"- ๊ฐ์๋: {rain_mm:.1f} mm/24h\n"
|
| 98 |
-
f"- ํธ๋์๋ ฮP: {dp_kpa:.1f} kPa\n"
|
| 99 |
-
f"- ESS SoC: {
|
| 100 |
-
f"โถ {st['
|
| 101 |
)
|
| 102 |
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 107 |
</div>
|
| 108 |
"""
|
|
|
|
| 109 |
|
| 110 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 111 |
|
| 112 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 113 |
# Gradio UI
|
| 114 |
-
#
|
| 115 |
-
with gr.Blocks(theme=gr.themes.Soft()) as
|
| 116 |
-
gr.Markdown("## ๐
|
| 117 |
-
|
| 118 |
-
Q_in = gr.Number(label="ํ์ฌ ์ ๋ Q (mยณ/s)", value=2.0)
|
| 119 |
-
rain_mm = gr.Number(label="๊ฐ์๋ (mm/24h)", value=10)
|
| 120 |
with gr.Row():
|
| 121 |
-
|
| 122 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 123 |
|
| 124 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 125 |
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 129 |
|
| 130 |
-
|
| 131 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 132 |
|
| 133 |
-
# ------------------------------
|
| 134 |
-
# ์คํ ์์
|
| 135 |
-
# ------------------------------
|
| 136 |
if __name__ == "__main__":
|
| 137 |
-
|
|
|
|
| 1 |
+
import time
|
| 2 |
import gradio as gr
|
| 3 |
|
| 4 |
+
# =========================
|
| 5 |
+
# ์ค๊ณ/์๊ณ ๊ธฐ๋ณธ๊ฐ
|
| 6 |
+
# =========================
|
| 7 |
+
DEFAULTS = dict(
|
| 8 |
+
Hn=8.0, # ์ค๊ณ ๋์ฐจ (m)
|
| 9 |
+
Qn=3.5, # ์ค๊ณ ์ ๋ (mยณ/s)
|
| 10 |
+
rain_thr=40.0, # ๊ณ ์ ๋ ํ์ ๊ฐ์๋ (mm/24h)
|
| 11 |
+
dp_limit=3.0, # ํธ๋์๋ ๋งํ ๊ฒฝ๊ณ ์๊ณ (kPa) => ์ ๋น ๋ชจ๋
|
| 12 |
+
soc_limit=90.0, # ESS ๊ณผ์ถฉ์ ์๊ณ (%) => ์ ๋น ๋ชจ๋
|
| 13 |
+
pf_target=0.95, # ๋ชฉํ ์ญ๋ฅ
|
| 14 |
+
rho=1000.0, # ๋ฌผ ๋ฐ๋
|
| 15 |
+
g=9.80665 # ์ค๋ ฅ๊ฐ์๋
|
| 16 |
+
)
|
| 17 |
+
|
| 18 |
+
# =========================
|
| 19 |
+
# ๊ณต์ฉ ํจ์
|
| 20 |
+
# =========================
|
| 21 |
+
def electrical_power_kw(Q, H, eta, rho=DEFAULTS["rho"], g=DEFAULTS["g"]):
|
| 22 |
+
if Q <= 0 or H <= 0 or eta <= 0: return 0.0
|
| 23 |
+
return (rho * g * Q * H * eta)/1000.0
|
| 24 |
+
|
| 25 |
+
def efficiency_from_relative_flow(r):
|
| 26 |
+
# ๊ฐ๋จ ๊ทผ์ฌ: r=Q/Qn (๋ถ๋ถ๋ถํ~์ ๊ฒฉ์์ ์๋ง, ์ ๊ฒฉ ๋์ด๊ฐ๋ฉด ์ํญ ํ๋ฝ)
|
| 27 |
+
r = max(0.0, min(1.3, float(r)))
|
| 28 |
+
pts = [
|
| 29 |
+
(0.00, 0.00), (0.10, 0.40), (0.30, 0.60), (0.50, 0.78),
|
| 30 |
+
(0.70, 0.86), (0.90, 0.90), (1.00, 0.91), (1.20, 0.88), (1.30, 0.85)
|
| 31 |
+
]
|
| 32 |
+
for (x1,y1),(x2,y2) in zip(pts[:-1], pts[1:]):
|
| 33 |
+
if x1 <= r <= x2:
|
| 34 |
+
t = 0 if x2==x1 else (r-x1)/(x2-x1)
|
| 35 |
+
return y1 + t*(y2-y1)
|
| 36 |
+
return 0.0
|
| 37 |
+
|
| 38 |
+
# =========================
|
| 39 |
+
# ๋ชจ๋ ๊ฒฐ์ (์์ฒญ ๊ธฐ์ค)
|
| 40 |
+
# - ์ ๋น: ฮP > dp_limit OR SoC >= soc_limit (์ต์ฐ์ )
|
| 41 |
+
# - ์ ์ ๋: Q < 0.4*Qn
|
| 42 |
+
# - ๊ณ ์ ๋: Q > 1.2*Qn OR rain >= rain_thr
|
| 43 |
+
# - ์ ์: ๋๋จธ์ง
|
| 44 |
+
# =========================
|
| 45 |
+
def decide_mode(Q, Qn, rain, dp, soc, rain_thr, dp_limit, soc_limit):
|
| 46 |
+
if (dp is not None and dp > dp_limit) or (soc is not None and soc >= soc_limit):
|
| 47 |
return "์ ๋น"
|
| 48 |
+
if Q < 0.4*Qn:
|
|
|
|
| 49 |
return "์ ์ ๋"
|
| 50 |
+
if (Q > 1.2*Qn) or (rain >= rain_thr):
|
|
|
|
| 51 |
return "๊ณ ์ ๋"
|
|
|
|
| 52 |
return "์ ์"
|
| 53 |
|
| 54 |
+
# =========================
|
| 55 |
+
# ๋ชจ๋๋ณ ์ด์ ์ ์ฑ
|
| 56 |
+
# =========================
|
| 57 |
+
def mode_policy(mode, Q, Qn, Hn):
|
| 58 |
+
r = Q/Qn if Qn>0 else 0.0
|
| 59 |
+
eta = efficiency_from_relative_flow(r)
|
| 60 |
+
|
| 61 |
if mode == "์ ์":
|
| 62 |
+
eta_eff = max(eta, 0.88)
|
| 63 |
+
p = electrical_power_kw(Q, Hn, eta_eff)
|
| 64 |
+
return dict(eta=eta_eff, p_kw=p, note="์ ์ ์ด์ : ํจ์จ ์ต์ ์ ", vane="์ ๋ ๋น๋ก", gate="์ ๋ ๋น๋ก",
|
| 65 |
+
curtail=False, bypass=False, service=False)
|
| 66 |
+
|
| 67 |
+
if mode == "์ ์ ๋":
|
| 68 |
+
eta_eff = max(0.70, eta*0.95)
|
| 69 |
+
p = electrical_power_kw(Q, Hn, eta_eff)*0.90
|
| 70 |
+
return dict(eta=eta_eff, p_kw=p, note="์ ์ ๋: ์ถ๋ ฅ ์ถ์ยทํจ์จ ์ต์ ํ", vane="15โ55%", gate="15โ55%",
|
| 71 |
+
curtail=False, bypass=False, service=False)
|
| 72 |
+
|
| 73 |
+
if mode == "๊ณ ์ ๋":
|
| 74 |
+
eta_eff = max(0.68, eta*0.9)
|
| 75 |
+
p = electrical_power_kw(Q, Hn, eta_eff)*0.60 # ์ปคํ
์ผ
|
| 76 |
+
return dict(eta=eta_eff, p_kw=p, note="๊ณ ์ ๋: ์ถ๋ ฅ ์ ํยท๋ฐ์ดํจ์ค ๋ณํ", vane="๊ฐ๋ ์ถ์", gate="๊ฐ๋ ์ถ์",
|
| 77 |
+
curtail=True, bypass=True, service=False)
|
| 78 |
+
|
| 79 |
+
if mode == "์ ๋น":
|
| 80 |
+
return dict(eta=0.0, p_kw=0.0, note="์ ๋น: ๋ฐ์ ์ค์งยท์ ๋น ํ์(์คํฌ๋ฆฐ/ESS)", vane="0%", gate="0%",
|
| 81 |
+
curtail=True, bypass=True, service=True)
|
| 82 |
+
|
| 83 |
+
return dict(eta=0.0, p_kw=0.0, note="์ ์ ์๋ ๋ชจ๋", vane="-", gate="-",
|
| 84 |
+
curtail=False, bypass=False, service=False)
|
| 85 |
+
|
| 86 |
+
# =========================
|
| 87 |
+
# ๋ทฐ(UI) ๊ตฌ์ฑ ์์
|
| 88 |
+
# =========================
|
| 89 |
+
def mode_badge(mode:str)->str:
|
| 90 |
+
colors = {
|
| 91 |
+
"์ ์": ("#22c55e","โ"),
|
| 92 |
+
"์ ์ ๋": ("#eab308","โ"),
|
| 93 |
+
"๊ณ ์ ๋": ("#f97316","โ"),
|
| 94 |
+
"์ ๋น": ("#ef4444", None)
|
| 95 |
+
}
|
| 96 |
+
col, dot = colors.get(mode, ("#6b7280","โ"))
|
| 97 |
+
if mode == "์ ๋น":
|
| 98 |
+
icon = """
|
| 99 |
+
<svg width="22" height="22" viewBox="0 0 64 64" style="vertical-align:middle">
|
| 100 |
+
<polygon points="32,6 58,54 6,54" fill="#ef4444" stroke="#b91c1c" stroke-width="3"/>
|
| 101 |
+
<rect x="30" y="22" width="4" height="18" fill="#ffffff" rx="2"/>
|
| 102 |
+
<circle cx="32" cy="46" r="3" fill="#ffffff"/>
|
| 103 |
+
</svg>
|
| 104 |
+
"""
|
| 105 |
+
return f"""
|
| 106 |
+
<div style="padding:10px 14px;border-radius:14px;background:{col};
|
| 107 |
+
color:#fff;font-weight:800;display:inline-flex;gap:10px;align-items:center;">
|
| 108 |
+
{icon}<span>์ ๋น ๋ชจ๋</span>
|
| 109 |
+
</div>"""
|
| 110 |
+
return f"""
|
| 111 |
+
<div style="padding:10px 14px;border-radius:14px;background:{col};
|
| 112 |
+
color:#fff;font-weight:800;display:inline-flex;gap:8px;align-items:center;">
|
| 113 |
+
<span style="font-size:18px">{dot}</span><span>์ด์ ๋ชจ๋ : {mode}</span>
|
| 114 |
+
</div>"""
|
| 115 |
+
|
| 116 |
+
def donut(label:str, value:float, maxv:float, unit:str=""):
|
| 117 |
+
maxv = max(1e-6, maxv)
|
| 118 |
+
pct = max(0.0, min(value/maxv, 1.0))
|
| 119 |
+
r = 42; C = 2*3.14159*r; offset = C*(1-pct)
|
| 120 |
+
return f"""
|
| 121 |
+
<div style="display:flex;flex-direction:column;align-items:center;gap:6px;">
|
| 122 |
+
<svg width="120" height="120" viewBox="0 0 120 120">
|
| 123 |
+
<circle cx="60" cy="60" r="{r}" stroke="#e5e7eb" stroke-width="12" fill="none"/>
|
| 124 |
+
<circle cx="60" cy="60" r="{r}" stroke="#3b82f6" stroke-width="12" fill="none"
|
| 125 |
+
stroke-dasharray="{C:.1f}" stroke-dashoffset="{offset:.1f}"
|
| 126 |
+
stroke-linecap="round" transform="rotate(-90 60 60)"/>
|
| 127 |
+
<text x="60" y="60" text-anchor="middle" dominant-baseline="middle"
|
| 128 |
+
font-size="16" font-weight="700">{value:.1f}{unit}</text>
|
| 129 |
+
</svg>
|
| 130 |
+
<div style="font-size:14px;color:#475569">{label}</div>
|
| 131 |
+
</div>
|
| 132 |
+
"""
|
| 133 |
+
|
| 134 |
+
def chip(label:str, on:bool, on_color="#10b981"):
|
| 135 |
+
bg = on_color if on else "#e5e7eb"
|
| 136 |
+
fg = "#fff" if on else "#111827"
|
| 137 |
+
text = "ON" if on else "OFF"
|
| 138 |
return f"""
|
| 139 |
+
<div style="padding:6px 10px;border-radius:999px;background:{bg};color:{fg};
|
| 140 |
+
font-size:12px;font-weight:700;display:inline-block;">
|
| 141 |
+
{label}: {text}
|
| 142 |
+
</div>
|
| 143 |
+
"""
|
| 144 |
+
|
| 145 |
+
def gauge_bar(label:str, value:float, maxv:float, unit:str=""):
|
| 146 |
+
maxv = max(1e-6, maxv)
|
| 147 |
+
pct = int(round(max(0.0, min(value/maxv,1.0))*100))
|
| 148 |
+
return f"""
|
| 149 |
+
<div style="margin:4px 0 10px 0;">
|
| 150 |
+
<div style="font-size:13px;margin-bottom:4px">{label}: <b>{value:.1f}{unit}</b></div>
|
| 151 |
+
<div style="width:100%;height:10px;border-radius:7px;background:#e5e7eb">
|
| 152 |
+
<div style="width:{pct}%;height:10px;border-radius:7px;background:#6366f1"></div>
|
| 153 |
</div>
|
| 154 |
</div>
|
| 155 |
"""
|
| 156 |
|
| 157 |
+
# =========================
|
| 158 |
+
# ํต์ฌ ์คํ ๋ก์ง
|
| 159 |
+
# =========================
|
| 160 |
+
def _evaluate(Q_in, rain_mm, dp_kpa, soc_pct, Hn, Qn, rain_thr, dp_limit, soc_limit):
|
| 161 |
+
mode = decide_mode(Q_in, Qn, rain_mm, dp_kpa, soc_pct, rain_thr, dp_limit, soc_limit)
|
| 162 |
+
st = mode_policy(mode, Q_in, Qn, Hn)
|
| 163 |
+
p_ref = electrical_power_kw(Qn, Hn, 0.9)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 164 |
|
| 165 |
+
header = mode_badge(mode)
|
| 166 |
+
donuts = f"""
|
| 167 |
+
<div style="display:flex;gap:28px;flex-wrap:wrap;align-items:center">
|
| 168 |
+
{donut("ํจ์จ(ฮท)", st['eta']*100, 100, "%")}
|
| 169 |
+
{donut("์ถ๋ ฅ(kW)", st['p_kw'], max(1.0, p_ref), " kW")}
|
| 170 |
+
</div>
|
| 171 |
+
"""
|
| 172 |
+
|
| 173 |
+
chips = f"""
|
| 174 |
+
<div style="display:flex;gap:8px;flex-wrap:wrap">
|
| 175 |
+
{chip("์ถ๋ ฅ ์ ํ", st['curtail'])}
|
| 176 |
+
{chip("๋ฐ์ดํจ์ค", st['bypass'])}
|
| 177 |
+
{chip("์ ๋น ํ์", st['service'], on_color="#ef4444")}
|
| 178 |
+
</div>
|
| 179 |
+
"""
|
| 180 |
|
| 181 |
summary = (
|
| 182 |
f"**ํ์ฌ ๋ชจ๋**: {mode}\n\n"
|
| 183 |
+
f"- ํ์ฌ ์ ๋ Q: {Q_in:.2f} mยณ/s (์ค๊ณ Qโ={Qn:.2f} mยณ/s)\n"
|
| 184 |
f"- ๋์ฐจ H: {Hn:.2f} m\n"
|
| 185 |
+
f"- ๊ฐ์๋: {rain_mm:.1f} mm/24h (์๊ณ {rain_thr:.0f})\n"
|
| 186 |
+
f"- ํธ๋์๋ ฮP: {dp_kpa:.1f} kPa (์๊ณ {dp_limit:.1f})\n"
|
| 187 |
+
f"- ESS SoC: {soc_pct:.0f}% (์๊ณ {soc_limit:.0f}%)\n\n"
|
| 188 |
+
f"โถ {st['note']}"
|
| 189 |
)
|
| 190 |
|
| 191 |
+
maintenance_html = ""
|
| 192 |
+
if mode == "์ ๋น":
|
| 193 |
+
maintenance_html = """
|
| 194 |
+
<div style="margin-top:8px;padding:10px 12px;border:1px solid #fecaca;border-radius:10px;background:#fef2f2">
|
| 195 |
+
<div style="font-weight:800;color:#b91c1c;margin-bottom:6px">์ ๋น ๋ชจ๋ ํต์ฌ ๋์</div>
|
| 196 |
+
<ul style="margin:0 0 0 16px; padding:0; color:#7f1d1d">
|
| 197 |
+
<li><b>๋ฐ์ OFF</b> (์ถ๋ ฅ 0 kW, ํจ์จ 0)</li>
|
| 198 |
+
<li><b>๊ฐ์ด๋๋ฒ ์ธ/์ทจ์๋ฌธ 0%</b> (๋จ๊ณ์ ๋ซํ)</li>
|
| 199 |
+
<li><b>๋ฐ์ดํจ์ค ON</b> (์์/ํ ํฌ ์์น ๋ฐฉ์ง)</li>
|
| 200 |
+
<li><b>์ ๋น ์๋ด</b>: ์คํฌ๋ฆฐ ์ฒญ์ ๋๋ SoC ๋ฎ์ถ๊ธฐ</li>
|
| 201 |
+
</ul>
|
| 202 |
+
</div>
|
| 203 |
+
"""
|
| 204 |
+
|
| 205 |
+
panel = f"""
|
| 206 |
+
<div style="display:flex;flex-direction:column;gap:14px">
|
| 207 |
+
{header}
|
| 208 |
+
{donuts}
|
| 209 |
+
{chips}
|
| 210 |
+
{maintenance_html}
|
| 211 |
</div>
|
| 212 |
"""
|
| 213 |
+
return summary, panel, ""
|
| 214 |
|
| 215 |
+
def run(Q_in, rain_mm, dp_kpa, soc_pct, Hn, Qn, rain_thr, dp_limit, soc_limit):
|
| 216 |
+
try:
|
| 217 |
+
Q_in=float(Q_in); rain_mm=float(rain_mm); dp_kpa=float(dp_kpa); soc_pct=float(soc_pct)
|
| 218 |
+
Hn=float(Hn); Qn=float(Qn); rain_thr=float(rain_thr); dp_limit=float(dp_limit); soc_limit=float(soc_limit)
|
| 219 |
+
except:
|
| 220 |
+
return "โ ๏ธ ์
๋ ฅ ์ค๋ฅ๋ฅผ ํ์ธํ์ธ์.", "", ""
|
| 221 |
+
return _evaluate(Q_in, rain_mm, dp_kpa, soc_pct, Hn, Qn, rain_thr, dp_limit, soc_limit)
|
| 222 |
|
| 223 |
+
# =========================
|
| 224 |
+
# ํ๋ฆฌ์
(์ฆ์ ์ ํ์ฉ)
|
| 225 |
+
# =========================
|
| 226 |
+
def preset_normal_and_run(Hn, Qn, rain_thr, dp_limit, soc_limit):
|
| 227 |
+
Q = 0.8*float(Qn); rain=10.0; dp=1.0; soc=50.0
|
| 228 |
+
md, panel, extra = _evaluate(Q, rain, dp, soc, float(Hn), float(Qn), float(rain_thr), float(dp_limit), float(soc_limit))
|
| 229 |
+
return Q, rain, dp, soc, md, panel, extra
|
| 230 |
+
|
| 231 |
+
def preset_low_and_run(Hn, Qn, rain_thr, dp_limit, soc_limit):
|
| 232 |
+
Q = 0.3*float(Qn); rain=5.0; dp=1.0; soc=50.0
|
| 233 |
+
md, panel, extra = _evaluate(Q, rain, dp, soc, float(Hn), float(Qn), float(rain_thr), float(dp_limit), float(soc_limit))
|
| 234 |
+
return Q, rain, dp, soc, md, panel, extra
|
| 235 |
+
|
| 236 |
+
def preset_high_and_run(Hn, Qn, rain_thr, dp_limit, soc_limit):
|
| 237 |
+
Q = 1.3*float(Qn); rain=max(50.0, float(rain_thr)); dp=1.0; soc=50.0
|
| 238 |
+
md, panel, extra = _evaluate(Q, rain, dp, soc, float(Hn), float(Qn), float(rain_thr), float(dp_limit), float(soc_limit))
|
| 239 |
+
return Q, rain, dp, soc, md, panel, extra
|
| 240 |
+
|
| 241 |
+
def preset_maint_and_run(Hn, Qn, rain_thr, dp_limit, soc_limit):
|
| 242 |
+
# ์ ๋น ๋ชจ๋: ์คํฌ๋ฆฐ ๋งํ์ผ๋ก ์ ๋(ฮP > dp_limit)
|
| 243 |
+
Q = 0.8*float(Qn); rain=10.0; dp=float(dp_limit)+0.5; soc=50.0
|
| 244 |
+
md, panel, extra = _evaluate(Q, rain, dp, soc, float(Hn), float(Qn), float(rain_thr), float(dp_limit), float(soc_limit))
|
| 245 |
+
return Q, rain, dp, soc, md, panel, extra
|
| 246 |
+
|
| 247 |
+
# =========================
|
| 248 |
+
# ์๋ ์๋ฎฌ๋ ์ด์
(2์ด ๊ฐ๊ฒฉ)
|
| 249 |
+
# =========================
|
| 250 |
+
def autoplay(Hn, Qn, rain_thr, dp_limit, soc_limit):
|
| 251 |
+
steps = [
|
| 252 |
+
("์ ์", preset_normal_and_run(Hn, Qn, rain_thr, dp_limit, soc_limit)),
|
| 253 |
+
("์ ์ ๋", preset_low_and_run(Hn, Qn, rain_thr, dp_limit, soc_limit)),
|
| 254 |
+
("๊ณ ์ ๋", preset_high_and_run(Hn, Qn, rain_thr, dp_limit, soc_limit)),
|
| 255 |
+
("์ ๋น", preset_maint_and_run(Hn, Qn, rain_thr, dp_limit, soc_limit)),
|
| 256 |
+
]
|
| 257 |
+
for _, tup in steps:
|
| 258 |
+
Q, rain, dp, soc, md, panel, extra = tup
|
| 259 |
+
yield (Q, rain, dp, soc, md, panel, extra)
|
| 260 |
+
time.sleep(2.0)
|
| 261 |
+
|
| 262 |
+
# =========================
|
| 263 |
# Gradio UI
|
| 264 |
+
# =========================
|
| 265 |
+
with gr.Blocks(theme=gr.themes.Soft(), title="์์๋ ฅ ์ค๋งํธ ์ด์ ๋ชจ๋ ๋์๋ณด๋ (์ ์/์ ์ ๋/๊ณ ์ ๋/์ ๋น)") as app:
|
| 266 |
+
gr.Markdown("## ๐ ์์๋ ฅ ์ค๋งํธ ์ด์ ๋ชจ๋ ๋์๋ณด๋")
|
| 267 |
+
|
|
|
|
|
|
|
| 268 |
with gr.Row():
|
| 269 |
+
with gr.Column(scale=1):
|
| 270 |
+
Q_in = gr.Number(label="ํ์ฌ ์ ๋ Q (mยณ/s)", value=2.0)
|
| 271 |
+
rain = gr.Number(label="๊ฐ์๋ (mm/24h)", value=10)
|
| 272 |
+
dp = gr.Number(label="ํธ๋์๋ ฮP (kPa)", value=1.0)
|
| 273 |
+
soc = gr.Number(label="ESS SoC (%)", value=50)
|
| 274 |
+
|
| 275 |
+
with gr.Accordion("๊ณ ๊ธ ์ค์ (์ค๊ณ/์๊ณ๊ฐ)", open=False):
|
| 276 |
+
with gr.Row():
|
| 277 |
+
Hn = gr.Number(label="์ค๊ณ ๋์ฐจ Hโ (m)", value=DEFAULTS["Hn"])
|
| 278 |
+
Qn = gr.Number(label="์ค๊ณ ์ ๋ Qโ (mยณ/s)", value=DEFAULTS["Qn"])
|
| 279 |
+
with gr.Row():
|
| 280 |
+
rain_thr = gr.Number(label="๊ณ ์ ๋ ํ๋จ ๊ฐ์ฐ ์๊ณ (mm/24h)", value=DEFAULTS["rain_thr"])
|
| 281 |
+
dp_limit = gr.Number(label="ฮP ์๊ณ (kPa, ์ ๋น)", value=DEFAULTS["dp_limit"])
|
| 282 |
+
soc_limit = gr.Number(label="ESS SoC ์๊ณ (% , ์ ๋น)", value=DEFAULTS["soc_limit"])
|
| 283 |
+
|
| 284 |
+
run_btn = gr.Button("์๋ฎฌ๋ ์ด์
์คํ", variant="primary")
|
| 285 |
+
|
| 286 |
+
gr.Markdown("### ๐ ๋น ๋ฅธ ์ ํ (์๋ ๋ฒํผ์ ๋๋ฅด๋ฉด **์ฆ์** ํด๋น ๋ชจ๋๋ก ์ธํ
+ ์คํ)")
|
| 287 |
+
with gr.Row():
|
| 288 |
+
btn_norm = gr.Button("์ ์", variant="secondary")
|
| 289 |
+
btn_low = gr.Button("์ ์ ๋", variant="secondary")
|
| 290 |
+
btn_high = gr.Button("๊ณ ์ ๋", variant="secondary")
|
| 291 |
+
btn_maint= gr.Button("์ ๋น", variant="stop")
|
| 292 |
+
|
| 293 |
+
demo_btn = gr.Button("๐ฌ ์๋ ์์ฐ (์ ์ โ ์ ์ ๋ โ ๊ณ ์ ๋ โ ์ ๋น, 2์ด ๊ฐ๊ฒฉ)")
|
| 294 |
+
|
| 295 |
+
with gr.Column(scale=2):
|
| 296 |
+
out_md = gr.Markdown()
|
| 297 |
+
out_vis = gr.HTML()
|
| 298 |
+
out_extra = gr.HTML()
|
| 299 |
|
| 300 |
+
# ์คํ ๋ฒํผ
|
| 301 |
+
run_btn.click(
|
| 302 |
+
fn=run,
|
| 303 |
+
inputs=[Q_in, rain, dp, soc, Hn, Qn, rain_thr, dp_limit, soc_limit],
|
| 304 |
+
outputs=[out_md, out_vis, out_extra]
|
| 305 |
+
)
|
| 306 |
|
| 307 |
+
# ์ฆ์ ์ ํ ๋ฒํผ๋ค (์
๋ ฅ์นธ๋ ํจ๊ป ์
๋ฐ์ดํธ)
|
| 308 |
+
btn_norm.click(
|
| 309 |
+
fn=preset_normal_and_run,
|
| 310 |
+
inputs=[Hn, Qn, rain_thr, dp_limit, soc_limit],
|
| 311 |
+
outputs=[Q_in, rain, dp, soc, out_md, out_vis, out_extra]
|
| 312 |
+
)
|
| 313 |
+
btn_low.click(
|
| 314 |
+
fn=preset_low_and_run,
|
| 315 |
+
inputs=[Hn, Qn, rain_thr, dp_limit, soc_limit],
|
| 316 |
+
outputs=[Q_in, rain, dp, soc, out_md, out_vis, out_extra]
|
| 317 |
+
)
|
| 318 |
+
btn_high.click(
|
| 319 |
+
fn=preset_high_and_run,
|
| 320 |
+
inputs=[Hn, Qn, rain_thr, dp_limit, soc_limit],
|
| 321 |
+
outputs=[Q_in, rain, dp, soc, out_md, out_vis, out_extra]
|
| 322 |
+
)
|
| 323 |
+
btn_maint.click(
|
| 324 |
+
fn=preset_maint_and_run,
|
| 325 |
+
inputs=[Hn, Qn, rain_thr, dp_limit, soc_limit],
|
| 326 |
+
outputs=[Q_in, rain, dp, soc, out_md, out_vis, out_extra]
|
| 327 |
+
)
|
| 328 |
|
| 329 |
+
# ์๋ ์์ฐ (2์ด ๊ฐ๊ฒฉ์ผ๋ก ๋จ๊ณ์ ์ถ๋ ฅ + ์
๋ ฅ์นธ ๋์ ์
๋ฐ์ดํธ)
|
| 330 |
+
demo_btn.click(
|
| 331 |
+
fn=autoplay,
|
| 332 |
+
inputs=[Hn, Qn, rain_thr, dp_limit, soc_limit],
|
| 333 |
+
outputs=[Q_in, rain, dp, soc, out_md, out_vis, out_extra]
|
| 334 |
+
)
|
| 335 |
|
|
|
|
|
|
|
|
|
|
| 336 |
if __name__ == "__main__":
|
| 337 |
+
app.launch()
|