Files
eu_active_script/lion-ououmeng9.py

123 lines
7.0 KiB
Python
Raw Normal View History

from cassandra.cluster import Cluster
from cassandra.query import BatchStatement
import time
import hashlib
from cassandra.auth import PlainTextAuthProvider
import base64
from multiprocessing import Process
from multiprocessing import Pool
def sha256(data):
sha256 = hashlib.sha256()
sha256.update(data.encode('utf-8'))
return sha256.hexdigest()
def execute():
# 定义用户名和密码
username = 'tsp_eu_stress'
password = 'UaiKeq6cKsm2S4y'
# 创建身份验证提供程序
auth_provider = PlainTextAuthProvider(username=username, password=password)
# 连接到 Cassandra 集群
cluster = Cluster(['10.95.0.81'], auth_provider=auth_provider)
session = cluster.connect()
# # 创建Cassandra集群连接
# cluster = Cluster(['172.25.116.188'])
session = cluster.connect('tsp_eu')
# 创建批量操作语句
# batch = BatchStatement()
query2 = "insert into tsp_eu.realtime_his(v,ct,data,st,type) values(%s, %s,%s, %s,%s)"
query3 = "insert into tsp_eu.realtime_hf(v,ct,data,st,type) values(%s, %s,%s, %s,%s)"
#j为每个vin插入条数i为插入的vin数
for j in range(1):
for i in range(1,1000001):
# time.sleep(1)
# 创建插入语句
# tbox登陆登出插入语句
# query1 = "INSERT INTO tbox_login_logout (v,st,ct,reason,result,tbox_sn,type) VALUES (%s, %s,%s, %s,%s, %s,%s)"
# batch = BatchStatement()
# batch1 = BatchStatement()
# batch.add(query1, (
# sha256('TESTVIN' + str(i).zfill(10)), int(time.time() * 1000), int(time.time() * 1000), "1", "1", "1111",
# "2"))
# print('TESTVIN' + str(i).zfill(10))
# session.execute(batch)
#
# # # IHU车机登陆登出插入语句
# query2 = "insert into tsp_eu.hu_login_logout(v,st,ct,hu_sn,status,status_msg,type) values(%s, %s,%s, %s,%s, %s,%s)"
# batch1.add(query2, (sha256('TESTVIN' + str(i).zfill(10)), int(time.time() * 1000), int(time.time() * 1000),
# 'TESTVIN' + str(i).zfill(10), '1', 'ddd', '1'))
# session.execute(batch1)
# 低频数据插入语句
# batch2 = BatchStatement()
# print('TESTVIN' + str(i).zfill(10))
# batch2.add(query2, (
# sha256('TESTVIN' + str(i).zfill(10)), int(time.time() * 1000), "{\"202F\":255,\"2030\":255,\"2031\":255,\"2032\":255,\"2035\":255,\"2036\":255,\"2039\":255,\"203A\":255,\"203B\":255,\"203C\":255}",int(time.time() * 1000), '0'))
# session.execute(batch2)
#
# # 高频数据插入语句
# batch3 = BatchStatement()
# query3 = "insert into tsp_eu.realtime_hf(v,ct,data,st,type) values(%s, %s,%s, %s,%s)"
# batch2.add(query3, (
# sha256('TESTVIN' + str(i).zfill(10)), int(time.time() * 1000), "{\"0001\":46720,\"2005\":0,\"2076\":0,\"2077\":38912,\"2082\":2958360575,\"2084\":111428784,\"2085\":46720,\"2086\":0,\"2087\":2908749824,\"208A\":176,\"208C\":68}",
# int(time.time() * 1000), '0'))
# session.execute(batch2)
# 实时数据插入语句-每个vin只能有一条数据
batch4 = BatchStatement()
query4 = "insert into tsp_eu.realtime_new(v,ct,data,st) values(%s, %s,%s, %s)"
print('HESTVIN' + str(i).zfill(10))
batch4.add(query4, (
sha256('HESTVIN' + str(i).zfill(10)), int(time.time() * 1000), {'2001': '350', '2002': '1', '2003': '2000', '2004': '600', '2005': '60', '2006': '83', '2007': '350', '2008': '0', '2009': '10000', '200A': '600', '200B': '1000', '200C': '3000', '200D': '0', '200E': '1', '200F': '3', '2010': '1', '2011': '0', '2012': '0', '2013': '2', '2014': '1', '2015': '0', '2016': '0', '2017': '3', '2018': '0', '2019': '0', '201A': '0', '201B': '0', '201C': '0', '201D': '0', '201E': '0', '201F': '0', '2020': '0', '2021': '0', '2022': '0', '2023': '0', '2024': '0', '2025': '0', '2026': '230', '2027': '230', '2028': '230', '2029': '0', '202A': '6', '202B': '6', '202C': '1', '202D': '0', '202E': '0', '202F': '0', '2030': '1', '2031': '2', '2032': '0', '2033': '1', '2034': '1', '2035': '1', '2036': '1', '2037': '3', '2038': '1', '2039': '1', '203A': '0', '203B': '0', '203C': '0', '203D': '0', '203E': '150', '203F': '0', '2040': '0', '2041': '3', '2042': '17000', '2043': '1000', '2044': '85', '2045': '0', '2046': '23', '2047': '23', '2048': '23', '2049': '23', '204A': '70', '204B': '70', '204C': '70', '204D': '70', '204E': '0', '204F': '0', '2050': '0', '2051': '0', '2052': '0', '2053': '0', '2054': '0', '2055': '0', '2056': '0', '2057': '0', '2058': '0', '2059': '0', '205A': '0', '205B': '0', '205C': '0', '205D': '0', '205E': '1687590135166', '205F': '1687590135166', '2060': '5000', '2061': '180', '2062': '3000', '2063': '0', '2064': '0', '2065': '0', '2066': '0', '2067': '0', '2068': '0', '2069': '0', '206A': '0', '206B': '0', '206C': '0', '206D': '5', '206E': '0', '206F': '5', '2070': '0', '2071': '0', '2072': '0', '2073': '0', '2076': '3', '2077': '350', '2078': '0', '2080': '255', '2081': '255', '2082': '4294967295', '2083': '255', '2084': '4294967295', '2085': '4294967295', '2086': '4294967295', '2087': '4294967295', '2088': '0', '2089': '255', '208A': '255', '208B': '255', '208C': '1800', '208D': '4294967295', '208E': '4294967295', '208F': '4294967295', '2090': '4294967295', '2091': '255', '2092': '255', '2093': '255', '2094': '255', '2095': '65535'}, int(time.time() * 1000)))
session.execute(batch4)
# # 最新诊断
# batch5 = BatchStatement()
# query5 = "insert into tsp_eu.diagnosis_new(v,ct,data,out_vehicle_type,st) values(%s,%s, %s,%s, %s)"
# batch5.add(query5, (
# base64.urlsafe_b64encode(('TESTVIN' + str(i).zfill(10)).encode())[0:23].decode(), int(time.time() * 1000),
# {'10': 'null', '11': 'null', '12': 'null', '13': 'null', '15': 'null', '19': 'null',
# '2': '[9717033,9717267]', '20': 'null', '21': 'null', '22': 'null', '24': 'null', '32': 'null',
# '35': 'null', '36': 'null', '5': 'null', '8': 'null'}, 'T19CEV_OUTSIDE_001_TEST_KB51',
# int(time.time() * 1000)))
# session.execute(batch5)
# # 历史诊断
# batch6 = BatchStatement()
# query6 = "insert into tsp_eu.diagnosis_his(v,ct,data,st) values(%s, %s,%s, %s)"
# batch6.add(query6, (
# sha256('TESTVIN' + str(i).zfill(10)), int(time.time() * 1000),
# "{\"5010\":0,\"5011\":1,\"5001\":4,\"5A01\":[]}",
# int(time.time() * 1000)))
# session.execute(batch6)
# 执行批量操作
# session.execute(batch)
# 关闭连接
session.shutdown()
cluster.shutdown()
if __name__ == '__main__':
# poo1=Pool(30)
# for i in range(1000):
# poo1.apply_async(execute)
# poo1.close()
# poo1.join()
# for i in range(10):
# p=Process(target=execute)
# p.start()
execute()