Skip to content

Ego Vehicle / Test Suite / Map / Judgment / Result Example

9. Ego Vehicle Operations

9.1 Import Ego Vehicle

API
"""
def delete_sessions_api(self, payload: dict):
    """
    Sessions delete API
    @param payload: eg  {"ids":["f9e096f6-78ff-431a-a5e2-24a2de4117df"]}
    @return:
    """
    return self.send(self.post, delete_sessions_url, json=payload).json()

def delete_task_api(self, payload: dict):
    """
    Task delete API
    @param payload: eg  {"ids":["f9e096f6-78ff-431a-a5e2-24a2de4117df"]}
    @return:
    """
    return self.send(self.post, delete_task_url, json=payload).json()

"""
Implementation
class File:
    """
    File parent class
    """

    def __init__(self, file_path: str):
        if not exists(file_path):
            raise FileNotFoundError
        self._file_path = file_path
        self._data = None
class FileReader(File):
    """
    Read file
    """

    def __init__(self, file_path: str):
        super(FileReader, self).__init__(file_path)

    def read_byte(self) -> bytes:
        with open(self._file_path, 'rb') as f:
            return f.read()

    def read_str(self) -> str:
        with open(self._file_path, 'r', encoding='utf-8') as f:
            return f.read()

    def read_json(self) -> json:
        with open(self._file_path, 'r', encoding='utf-8') as f:
            return json.load(f)

def import_vehicle_api(self,payload:dict):
    """
        Import Ego Vehicle
        @param payload: eg {"vehicleData": {"byId": {vehicle_id: vehicle_data},
                                      "allIds": [vehicle_id]}}
        @return:
    """
    return self.send(self.post,import_vehicle_url,json=payload).json()

def get_vehicle_data(file_path: str):
    vehicle_info = FileReader(file_path).read_json()
    vehicle_id = vehicle_info.get("id")
    return vehicle_info, vehicle_id

def import_vehicle(self, file_path:str)->str:
    """
    Import Ego Vehicle
    @param file_path: Ego Vehicle file
    @return: Ego Vehicle ID
    """
    vehicle_data,vehicle_id = self.get_vehicle_data(file_path)
    payload = {"vehicleData": {"byId": {vehicle_id: vehicle_data},
                                        "allIds": [vehicle_id]}}
    result = self.import_vehicle_api(payload)
    return result["data"]["id"]

def main(suite_name:str=None):
    suite = Suite()
    # suite.get_suite(suite_name)
    suite.import_vehicle('c:/test.json')
Usage Example
SimOneUrl = "http://172.31.9.85:30083/"
loginData = {
    "username": 'admin',
    "password": 'admin',
}
LoginPolicy("standalone")
if __name__ == '__main__':
     main()
Return Value
{'method': 'POST', 'url': 'http://172.31.9.85:30083/api-task/sessions/delete', 'headers': {'Content-Type': 'application/json', 'Authorization': '5a3662a3-2fbb-4790-b40d-42f600e63801'}, 'json': {'ids': ['bc344bf1-4bd3-493e-a4d3-95f98dcc3e48']}}
response:{"code":0,"data":{}}
{'method': 'POST', 'url': 'http://172.31.9.85:30083/api-task/tasks/delete', 'headers': {'Content-Type': 'application/json', 'Authorization': '5a3662a3-2fbb-4790-b40d-42f600e63801'}, 'json': {'ids': ['18a0fafe-d1e2-404b-b5e8-b4f3ea4c8e86']}}
response:{"code":0,"msg":"success"}

9.2 Delete Ego Vehicle

API
"""
def delete_vehicles_api(self, vehicles_id: str):
    """
    Delete Ego Vehicle
    @param vehicles_id: Ego Vehicle ID
    @return:
    """
    url = self.delete_vehicle_url.format(vehicles_id=vehicles_id)
    return self.send(self.delete, url)

"""
Implementation
    def delete_vehicles_api(self, vehicles_id: str):
        """
        Delete Ego Vehicle
        @param vehicles_id: Ego Vehicle ID
        @return:
        """
        url = delete_vehicle_url.format(vehicles_id=vehicles_id)
        return self.send(self.delete, url)

    def delete_vehicle(self,id:str):
        """
        Delete Ego Vehicle
        @param id: Ego Vehicle ID
        @return:
        """
        self.delete_vehicles_api(id)
