← 返回题库
中级

实现屏幕离线自动告警

未完成
中级参考 代码结构已给出,请填写 ____ 处
def solve():
    from pyodide.http import open_url
    from io import StringIO
    import pandas as pd
    hb_csv = open_url(____).read()
    sch_csv = open_url(____).read()
    pl_csv = open_url(____).read()
    hb = pd.read_csv(StringIO(____))
    schedules = pd.read_csv(StringIO(____))
    playback = pd.read_csv(StringIO(____))
    NOW = ____ + ____ * ____
    OFFLINE_TIMEOUT = ____
    SHOULD_PLAY_WINDOW = ____
    latest_hb = hb.sort_values(____).groupby(____).last().reset_index()
    def check_screen(____):
        hb_row = latest_hb[latest_hb['____']==sid]
        last_ts = int(____) if not hb_row.empty else ____
        is_offline = (____) > OFFLINE_TIMEOUT
        has_schedule = len(schedules[(____)&(____)]) > ____
        recent_plays = len(playback[(____)&(____)])
        should_alert = is_offline and has_schedule and recent_plays == ____
        return is_offline, has_schedule, recent_plays, should_alert
    print(____)
    alerts = ____
    for sid in list(latest_hb['____'].unique())[:____]:
        is_off, has_sch, plays, alert = check_screen(____)
        if alert: alerts += ____
        print("____"+sid+"____"+str(____)+"____"+str(____)+"____"+str(____)+"____"+str(____))
    print("____"+str(____))

示例

输入
solve()
期望输出
Offline alert check:
  SCR-0001: offline=True has_sch=False recent_plays=0 alert=False
  SCR-0002: offline=True has_sch=False recent_plays=0 alert=False
  SCR-0003: offline=True has_sch=False recent_plays=0 alert=False
  SCR-0004: offline=True has_sch=False recent_plays=0 alert=False
  SCR-0005: offline=True has_sch=False recent_plays=0 alert=False
  SCR-0006: offline=True has_sch=True recent_plays=0 alert=True
  SCR-0007: offline=True has_sch=False recent_plays=0 alert=False
  SCR-0008: offline=True has_sch=True recent_plays=0 alert=True
  SCR-0009: offline=True has_sch=True recent_plays=0 alert=True
  SCR-0010: offline=True has_sch=False recent_plays=0 alert=False
Total alerts: 3
Python 代码 🔒 登录后使用
🔒

登录后即可练习

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