← 返回题库
中级

实现设备资源HATEOAS链接

未完成
中级参考 代码结构已给出,请填写 ____ 处
def solve():
    from pyodide.http import open_url
    from io import StringIO
    import pandas as pd, json
    devs_csv = open_url(____).read()
    devs = pd.read_csv(StringIO(____))
    def device_with_links(____):
        did = row['____']
        base = f'____'
        obj = row[['____','____','____','____']].to_dict()
        obj['____'] = {'____':{'____':base},'____':{'____':f'____','____':'____'},
            '____':{'____':f'____'},'____':{'____':f'____'}}
        return obj
    for _, row in devs.head(____).iterrows():
        print(json.dumps(device_with_links(____), ensure_ascii=False, indent=____))

示例

输入
solve()
期望输出
{
  "device_id": "DEV001",
  "device_name": "A车间温湿度-01",
  "device_type": "temperature",
  "status": "online",
  "_links": {
    "self": {
      "href": "/api/v1/devices/DEV001"
    },
    "data": {
      "href": "/api/v1/devices/DEV001/data",
      "method": "POST"
    },
    "status": {
      "href": "/api/v1/devices/DEV001/status"
    },
    "commands": {
      "href": "/api/v1/devices/DEV001/commands"
    }
  }
}
{
  "device_id": "DEV002",
  "device_name": "A车间温湿度-02",
  "device_type": "temperature",
  "status": "online",
  "_links": {
    "self": {
      "href": "/api/v1/devices/DEV002"
    },
    "data": {
      "href": "/api/v1/devices/DEV002/data",
      "method": "POST"
    },
    "status": {
      "href": "/api/v1/devices/DEV002/status"
    },
    "commands": {
      "href": "/api/v1/devices/DEV002/commands"
    }
  }
}
Python 代码 🔒 登录后使用
🔒

登录后即可练习

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