migrace arch_detail do sqlite
This commit is contained in:
@ -5,6 +5,8 @@ from uuid import UUID, uuid4
|
||||
import json
|
||||
from datetime import datetime
|
||||
from v2realbot.enums.enums import RecordType, StartBarAlign, Mode, Account
|
||||
from v2realbot.common.model import RunArchiveDetail
|
||||
from tinydb import TinyDB, Query, where
|
||||
|
||||
sqlite_db_file = DATA_DIR + "/v2trading.db"
|
||||
conn = sqlite3.connect(sqlite_db_file)
|
||||
@ -63,22 +65,22 @@ def delete_logs(runner_id: UUID):
|
||||
conn.commit()
|
||||
return res.rowcount
|
||||
|
||||
print(insert_log(str(uuid4()), datetime.now().timestamp(), insert))
|
||||
c = conn.cursor()
|
||||
ts_from = 1683108821.08872
|
||||
ts_to = 1683108821.08874
|
||||
# res = c.execute(f"SELECT runner_id, time, data FROM runner_logs where time > {ts_from} and time <{ts_to}")
|
||||
# result = res.fetchall()
|
||||
# print(insert_log(str(uuid4()), datetime.now().timestamp(), insert))
|
||||
# c = conn.cursor()
|
||||
# ts_from = 1683108821.08872
|
||||
# ts_to = 1683108821.08874
|
||||
# # res = c.execute(f"SELECT runner_id, time, data FROM runner_logs where time > {ts_from} and time <{ts_to}")
|
||||
# # result = res.fetchall()
|
||||
|
||||
# res= delete_logs("7f9866ac-c742-47f4-a329-1d2b6721e781")
|
||||
# # res= delete_logs("7f9866ac-c742-47f4-a329-1d2b6721e781")
|
||||
# # print(res)
|
||||
|
||||
# # res = read_log_window(runner_id="33", timestamp_from=11 , timestamp_to=22)
|
||||
# # print(res)
|
||||
|
||||
# res = insert_log_multiple(uuid4(), insert_list)
|
||||
# print(res)
|
||||
|
||||
# res = read_log_window(runner_id="33", timestamp_from=11 , timestamp_to=22)
|
||||
# print(res)
|
||||
|
||||
res = insert_log_multiple(uuid4(), insert_list)
|
||||
print(res)
|
||||
|
||||
# res = read_log_window("3340e257-d19a-4179-baf3-3b39190acde3", ts_from, ts_to)
|
||||
|
||||
# print(res)
|
||||
@ -90,8 +92,80 @@ print(res)
|
||||
#print(res.description)
|
||||
#print(result)
|
||||
|
||||
def insert_archive_detail(archdetail: RunArchiveDetail):
|
||||
c = conn.cursor()
|
||||
json_string = json.dumps(archdetail, default=json_serial)
|
||||
res = c.execute("INSERT INTO runner_detail VALUES (?,?)",[str(archdetail["id"]), json_string])
|
||||
conn.commit()
|
||||
return res.rowcount
|
||||
|
||||
#returns list of details
|
||||
def get_all_archive_detail():
|
||||
conn.row_factory = lambda c, r: json.loads(r[0])
|
||||
c = conn.cursor()
|
||||
res = c.execute(f"SELECT data FROM runner_detail")
|
||||
return res.fetchall()
|
||||
|
||||
#vrátí konkrétní
|
||||
def get_archive_detail_byID(runner_id: UUID):
|
||||
conn.row_factory = lambda c, r: json.loads(r[0])
|
||||
c = conn.cursor()
|
||||
res = c.execute(f"SELECT data FROM runner_detail WHERE runner_id='{str(runner_id)}'")
|
||||
return res.fetchone()
|
||||
|
||||
#returns number of deleted elements
|
||||
def delete_archive_detail(runner_id: UUID):
|
||||
c = conn.cursor()
|
||||
res = c.execute(f"DELETE from runner_detail WHERE runner_id='{str(runner_id)}';")
|
||||
print(res.rowcount)
|
||||
conn.commit()
|
||||
return res.rowcount
|
||||
|
||||
def get_all_archived_runners_detail():
|
||||
arch_detail_file = DATA_DIR + "/arch_detail.json"
|
||||
db_arch_d = TinyDB(arch_detail_file, default=json_serial)
|
||||
res = db_arch_d.all()
|
||||
return 0, res
|
||||
|
||||
def migrate():
|
||||
set = list[RunArchiveDetail]
|
||||
res, set = get_all_archived_runners_detail()
|
||||
print(f"fetched {len(set)}")
|
||||
for row in set:
|
||||
#insert_archive_detail(row)
|
||||
print(f"inserted {row['id']}")
|
||||
|
||||
bars = {'high': [],
|
||||
'low': [],
|
||||
'volume': [],
|
||||
'close': [],
|
||||
'hlcc4': [],
|
||||
'open': [],
|
||||
'time': [],
|
||||
'trades':[],
|
||||
'resolution':[],
|
||||
'confirmed': [],
|
||||
'vwap': [],
|
||||
'updated': [],
|
||||
'index': []}
|
||||
|
||||
idecko = uuid4()
|
||||
|
||||
runArchiveDetail: RunArchiveDetail = RunArchiveDetail(id = idecko,
|
||||
name="nazev runneru",
|
||||
bars=bars,
|
||||
indicators=[dict(time=[])],
|
||||
statinds=dict(neco=233,zase=333),
|
||||
trades=list(dict()))
|
||||
|
||||
# insert_archive_detail(runArchiveDetail)
|
||||
migrate()
|
||||
# res = get_archive_detail_byID(idecko)
|
||||
# print("byID",res)
|
||||
res = get_all_archive_detail()
|
||||
print("finished: all",len(res))
|
||||
# delete_archive_detail(idecko)
|
||||
# res = get_archive_detail_byID(idecko)
|
||||
# print("byID",res)
|
||||
# res = get_all_archive_detail()
|
||||
# print("all",res)
|
||||
Reference in New Issue
Block a user