← 返回题库
中级

实现单指标阈值告警触发

未完成
中级参考 代码结构已给出,请填写 ____ 处
def solve():
    from pyodide.http import open_url
    from io import StringIO
    import pandas as pd
    st_csv = open_url(____).read()
    alerts_csv = open_url(____).read()
    st = pd.read_csv(StringIO(____))
    alerts = pd.read_csv(StringIO(____))
    ranges = {r['____']:(____) for _,r in st.iterrows()}
    def check_threshold(____):
        if metric not in ranges: return None
        lo, hi = ranges[metric]
        if value > hi: return {'____':'____','____':device_id,'____':metric,'____':value,'____':hi}
        if value < lo: return {'____':'____','____':device_id,'____':metric,'____':value,'____':lo}
        return None
    test_readings = [
        (____),(____),(____),
        (____),(____),
    ]
    print(____)
    for did, metric, value in test_readings:
        alert = check_threshold(____)
        if alert:
            print("____"+did+"____"+metric+"____"+str(____)+"____"+str(____))
        else:
            print("____"+did+"____"+metric+"____"+str(____))
    print("____"+str(len(____)))

示例

输入
solve()
期望输出
Threshold alerts:
  OK ESP-001/vibration_rms=18.7
  ALERT ESP-002/pressure=1210.0 threshold=1200.0
  OK RPI-001/cpu_temp=88.0
  OK ARD-001/temperature=25.0
  OK RPI-003/cpu_temp=55.0
Existing alerts: 5
Python 代码 🔒 登录后使用
🔒

登录后即可练习

注册免费账号,在浏览器中直接运行 Python 代码