← 返回题库
中级

检测传感器读数卡死(Stuck Value)

未完成
中级参考 代码结构已给出,请填写 ____ 处
def solve():
    from pyodide.http import open_url
    from io import StringIO
    import pandas as pd
    st_csv = open_url(____).read()
    st = pd.read_csv(StringIO(____))
    stuck_thresholds = {r['____']:r['____'] for _,r in st.iterrows()}
    readings = [
        (____),(____),(____),
        (____),(____),(____),
        (____),(____),
        (____),(____),(____),
    ]
    def detect_stuck(____):
        threshold = int(stuck_thresholds.get(____))
        if len(____) < threshold: return False, ____
        last_n = values[-threshold:]
        return len(set(____)) == ____, threshold
    by_device = {}
    for did, metric, val in readings:
        key = (____)
        by_device.setdefault(____).append(____)
    for (____), vals in by_device.items():
        stuck, n = detect_stuck(____)
        flag = "____" + str(____) + "____" if stuck else "____"
        print(did + "____" + metric + "____" + flag + "____" + str(____))

示例

输入
solve()
期望输出
ARD-002/temperature: STUCK (consecutive=8) values=[25.0, 25.0, 25.0, 25.0, 25.0]
ARD-001/temperature: ok values=[24.5, 24.7, 25.0]
Python 代码 🔒 登录后使用
🔒

登录后即可练习

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