def main(category_name:str,case_name:str=None,vehicle_name:str=None):
    suite = Suite()
    suite.get_category()
    cate_id = suite.get_category()
    cate_name = [cate_id["data"][category_name]]
    cases_dict, case_id_list = suite.get_cases_category(cate_name)
    print(case_name)
    # Ego Vehicle control logic
    if vehicle_name:
        vehicle_dict = suite.get_vehicle_id([vehicle_name])[1]
        if vehicle_name not in vehicle_dict.keys():
            print(f"vehicle_name:{vehicle_name} does not exist")
            return
        vehicle_id = vehicle_dict[vehicle_name]
    else:
        vehicle_id = None
    print(f"vehicle_name:{vehicle_name},vehicle_id:{vehicle_id}")
    suite.delete_vehicle(vehicle_id)
Usage Example
SimOneUrl = "http://172.31.9.85:30083/"
loginData = {
    "username": 'admin',
    "password": 'admin',
}
LoginPolicy("standalone")
if __name__ == '__main__':
    main("Turn Conflict", "Turn Conflict 8", "test")
Return Value

No Return Value

9.3 Get Ego Vehicle Information

API
"""
def get_vehicle_api(self):
    """
    Get Ego Vehicle Information
    @return:
    """
    return self.send(self.get,self.get_vehicle_url).json()

"""
Implementation
    def get_vehicle_api(self):
        """
        Get Ego Vehicle Information
        @return:
        """
        return self.send(self.get, get_vehicle_url).json()


    def get_vehicle(self, userid: str = None):
        """
        Get Ego Vehicle Information Based on User Information
        @param userid:
        @return:
        """
        global vehicle_data
        vehicle_data = {}
        res = self.get_vehicle_api()
        # print(f"get_vehicle_api response ->: {res}")
        data = res["data"]["list"]["byId"]
        id_list = res["data"]["list"]["allIds"]
        if userid:
            for id in id_list:
                if data[id]["userId"] == userid:
                    vehicle_data.setdefault(data[id]["name"], data[id]["id"])
        else:
            for id in id_list:
                vehicle_data.setdefault(data[id]["userId"], {}).update({data[id]["name"]: data[id]["id"]})
        print("Obtained Ego Vehicle Information->:{}".format(str(vehicle_data)))
        return vehicle_data

    def get_vehicle_id(self, vehicle_name: list) -> list and dict:
        """
        Get Ego Vehicle ID Based on Ego Vehicle Name
        @param vehicle_name:
        @return:
        """
        vehicle_id_dict = {}
        vehicle_id_list = []
        vehicle_list = []
        for i in vehicle_name:
            for k, v in self.get_vehicle().items():
                vehicle_list.append(v)
            for vehicle_dict in vehicle_list:
                # print("vehicle_dict", vehicle_dict)
                vehicle_dict_key = dict(vehicle_dict).items()
                for vehicle_dict_k, vehicle_dict_v in vehicle_dict_key:
                    if i in vehicle_dict_k:
                        vehicle_name_id = vehicle_dict[i]
                        vehicle_id_list.append(vehicle_name_id)
                        vehicle_id_dict.setdefault(i, vehicle_name_id)

        print("vehicle_id_list->:", vehicle_id_list, "\nvehicle_id_dict->:", vehicle_id_dict)
        return vehicle_id_list, vehicle_id_dict



def main(category_name:str,case_name:str=None,vehicle_name:str=None):
    suite = Suite()
    suite = Suite()
    suite.get_category()
    cate_id = suite.get_category()
    cate_name = [cate_id["data"][category_name]]
    cases_dict, case_id_list = suite.get_cases_category(cate_name)

    # Ego Vehicle control logic
    if vehicle_name:
        vehicle_dict = suite.get_vehicle_id([vehicle_name])[1]
        if vehicle_name not in vehicle_dict.keys():
            print(f"vehicle_name:{vehicle_name} does not exist")
            return
        vehicle_id = vehicle_dict[vehicle_name]
    else:
        vehicle_id = None
    print(f"vehicle_name:{vehicle_name},vehicle_id:{vehicle_id}")

    # Case name logic
    if case_name:
        case_id_list = cases_dict[case_name]
        print(f" case_name:{case_name}")

    # Start case
    session_id, task_ids = suite.run_task(case_id_list, vehicle_id=vehicle_id)
