123 lines
2.8 KiB
Python
123 lines
2.8 KiB
Python
import sys
|
|
from traceback import format_exc
|
|
import asyncio
|
|
from appPublic.uniqueID import getID
|
|
from appPublic.timeUtils import days_between, strdate_add
|
|
from random import randint, random
|
|
|
|
from sqlor.dbpools import DBPools
|
|
databases = {
|
|
"sage":{
|
|
"driver":"aiomysql",
|
|
"async_mode":True,
|
|
"coding":"utf8",
|
|
"maxconn":100,
|
|
"dbname":"sage",
|
|
"kwargs":{
|
|
"user":"test",
|
|
"db":"sage",
|
|
"password":"QUZVcXg5V1p1STMybG5Ia6mX9D0v7+g=",
|
|
"host":"localhost"
|
|
}
|
|
}
|
|
}
|
|
|
|
def get_modelid():
|
|
return sys.argv[4]
|
|
return 'AuJYPP051dQJW9njyXhIu'
|
|
|
|
|
|
def get_date(d1, d2):
|
|
days = days_between(d1, d2) - 1
|
|
if (d1 > d2):
|
|
d = d2
|
|
d2 = d1
|
|
d1 = d
|
|
return strdate_add(d1, days=random() * (days + 1))
|
|
|
|
def get_time(d):
|
|
tf = 7 * 60 * 60
|
|
tt = 21 * 60 * 60
|
|
ti = tf + int(random() * (tt - tf))
|
|
h = int(ti / 3600)
|
|
m = int((ti - h * 3600) / 60)
|
|
s = ti % 60
|
|
return '%s %02d:%02d:%02d' % (d, h, m, s)
|
|
|
|
async def get_users(sor):
|
|
sql = "select id from users"
|
|
users = await sor.sqlExe(sql, {})
|
|
return users
|
|
|
|
def get_user(users):
|
|
cnt = len(users)
|
|
return users[randint(0, cnt - 1)].id
|
|
|
|
async def get_modeltype(sor, mii):
|
|
try:
|
|
sql = """select b.modeltypeid
|
|
from modelinstance a, modelapi b
|
|
where a.modelid = b.modelid
|
|
and a.id = ${id}$"""
|
|
recs = await sor.sqlExe(sql, {'id':mii})
|
|
if len(recs) > 0:
|
|
cnt = len(recs)
|
|
return recs[randint(0,cnt-1)].modeltypeid
|
|
else:
|
|
print(f'{sql=}, {mii=} not found')
|
|
return None
|
|
except Exception as e:
|
|
tbc = format_exc()
|
|
print(f'{e}, {tbc=}')
|
|
|
|
async def main():
|
|
db = DBPools(databases)
|
|
mti_tokens = {
|
|
'semanticsunderstanding':8839818053,
|
|
'dialogsemantics':4475142259,
|
|
'textclassify':6931846764,
|
|
'textmatching':3896737113
|
|
}
|
|
|
|
async with db.sqlorContext('sage') as sor:
|
|
userids = await get_users(sor)
|
|
mii = 'AuJYPP051dQJW9njyXhIu'
|
|
for mti, max_token in mti_tokens.items():
|
|
while max_token > 0:
|
|
input_t = 1000 + randint(0, 1000000)
|
|
output_t = 1000 + randint(0, 1000000)
|
|
token_cnt = input_t + output_t
|
|
if token_cnt > max_token:
|
|
t = int (token_cnt - max_token) / 2
|
|
input_t -= t
|
|
output_t = max_token - input_t
|
|
max_token = 0
|
|
else:
|
|
max_token -= token_cnt
|
|
|
|
transdate = get_date('2024-11-01', '2024-12-01')
|
|
transtime = get_time(transdate)
|
|
modeltypeid = mti
|
|
userid = get_user(userids)
|
|
pricing_mode = 'token'
|
|
accounting_status = 'not_accounting_yet'
|
|
id = getID()
|
|
d = {
|
|
"id":id,
|
|
"transdate":transdate,
|
|
"transtime":transtime,
|
|
"modelinstanceid":mii,
|
|
"modeltypeid":modeltypeid,
|
|
"userid":userid,
|
|
"pricing_mode":pricing_mode,
|
|
"input_tokens":input_t,
|
|
"output_tokens":output_t,
|
|
"token_cnt":token_cnt,
|
|
"accounting_status":accounting_status
|
|
}
|
|
await sor.C('feelog', d)
|
|
|
|
if __name__ == '__main__':
|
|
asyncio.get_event_loop().run_until_complete(main())
|
|
|