针对接口响应时长进行排序

def sort_by_response_time(case_list):
    # 存放url和响应时长
    new_list = []
    newlist4 = []
    newlist5 = []
    diclist_top5 = {}
    for i in range(0, len(case_list)):
        new_list.append(case_list[i][3])

    # set去重
    new_list_remove_dup = set(new_list)
    for i in new_list_remove_dup:
        angle_list = [i, 0]
        newlist4.append(angle_list)
        newlist5.append(angle_list)

    # 对接口相应时长进行排序,按降序排序
    for i in range(0, len(newlist4)):
        for n in range(0, len(case_list)):
            if newlist4[i][0] == case_list[n][3] and case_list[n][5] >= newlist4[i][1]:
                newlist4[i][1] = case_list[n][5]
                newlist5[i][0] = newlist4[i][0].replace("/", "\n")
                newlist5[i][1] = case_list[n][5]
            else:
                pass

    dic_list = sorted(dict(newlist5).items(), key=lambda x: x[1], reverse=True)
    for i, (k, v) in enumerate(dict(dic_list).items()):
        if i in range(0, 5):
            diclist_top5[k] = v
        else:
            break
    return diclist_top5

if __name__ == '__main__':
    l = [[1, '直接录', 'GET', '/ls/directrd', 'Fail', 0.70, ' "resultCode": 201', 200, '{"resultCode":200,"message":"OK","data":{"total":11,"page_total":2,"list":[],'],
     [2, '直接请搜索', 'GET', '/app/api/fw/seoss/2', 'Success', 0.089, ' "resultCode": 200', 200, '{"resultCode":200,"message":"OK","data":{"total":0,"page_total":0,"list":[]}}'],
    [3, '', 'POST', 'qls', 'Success', 0.265, '"resultCode": 200', 200, '{"resultCode":200,"message":"OK","data":null}'],
         [4, '直录', 'GET', '/tcord', 'Fail', 0.5, ' "resultCode": 201', 200,
          '{"resultCode":200,"message":"OK","data":{"total":11,"page_total":2,"list":[],'],
         [5, '宣增', 'POST', 'qiqi/publicmaterial', 'Success', 0.90, '"resultCode": 200',200, ''],
         [6, '宣增', 'POST', 'qiqi/publicmaterial5555', 'Success', 0.80, '"resultCode": 200', 200, '']
         ]

sort_by_response_time(l)

 

posted @ 2021-01-18 16:07  jiyanjiao  阅读(58)  评论(0编辑  收藏  举报