Usage Example
SimOneUrl = "http://172.31.9.85:30083/"
loginData = {
    "username": 'admin',
    "password": 'admin',
}
LoginPolicy("standalone")
if __name__ == '__main__':
    main("Turn Conflict", "Turn Conflict 8", "Manual Control - Default")
Return Value
{'method': 'GET', 'url': 'http://172.31.9.85:30083/api-asset/vehicles', 'headers': {'Content-Type': 'application/json', 'Authorization': 'e5033d43-2368-4fd0-9c4b-299c4d3ba8d9'}}

10. Test Suite Operations

10.1 Get Test Suite

API
"""
def get_suite_api(self, isProjectItem : str):
    """
    @param isProjectItem : True(team) or False(personal)
    @return:

    """
    url = get_suites_url.format(isProjectItem)
    return self.send(self.get, url=url).json()

"""
Run Test Suite
    def get_suite_api(self, isProjectItem : bool):
        """
        @param isProjectItem : True(team) or False(personal)
        @return:

        """
        url = get_suites_url.format(isProjectItem)
        return self.send(self.get, url=url).json()

    def get_suite(self, suite_name: str = None , isProjectItem : bool = True):
        """
        @param isProjectItem : true(team) or false(personal)
        :return:
        """
        if  isProjectItem: isProjectItem = "true" 
        else: isProjectItem = "false"

        response = self.get_suite_api(isProjectItem)
        data = response['data']
        suite_dict = {}
        for id in data['allIds']:
            suite_dict.setdefault(data['byId'][id]['name'], {}).update({"caseIds": data['byId'][id]['caseIds']})
        print("suite_dict", suite_dict)
        try : 
            if not suite_name:
                return suite_dict
            else:
                # print("suite_dict[suite_name]:",suite_dict[suite_name])
                return suite_dict[suite_name]
        except Exception as e:
            print("suite_name does not exist")

def main(suite_name:str=None):
    suite = Suite()
    suite.get_suite(suite_name)
Usage Example
SimOneUrl = "http://172.31.9.85:30083/"
loginData = {
    "username": 'admin',
    "password": 'admin',
}
LoginPolicy("standalone")
if __name__ == '__main__':
    main("suite_name" , True)
Return Value
response:{"code":0,"data":{"byId":{"ea6d0670-0db5-11ef-98b6-f5137907bac2":{"schema":"suite","id":"ea6d0670-0db5-11ef-98b6-f5137907bac2","userId":"standalone","parentId":"","name":"test","created":1715226044506,"lastModified":1715226044506,"createUserRole":1,"caseIds":["f5bbfb2c-619a-4812-90c2-75a84247a4db"]}},"allIds":["ea6d0670-0db5-11ef-98b6-f5137907bac2"]}}
suite_dict {'test': {'caseIds': ['f5bbfb2c-619a-4812-90c2-75a84247a4db']}}

10.2 Run Test Suite

API
"""
def get_suite_api(self):
    """
    get_suite
    @return:
    """
    return self.send(self.get, url=get_suites_url).json()

def run_suite_api(self, payload:dict):
    """
    run_suite
    @param payload: payload
    @return:
    """
    return self.send(self.post, url=self.run_suite_url, json=payload).json()

"""
Implementation
    def get_suite_api(self):
        """
        get_suite
        @return:
        """
        return self.send(self.get, url=get_suites_url).json()


    def get_suite(self,suite_name:str=None):
        """
        :return:
        """
        response = self.get_suite_api()
        data = response['data']
        suite_dict = {}
        for id in data['allIds']:
            suite_dict.setdefault(data['byId'][id]['name'], {}).update({"caseIds": data['byId'][id]['caseIds']})
        print("suite_dict",suite_dict)
        if not suite_name:
            return suite_dict
        else:
            #print("suite_dict[suite_name]:",suite_dict[suite_name])
            return suite_dict[suite_name]

    def run_suite_api(self, payload: dict):
        """
        run_suite
        @param payload: payload
        @return:
        """
        return self.send(self.post, url=run_suite_url, json=payload).json()


    def run_suite(self, suite_name: str, taskName: str = None, vehicle_id: str = None):
        if taskName is None:
            def creat_task_name():
                return "taskName_" + time.strftime("%Y-%m-%d_%H:%M:%S", time.localtime())

            taskName = creat_task_name()
        caseid_list = self.get_suite(suite_name)['caseIds']
        payload = {
            'caseIds': caseid_list,
            'taskName': taskName,
            "type" : "worldsim",
            "enableStateMachine" : False,
            "vehicleConfig" : {
                "Ego" : {
                    "instanceId" : "Ego" ,
                    "id" : "default",
                    "name" : "Ego Vehicle",
                    "classId" :"MKZ",
                    "algorithms" : [
                        {
                        "id" : "Default",
                         "name" : "Default Controller",
                         "algorithmId": "SimOneDriver",
                         }
                    ]
                }
            },
            "withEvaluation" : False
        }
        if vehicle_id:
            # vehicle_module = VehicleBusiness()
            # vehicle_module.get_vehicle()
            payload.update({"overrideVehicleId": vehicle_id})
        response = self.run_suite_api(payload)
        data = response['data']
        return data['sessionId'], data['taskIds']

