Classroom-示例4:下发判题并查询判题结果以及下载结果:操作步骤

时间:2025-01-26 10:34:08

操作步骤

  1. 下发判题任务。

    • 接口信息

      URI:GET /v1/enablement/judgements

      API文档详情请参见:下发判题任务

      API Explorer 在线调试请参见:下发判题任务

    • 说明
      • 输出类型为文件生成类型时(output_type为fileout),不需要指定生成路径,程序会将标准输出的输出流写入文件并返回文件id。
      • 输出类型为图片生成类型时(output_type为imgout), 需要指定生成路径,并且须生成在目录"/projects/output/"下,程序会返回图片的id。
    • 请求示例
      POST  https://classroom-ext.cn-north-4.myhuaweicloud.com/v1/enablement/judgements
    • 响应示例
      {"notify_url": "https://117.12.143.1/taskBack","code_type": "inline","source_code": "aW1wb3J0IG9zCnByaW50KCIyMDIxLTA3LTE0Iik=","description": "java code","runtime_type": "java","timeout": 60,"output_type": "sysout"}

  1. 根据判题任务id查询判题结果。

    • 接口信息

      URI:GET v1/enablement/judgements/{judgement_id}

      API文档详情请参见:获取判题结果详情

      API Explorer在线调试请参见:获取判题结果详情

    • 请求示例
      GET  https://classroom-ext.cn-north-4.myhuaweicloud.com/v1/enablement/judgements/933b85316de54cea9e650d5f4f6b7ad2
    • 响应示例
      {    "task_status": "callback_success",    "status": "compile_error",    "judgement_id": "933b85316de54cea9e650d5f4f6b7ad2",    "start_time": "2021-07-15 19:49:22",    "end_time": "2021-07-15 19:49:28",    "result": {        "output": "java sysout",                                  // 下发判题时output_type为sysout或代码出错时只会返回output字段        "file_id": "b47e7d4e-ae9e-43a2-a452-c2aa6bfb5ee9.txt",    // 下发判题时output_type为fileout只会返回file_id字段        "image_id": "94737d4e-ae9e-43a2-9702-bda76bfb5ee9.png"    // 下发判题时output_type为imgout只会返回image_id字段        "testcases": [                                            // 下发判题时output_type为caseout或judgeout只会返回testcases字段            {                "input": "10 20",                "output": "30"            }           ]    }}

  1. 下载判题结果文件

    • 接口信息

      URI:GET /v1/enablement/judgement/files/{file_id}

      API文档详情请参见:获取判题结果详情

      API Explorer在线调试请参见:下载判题结果文件

    • 请求示例
      GET  https://classroom-ext.cn-north-4.myhuaweicloud.com/v1/enablement/judgement/files/b47e7d4e-ae9e-43a2-a452-c2aa6bfb5ee9.txt
    • 响应示例

    文件流的形式返回。

support.huaweicloud.com/api-classroom/classroom_03_1015.html