← 返回题库
中级

实现设备状态缓存预热

未完成
中级参考 代码结构已给出,请填写 ____ 处
def solve():
    from pyodide.http import open_url
    from io import StringIO
    import pandas as pd, json
    snap_csv = open_url(____).read()
    devs_csv = open_url(____).read()
    snaps = pd.read_csv(StringIO(____))
    devs = pd.read_csv(StringIO(____))
    cache = {}
    def warm_cache(____):
        warmed = ____
        for _, row in snapshots_df.iterrows():
            key = f"____"
            cache[key] = {'____': json.loads(____), '____': row['____'], '____': row['____']}
            warmed += ____
        return warmed
    warmed = warm_cache(____)
    print(____)
    for key, val in list(cache.items())[:____]:
        print(____)
    all_devices = set(____)
    cached_devices = {k.split(____)[____] for k in cache}
    not_warmed = all_devices - cached_devices
    print(____)

示例

输入
solve()
期望输出
缓存预热: 6个设备状态
  device:DEV001:latest: version=4, etag="3725fd70e4a...
  device:DEV002:latest: version=5, etag="21b0ca8fa14...
  device:DEV003:latest: version=1, etag="6cdfef13752...
未预热: 4台 {'DEV009', 'DEV008', 'DEV010', 'DEV007'}
Python 代码 🔒 登录后使用
🔒

登录后即可练习

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