def main(suite_name:str=None):
    suite = Suite()
    # suite.get_suite(suite_name)
    suite.run_suite(suite_name)
Usage Example
SimOneUrl = "http://172.31.9.85:30083/"
loginData = {
    "username": 'admin',
    "password": 'admin',
}
LoginPolicy("standalone")
if __name__ == '__main__':
    main("test")
Return Value
{'method': 'POST', 'url': 'http://172.31.9.85:30083/api-task/tasks', 'headers': {'Content-Type': 'application/json', 'Authorization': '7d4c315b-dbd1-4f4b-8552-ff66be9346ec'}, 'json': {'caseIds': ['f5bbfb2c-619a-4812-90c2-75a84247f4db'], 'taskName': 'taskName_2024-05-09_11:49:56'}}
response:{"code":0,"data":{"sessionId":"5b4fc9fb-8da4-42f4-8eef-7e4522b85dd4","taskIds":["0b933b59-b4d6-49e8-b656-de52a8561fb6"]}}

10.3 Get Runtime Test Suite Information

API
"""
def suite_queue_api(self):
    """
    suite_queue
    @return:
    """
    return self.send(self.get, url=self.queue_status_url).json()

"""
Implementation
    def suite_queue_api(self):
        """
        suite_queue
        @return:
        """
        return self.send(self.get, url=queue_status_url).json()


    def suite_queue_check(self,n=10):
        """
        @param n:cycle index
        @return:
        """
        if n==1:
            print("-----------------------The test case run fail--------------------------------------")
            return False
        while(1):
            try:
                assert self.suite_queue_api()
                response = self.suite_queue_api()
                assert response["code"]==0
            except Exception as e:
                return -1
            queue_info = response["data"]
            running,pending,waiting = queue_info["running"],queue_info["pending"],queue_info["waiting"]

            if running == 0 and pending == 0 and waiting == 0:
                print("-----------------------The test case run finish--------------------------------------")
                return True
            else:
                time.sleep(interval)

def main(suite_name:str=None):
    suite = Suite()
    # suite.get_suite(suite_name)
    suite.run_suite(suite_name)
    suite.suite_queue_check()
Usage Example
SimOneUrl = "http://172.31.9.85:30083/"
loginData = {
    "username": 'admin',
    "password": 'admin',
}
LoginPolicy("standalone")
if __name__ == '__main__':
    main("test")
Return Value
{'method': 'GET', 'url': 'http://172.31.9.85:30083/api-task/tasks/queue?own=true', 'headers': {'Content-Type': 'application/json', 'Authorization': 'f083c671-f6fe-4d64-b775-3f0539eca7c9'}}
response:{"code":0,"data":{"total":2,"running":1,"pending":1,"waiting":1,"finished":0,"estimatedTaskDuration":87.22495652173913}}

10.4 Get task_id in the Task Set

API
"""
def get_taskassemble_api(self):
    '''
    Get Test Suite
    @param
    @return:
    '''
    return self.send(self.get, get_taskassemble_url).json()
"""
Implementation
    def get_taskassemble_api(self, task_set_id):
        '''
        Get Test Suite
        @param
        @return:
        '''
        return self.send(self.get, get_taskassemble_url.format(task_set_id=task_set_id)).json()
    def get_task_id_of_task_set(self, task_set_id: str) -> list:
        """
        Get task_id of all Use Cases in the Task Set
        @param task_set_id: Task Set ID
        @return: list
        """
        response = self.get_taskassemble_api(task_set_id)
        _task_id_list = response["data"]["list"]
        # print("---------------------------------task_id_list-----------------------")
        # print(_task_id_list)
        index = 0
        task_id_list = []
        for i in _task_id_list:
            index += 1
            # print(f"------------------------Element {index}----------------")
            # print(i)
            if i['parentId'] == task_set_id:
                # print(i)
                task_id_list.append(i["id"])
        # print("task_id_list",task_id_list)
        return task_id_list
