• python csv 数据切割定制jmeter数据


    需求压测随机抽取10w数据中自定义区间的指定数量数据进行压测:

    jmeter csv/txt配置:

    需要获取{data: [${myList}]  }  jmeter需要数据类型

    获取展读取csv数据展示{ data:

    [

    "cfcd208495d565ef66e7dff9f98764da", "c4ca4238a0b923820dcc509a6f75849b", "c81e728d9d4c2f636f067f89cc14862c"

    ]

    }

    import  hmac
    import base64
    from hashlib import sha1
    import random
    
    def test_get(index_start:int,n,path):
    
            with open(path, 'r') as f:
                lines = f.readlines()
            lines_data = [i.strip() for i in lines]
            if n%1000==0:
               numbers=int(n/1000)
               datas=[]
               for i in range(numbers):
                 data=lines_data[index_start:index_start+1000]
                 datas.extend(data)
               print("数据拼接长度{}".format(len(datas)))
               dt=["{}".format(i) for i  in datas]
               return dt
            else:
                numbers=int(n/1000)
                remain=n%1000
                datas = []
                for i in range(numbers):
                    data = lines_data[index_start:index_start + 1000]
                    datas.extend(data)
                seed=random.randint(index_start,index_start+100)
                datas.extend(lines_data[index_start+seed:index_start+seed
                                                         +remain])
                print("数据拼接长度{}".format(len(datas)))
                dt = ["{}".format(i) for i in datas]
                return dt
    
    def write_result(index,numbers,path_csv):
        datas=test_get(index_start=index,n=numbers,path=path_csv)
        st=''
        for i in datas:
            st +='"{}", '.format(i)
        with open('./result.txt', 'w') as f:
            f.write('{}'.format(st.strip().strip(',')))
     
    
    """
    def   hash_mac(app_secret:str,msg:str):
        hmac_code = hmac.new(app_secret.encode(), msg.encode(), sha1).digest()
        return base64.b64encode(hmac_code).decode()
    """
    if __name__ == '__main__':
       write_result(0, 1000, path_csv=r"D:workspaceDS_4.csv")

    生成数据csv/txt数据格式:

      

  • 相关阅读:
    一次向svn中增加所有新增文件 svn add all new files
    cocos2d-x Lua与OC互相调用
    IOS8开发之实现App消息推送
    IOS Remote Notification
    再见
    vue中$router.push打开新窗口
    nuxt拦截IE浏览器
    百度统计api获取数据
    css滚动条样式自定义
    nuxt框架Universal和Spa两种render mode的区别
  • 原文地址:https://www.cnblogs.com/SunshineKimi/p/11649561.html
Copyright © 2020-2023  润新知