fix: use old case model

This commit is contained in:
Alex Duan 2024-12-30 16:57:16 +08:00
parent 2c35ec8ae9
commit f6b180ff56
1 changed files with 26 additions and 33 deletions

View File

@ -2,6 +2,9 @@ import taos
from datetime import datetime from datetime import datetime
import random import random
numOfSubTable = 10
numOfRow = 10
conn = None conn = None
stmt2 = None stmt2 = None
host="localhost" host="localhost"
@ -26,38 +29,28 @@ try:
sql = "INSERT INTO ? USING meters (groupid, location) TAGS(?,?) VALUES (?,?,?,?)" sql = "INSERT INTO ? USING meters (groupid, location) TAGS(?,?) VALUES (?,?,?,?)"
stmt2 = conn.statement2(sql) stmt2 = conn.statement2(sql)
# table name array tbnames = []
tbnames = ["d0","d1","d2"] tags = []
# tag data array datas = []
tags = [
[1, "BeiJing"], for i in range(numOfSubTable):
[2, None], # tbnames
[3, "ShangHai"] tbnames.append(f"d_bind_{i}")
] # tags
# column data array tags.append([i, f"location_{i}"])
datas = [ # datas
# d0 tabled current = int(datetime.now().timestamp() * 1000)
[ timestamps = []
[1601481600000,1601481600001,1601481600002,1601481600003,1601481600004,1601481600005], currents = []
[10.1, 10.2, 10.3, 10.4, 10.5 ,None ], voltages = []
[98, None, 60, 100, 99 ,128 ], phases = []
[0, 1, 0, 0, 1 ,0 ] for j in range (numOfRow):
], timestamps.append(current + i*1000 + j)
# d1 tabled currents.append(float(random.random() * 30))
[ voltages.append(random.randint(100, 300))
[1601481700000,1601481700001,1601481700002,1601481700003,1601481700004,1601481700005], phases.append(float(random.random()))
[10.1, 10.2, 10.3, 10.4, 10.5 ,11.2 ], data = [timestamps, currents, voltages, phases]
[98, 80, 60, 100, 99 ,128 ], datas.append(data)
[0, 1, 0, 0, 1 ,0 ]
],
# d2 tabled
[
[1601481800000,1601481800001,1601481800002,1601481800003,1601481800004,1601481800005],
[10.1, 10.2, 10.3, 10.4, 10.5 ,13.4 ],
[98, 80, 60, 100, 99 ,128 ],
[0, 1, 0, None, 1 ,0 ]
],
]
# 4 bind param # 4 bind param
stmt2.bind_param(tbnames, tags, datas) stmt2.bind_param(tbnames, tags, datas)
@ -66,7 +59,7 @@ try:
stmt2.execute() stmt2.execute()
# show # show
print(f"Successfully inserted with stmt2 to power.meters.") print(f"Successfully inserted with stmt2 to power.meters. child={numOfSubTable} rows={numOfRow} \n")
except Exception as err: except Exception as err:
print(f"Failed to insert to table meters using stmt2, ErrMessage:{err}") print(f"Failed to insert to table meters using stmt2, ErrMessage:{err}")