def main(suite_name:str=None):
    suite = Suite()
    res = suite.run_suite(suite_name)
    suite.get_task_id_of_task_set(res[1])
Usage Example
SimOneUrl = "http://172.31.9.85:30083/"
loginData = {
    "username": 'admin',
    "password": 'admin',
}
LoginPolicy("standalone")
if __name__ == '__main__':
    main("test")
Return Value
task_set_id_list  [id1,id2,...]

11. Map Operations

11.1 Import Map

API
"""
def import_map_api(self, payload: dict, files: dict):
    """
    Import Map API
    @param payload: parameter dict
    @param files: files to upload
    @return:
    """
    self.headers = {"projectId": "default"}
    return self.send(self.post, import_map_url, data=payload, files=files).json()
"""
Implementation
    def import_map_api(self, payload: dict, files: dict):
        """
        Import Map API
        @param payload: parameter dict
        @param files: files to upload
        @return:
        """
        self.headers = {"projectId": "default"}
        return self.send(self.post, import_map_url, data=payload, files=files).json()

    def import_map(self, xodr_path: str, thumbnail_path: str):
        """
        Import Map
        @param xodr_path: map file path
        @param thumbnail_path: map thumbnail image
        @return:
        """
        payload = {"params": json.dumps(
            {"category": "customized", "id": "new_" + Faker('zh_CN').uuid4(),
             "name": os.path.splitext(os.path.basename(xodr_path))[0], "size": 512,
             "ppm": 10, "bgColor": "#dddddd", "reproject": True, "reprojectOrigin": False, "reprojectOriginLat": 0,
             "reprojectOriginLng": 0, "tags": [], "notes": "",
             "header": {"minX": -210.20535534122396, "minY": -149.68815701999185, "minZ": -1.862645149230957e-9,
                        "maxX": 237.95535534122394, "maxY": 135.43815701999196, "maxZ": 2.7940070024635385e-9,
                        "centerX": 97.12480158531203, "centerY": 24.463606820251727, "centerZ": 100,
                        "localEnuExt": "6378137,0,0;0,1,0;0,0,1;1,0,0"}})}
        files = {'xodr': open(xodr_path, 'rb'), "thumbnail": open(thumbnail_path, 'rb')}
        result = self.import_map_api(payload, files)
        if result["code"] == 0:
            print(f"Import map {xodr_path} succeeded, id: {result['data']['mapId']}")
        else:
            print(f"Import map {xodr_path} failed, result: {result}")
            raise f"Import map {xodr_path} failed, result: {result}"
        res_dict = {"code": result["code"], "mapId": result["data"]["mapId"],
                    "name": os.path.basename(os.path.basename(xodr_path))}
        return res_dict


def main():
    suite = Suite()

    suite.import_map(r"D:\Project\SimOneAutomation\simone_automation\Sysdata\Public\import\Map\xodr\标志牌测试.xodr",
                     r"D:\Project\SimOneAutomation\simone_automation\Sysdata\Public\import\Map\img\import_map.png"
                     )
Usage Example
SimOneUrl = "http://172.31.9.85:30083/"
loginData = {
    "username": 'admin',
    "password": 'admin',
}
LoginPolicy("standalone")
if __name__ == '__main__':
    main()
Return Value
{'method': 'POST', 'url': 'http://172.31.9.85:30083/api-asset/maps', 'headers': {'Authorization': '92400a5e-0e20-4d34-bfb3-05f9344f4889'}, 'data': {'params': '{"category": "customized", "id": "", "name": "\\u6807\\u5fd7\\u724c\\u6d4b\\u8bd5", "size": 512, "ppm": 10, "bgColor": "#dddddd", "reproject": true, "reprojectOrigin": false, "reprojectOriginLat": 0, "reprojectOriginLng": 0, "tags": [], "notes": "", "header": {"minX": -210.20535534122396, "minY": -149.68815701999185, "minZ": -1.862645149230957e-09, "maxX": 237.95535534122394, "maxY": 135.43815701999196, "maxZ": 2.7940070024635385e-09, "centerX": 97.12480158531203, "centerY": 24.463606820251727, "centerZ": 100, "localEnuExt": "6378137,0,0;0,1,0;0,0,1;1,0,0"}}'}, 'files': {'xodr': <_io.BufferedReader name='D:\\Project\\SimOneAutomation\\simone_automation\\Sysdata\\Public\\import\\Map\\xodr\\标志牌测试.xodr'>, 'thumbnail': <_io.BufferedReader name='D:\\Project\\SimOneAutomation\\simone_automation\\Sysdata\\Public\\import\\Map\\img\\import_map.png'>}}
response:{"code":0,"data":{"mapId":"01ca5bba-d804-4d32-900f-742fa958d47f"}}
import map D:\Project\SimOneAutomation\simone_automation\Sysdata\Public\import\Map\xodr\标志牌测试.xodrsuccess

11.2 Get Map Information

API
"""
def get_map_api(self):
    """
    Get Map
    @return:
    """
    return self.send(self.get, self.get_map_url).json()
"""
Implementation
    def get_map_api(self):
    """
    Get Map
    @return:
    """
    return self.send(self.get, self.get_map_url).json()
    def get_map_id(self,userid:str=None,map_name:str=None):
        """
        Get map information based on conditions, retrieves all maps by default
        @param userid: User ID
        @param map_name: Map name
        @return:
        """
        global map_data
        map_data={}
        try:
            result = self.get_map_api()
            # print(len(result['data']['maps']))
            map_info = result['data']['maps']

            if userid:
                for map in map_info:
                    if map["userId"] == userid:
                        map_data.setdefault(map["name"],map["id"])
            elif map_name:
                for map in map_info:
                    if map["name"] == map_name:
                        map_data = {map["name"]: map["id"]}
            else:
                for map in map_info:
                    map_data.setdefault(map["userId"],{}).update({map["name"]: map["id"]})
            return map_data

        except Exception as e:
            print(e)
def main():
    suite = Suite()

    suite.get_map_id()
Usage Example
SimOneUrl = "http://172.31.9.85:30083/"
loginData = {
    "username": 'admin',
    "password": 'admin',
}
LoginPolicy("standalone")
if __name__ == '__main__':
    main()
Return Value
response:{"code":0,"data"...}

11.3 Delete Map

API
"""
def delete_map_api(self,payload:dict):
   """
   Delete Map
   @param payload: eg:{ids: ["27a0bbc4-5d4d-48c1-9187-62df794dadae"]}
   @return:
   """
   return self.send(self.post, delete_map_url, json=payload).json()
"""
Implementation
    def delete_map_api(self,payload:dict):
        """
        Delete Map
        @param payload: eg:{ids: ["27a0bbc4-5d4d-48c1-9187-62df794dadae"]}
        @return:
        """
        return self.send(self.post, delete_map_url, json=payload).json()

    def delete_map(self,id:list):
        """
        Batch delete maps
        @param id: List of Map IDs
        @return:
        """
        print("List of deleted maps -> {}".format(str(id)))
        payload = {"ids": id}
        self.delete_map_api(payload)


def main():
    suite = Suite()

    suite.delete(["'92400a5e-0e20-4d34-bfb3-05f9344f4889'"])
Usage Example
SimOneUrl = "http://172.31.9.85:30083/"
loginData = {
    "username": 'admin',
    "password": 'admin',
}
LoginPolicy("standalone")
if __name__ == '__main__':
    main()
Return Value
response:{"code":0,"data"...}

12. Judgment Group Operations

12.1 Get Use Case Judgment Group Information

API
"""
def get_judgements_api(self, caseId, judgementId=None):
    """
    Get Judgment Group Information API
    @param caseId: Use Case ID
    @param judgementId: Judgment Group ID
    @return:
    """
    if judgementId:
        url = get_judgement_url.format(caseId=caseId,judgementId=judgementId)
    else:
        url = get_judgements_url.format(caseId=caseId)
    response = self.send(self.get, url).json()
    return response
"""
Implementation
    def get_judgements_api(self, caseId, judgementId=None):
        """
        Get Judgment Information API
        @param caseId: Use Case ID
        @param judgementId: Judgment ID
        @return:
        """
        if judgementId:
            url = get_judgement_url.format(caseId=caseId,judgementId=judgementId)
        else:
            url = get_judgements_url.format(caseId=caseId)
        response = self.send(self.get, url).json()
        return response

    def get_judgements_method(self, caseId:str, judgementId:str = None):
        """
        Get Judgment Information
        @param caseId: Use Case ID
        @param judgementId: Judgment ID
        @return:
        """
        response = self.get_judgements_api(caseId,judgementId)
        print("Obtained extended judgment information:",response["data"][1])
        return response


def main():
    suite = Suite()

    suite.get_judgements_api("ebd4cf06-b66f-4e03-9294-5f60f55d453a")
Usage Example
SimOneUrl = "http://172.31.9.85:30083/"
loginData = {
    "username": 'admin',
    "password": 'admin',
}
LoginPolicy("standalone")
if __name__ == '__main__':
    main()
Return Value
response:{"code":0,"msg":"success","data":[{"id":"timeout","name":"超时","type":"timeout","category":"general","enabled":true,"scope":{"type":"global","position":{"x":0,"y":0,"z":0},"heading":{"x":0,"y":0,"z":0,"w":1},"size":{"x":10,"y":10,"z":0}},"conditions":[{"variable":"timeout","value":600}],"settings":{"action":"failure","logLevel":"error","logInfo":""},"builtIn":true,"lock":true,"userId":"admin","schema":"judgement"},{"id":"collision","name":"碰撞","type":"collision","category":"general","enabled":true,"scope":{"type":"global","position":{"x":0,"y":0,"z":0},"heading":{"x":0,"y":0,"z":0,"w":1},"size":{"x":10,"y":10,"z":0}},"conditions":[],"settings":{"action":"failure","logLevel":"error","logInfo":""},"builtIn":true,"lock":true,"userId":"admin","schema":"judgement"}]}

12.2 Update Judgment Information

API
"""
def update_judgement_method(self, caseId, judgementId="collision"):
    __collision = {"schema": "judgement", "settings": {"logLevel": "error", "action": "failure", "logInfo": ""},
                   "scope": {"size": {"x": 10, "y": 10, "z": 0}, "heading": {"w": 1, "x": 0, "y": 0, "z": 0},
                             "position": {"x": 0, "y": 0, "z": 0},
                             "type": "global"}, "builtIn": True,
                   "name": "碰撞", "lock": True, "id": "collision",
                   "type": "collision", "category": "general",
                   "conditions": [], "userId": "admin",
                   "enabled": True}
    payload = json.dumps(__collision)
    judgement_url = "api-asset/cases/{caseId}/judgements/{judgementId}"
    response = self.send(self.put, judgement_url.format(caseId=caseId, judgementId=judgementId), data=payload)
    print("Update extended judgment information")
    print("status_code:", response.status_code)
"""
Implementation
    def update_judgement_method(self, caseId, judgementId="collision"):
        __collision = {"schema": "judgement", "settings": {"logLevel": "error", "action": "failure", "logInfo": ""},
                       "scope": {"size": {"x": 10, "y": 10, "z": 0}, "heading": {"w": 1, "x": 0, "y": 0, "z": 0},
                                 "position": {"x": 0, "y": 0, "z": 0},
                                 "type": "global"}, "builtIn": True,
                       "name": "Collision", "lock": True, "id": "collision",
                       "type": "collision", "category": "general",
                       "conditions": [], "userId": "admin",
                       "enabled": True}
        payload = json.dumps(__collision)
        judgement_url = "api-asset/cases/{caseId}/judgements/{judgementId}"
        response = self.send(self.put, judgement_url.format(caseId=caseId, judgementId=judgementId), data=payload)
        print("Update extended judgment information")
        print("status_code:", response.status_code)


def main(category_name: str, case_name: str):
    """
    category_name: Case Library Name
    case_name: Use Case Name
    reset: Whether to reset judgment
    """
    LoginPolicy("standalone")
    suite = Suite()
    suite.get_category()

    # Logic for getting caseId
    cate_id = suite.get_category()
    cate_name = [cate_id["data"][category_name]]
    cases_dict, case_id_list = suite.get_cases_category(cate_name)
    case_id = cases_dict[case_name][0]
    suite.get_judgements_method(case_id)
    suite.update_judgement_method(case_id)
Usage Example
SimOneUrl = "http://172.31.9.85:30083/"
loginData = {
    "username": 'admin',
    "password": 'admin',
}
LoginPolicy("standalone")
if __name__ == '__main__':
    main("new", "test_4")
Return Value
Update extended judgment information
status_code: 202

13. Task Runtime Result Operations

13.1 Get Runtime Test Suite Information

API
"""
def get_task_result_api(self,task_id:str):
    """
    Get result for the specified task
    @param task_id:
    @return:
    """
    return self.send(self.get,task_result_url.format(id=task_id)).json()
"""
Implementation
    def get_task_result_api(self,task_id:str):
        """
        Get result for the specified task
        @param task_id:
        @return:
        """
        return self.send(self.get,task_result_url.format(id=task_id)).json()

    def get_task_result(self, task_id_list: list = None) -> list:
        """
        Get case name, caseId, task_id, and result from the task set
        @param task_id_list: list of task IDs
        @param task_set_id: task set ID
        @return:
        """

        task_result_list = []
        for task_id in task_id_list:
            result = self.get_task_result_api(task_id)
            case_name = result["data"]["tasks"][0]["case"]["name"]
            case_id = result["data"]["tasks"][0]["caseId"]
            task_id = result["data"]["tasks"][0]["id"]
            task_result = result["data"]["tasks"][0]["pass"]
            if task_result != True: task_result = False
            task_result_list.append({"case_name": case_name,
                                     "case_id": case_id,
                                     "task_id": task_id,
                                     "task_result": task_result})
        print("task_result_list->", task_result_list)
        return task_result_list


def main():
    suite = Suite()
    # The input task_id can be obtained from the return value of run_task
    suite.get_task_result(["51ec8581-4563-49c4-8ce1-ba96962b278b"])
Usage Example
SimOneUrl = "http://172.31.9.85:30083/"
loginData = {
    "username": 'admin',
    "password": 'admin',
}
LoginPolicy("standalone")
if __name__ == '__main__':
    main()
Return Value
task_result_list-> [{'case_name': 'test_4-copy', 'case_id': 'f5bbfb2c-619a-4812-90c2-75a84247a4db', 'task_id': '51ec8581-4563-49c4-8ce1-ba96962b278b', 'task_result': False}]

13.2 Get Test Suite List Information

API
"""
def get_task_list_api(self):
    """
    Get task list
    """
    response = self.send(self.get, url=get_task_list_url).json()
"""
Implementation
    def get_task_list_api(self):
        """
        Get task list
        """
        response = self.send(self.get, url=get_task_list_url).json()
Usage Example
SimOneUrl = "http://172.31.9.85:30083/"
loginData = {
    "username": 'admin',
    "password": 'admin',
}
LoginPolicy("standalone")
if __name__ == '__main__':
    test = Suite()
    test.get_task_list_api()
Return Value
response:{"code":0,"data":{"list":[{"parentId":null,"deleted":null,"deleteTime":null,"createAt":"2024-05-16T02:34:13.000Z","updateAt":"2024-05-16T02:35:08.000Z",....}

13.3 Download Test Report

API
"""
    def export_report_api(self, sessions_id: str):
        """
        Export test report API
        @param sessions_id: sessions_id
        @return: Response
        """
        self.headers.update({"Language": "zh-Hans"})
        return self.send(self.get, export_report_url.format(sessions_id=sessions_id)).json()

    def download_report_api(self, sessions_id: str):
        """
        Download test report API
        @param sessions_id: sessions_id
        @return: Response
        """

        return self.send(self.get, download_report_url.format(sessions_id=sessions_id)).content
"""
Implementation
    def export_report_api(self, sessions_id: str):
        """
        Export test report API
        @param sessions_id: sessions_id
        @return: Response
        """
        self.headers.update({"Language": "zh-Hans"})
        return self.send(self.get, export_report_url.format(sessions_id=sessions_id)).json()

    def download_report_api(self, sessions_id: str):
        """
        Download test report API
        @param sessions_id: sessions_id
        @return: Response
        """

        return self.send(self.get, download_report_url.format(sessions_id=sessions_id)).content

    def download_report(self, sessions_id: str, download_path: str, download_name: str) -> None:
        """
        Download test report
        @param sessions_id: sessions_id
        @return: Response
        """
        self.export_report_api(sessions_id)
        pdf_data = self.download_report_api(sessions_id)
        download_pathname = os.path.join(download_path, download_name)
        with open(download_pathname, mode="wb") as f:
            f.write(pdf_data)
Usage Example
LoginPolicy("standalone")
if __name__ == '__main__':
    test = Suite()      
                        # Test Suite ID  
    test.download_report("54c0806b-ba80-4821-ae25-49f7c284f486", r"C:\Users\Administrator\Desktop\test", "test.pdf")
Return Value
response:{"code":0,"data":{"success":true}}
Test report binary data