mirror of
https://gitee.com/fasiondog/hikyuu.git
synced 2024-11-29 18:39:10 +08:00
data maintain tool(continue)
This commit is contained in:
parent
0edd61dacd
commit
8fc07c7298
@ -36,6 +36,7 @@ script:
|
||||
- cd ./build/fasiondog/hikyuu
|
||||
- export BOOST_ROOT=$HOME/boost_1_67_0
|
||||
- export BOOST_LIB=$HOME/boost_1_67_0/stage/lib
|
||||
- ls .
|
||||
- xmake f --with-unit-test=y --cxx=$CXX
|
||||
- xmake
|
||||
- xmake r unit-test
|
||||
|
@ -13,11 +13,9 @@ from hdf5import import *
|
||||
class HDF5ImportThread(QThread):
|
||||
message = pyqtSignal(list)
|
||||
|
||||
def __init__(self, config, quotations, ktypes):
|
||||
def __init__(self, config):
|
||||
super(self.__class__, self).__init__()
|
||||
self.config = config
|
||||
self.quotations = quotations
|
||||
self.ktypes = ktypes
|
||||
self.msg_name = 'HDF5_IMPORT'
|
||||
self.msg_task_name = ''
|
||||
|
||||
@ -28,18 +26,24 @@ class HDF5ImportThread(QThread):
|
||||
dest_dir = config['hdf5']['dir']
|
||||
sqlite_file_name = dest_dir + "/hikyuu-stock.db"
|
||||
|
||||
self.quotations = []
|
||||
if self.config['quotation']['stock']:
|
||||
self.quotations.append('stock')
|
||||
if self.config['quotation']['fund']:
|
||||
self.quotations.append('fund')
|
||||
|
||||
self.queue = Queue()
|
||||
self.tasks = []
|
||||
self.tasks.append(WeightImportTask(self.queue, sqlite_file_name, dest_dir))
|
||||
if 'DAY' in self.ktypes:
|
||||
self.tasks.append(TdxImportTask(self.queue, sqlite_file_name, 'SH', 'DAY','stock', src_dir, dest_dir))
|
||||
self.tasks.append(TdxImportTask(self.queue, sqlite_file_name, 'SZ', 'DAY','stock', src_dir, dest_dir))
|
||||
if '5MIN' in self.ktypes:
|
||||
self.tasks.append(TdxImportTask(self.queue, sqlite_file_name, 'SH', '5MIN','stock', src_dir, dest_dir))
|
||||
self.tasks.append(TdxImportTask(self.queue, sqlite_file_name, 'SZ', '5MIN', 'stock', src_dir, dest_dir))
|
||||
if '1MIN' in self.ktypes:
|
||||
self.tasks.append(TdxImportTask(self.queue, sqlite_file_name, 'SH', '1MIN','stock', src_dir, dest_dir))
|
||||
self.tasks.append(TdxImportTask(self.queue, sqlite_file_name, 'SZ', '1MIN', 'stock', src_dir, dest_dir))
|
||||
if self.config['ktype']['day']:
|
||||
self.tasks.append(TdxImportTask(self.queue, sqlite_file_name, 'SH', 'DAY', self.quotations, src_dir, dest_dir))
|
||||
self.tasks.append(TdxImportTask(self.queue, sqlite_file_name, 'SZ', 'DAY', self.quotations, src_dir, dest_dir))
|
||||
if self.config['ktype']['min5']:
|
||||
self.tasks.append(TdxImportTask(self.queue, sqlite_file_name, 'SH', '5MIN', self.quotations, src_dir, dest_dir))
|
||||
self.tasks.append(TdxImportTask(self.queue, sqlite_file_name, 'SZ', '5MIN', self.quotations, src_dir, dest_dir))
|
||||
if self.config['ktype']['min']:
|
||||
self.tasks.append(TdxImportTask(self.queue, sqlite_file_name, 'SH', '1MIN', self.quotations, src_dir, dest_dir))
|
||||
self.tasks.append(TdxImportTask(self.queue, sqlite_file_name, 'SZ', '1MIN', self.quotations, src_dir, dest_dir))
|
||||
|
||||
|
||||
def __del__(self):
|
||||
@ -75,9 +79,8 @@ class HDF5ImportThread(QThread):
|
||||
connect = sqlite3.connect(dest_dir + "\\hikyuu-stock.db")
|
||||
create_database(connect)
|
||||
|
||||
tdx_import_stock_name_from_file(connect, src_dir + "\\T0002\\hq_cache\\shm.tnf", 'SH', 'stock')
|
||||
tdx_import_stock_name_from_file(connect, src_dir + "\\T0002\\hq_cache\\szm.tnf", 'SZ', 'stock')
|
||||
|
||||
tdx_import_stock_name_from_file(connect, src_dir + "\\T0002\\hq_cache\\shm.tnf", 'SH', self.quotations)
|
||||
tdx_import_stock_name_from_file(connect, src_dir + "\\T0002\\hq_cache\\szm.tnf", 'SZ', self.quotations)
|
||||
|
||||
for task in self.tasks:
|
||||
p = Process(target=task)
|
||||
@ -90,7 +93,7 @@ class HDF5ImportThread(QThread):
|
||||
if progress is None:
|
||||
finished_count -= 1
|
||||
if taskname == 'TdxImportTask':
|
||||
self.send_message(['IMPORT_KDATA', 'FINISHED', ktype, total])
|
||||
self.send_message(['IMPORT_KDATA', 'FINISHED', market, ktype, total])
|
||||
else:
|
||||
self.send_message([taskname, 'FINISHED'])
|
||||
continue
|
||||
|
@ -34,18 +34,12 @@ class Ui_MainWindow(object):
|
||||
self.select_dzh_dir_pushButton = QtWidgets.QPushButton(self.layoutWidget)
|
||||
self.select_dzh_dir_pushButton.setObjectName("select_dzh_dir_pushButton")
|
||||
self.gridLayout_2.addWidget(self.select_dzh_dir_pushButton, 1, 3, 1, 1)
|
||||
self.label_3 = QtWidgets.QLabel(self.layoutWidget)
|
||||
self.label_3.setObjectName("label_3")
|
||||
self.gridLayout_2.addWidget(self.label_3, 1, 1, 1, 1)
|
||||
self.dzh_dir_lineEdit = QtWidgets.QLineEdit(self.layoutWidget)
|
||||
self.dzh_dir_lineEdit.setObjectName("dzh_dir_lineEdit")
|
||||
self.gridLayout_2.addWidget(self.dzh_dir_lineEdit, 1, 2, 1, 1)
|
||||
self.tdx_enable_checkBox = QtWidgets.QCheckBox(self.layoutWidget)
|
||||
self.tdx_enable_checkBox.setObjectName("tdx_enable_checkBox")
|
||||
self.gridLayout_2.addWidget(self.tdx_enable_checkBox, 0, 0, 1, 1)
|
||||
self.dzh_checkBox = QtWidgets.QCheckBox(self.layoutWidget)
|
||||
self.dzh_checkBox.setObjectName("dzh_checkBox")
|
||||
self.gridLayout_2.addWidget(self.dzh_checkBox, 1, 0, 1, 1)
|
||||
self.label_2 = QtWidgets.QLabel(self.layoutWidget)
|
||||
self.label_2.setObjectName("label_2")
|
||||
self.gridLayout_2.addWidget(self.label_2, 0, 1, 1, 1)
|
||||
@ -55,6 +49,12 @@ class Ui_MainWindow(object):
|
||||
self.select_tdx_dir_pushButton = QtWidgets.QPushButton(self.layoutWidget)
|
||||
self.select_tdx_dir_pushButton.setObjectName("select_tdx_dir_pushButton")
|
||||
self.gridLayout_2.addWidget(self.select_tdx_dir_pushButton, 0, 3, 1, 1)
|
||||
self.label_3 = QtWidgets.QLabel(self.layoutWidget)
|
||||
self.label_3.setObjectName("label_3")
|
||||
self.gridLayout_2.addWidget(self.label_3, 1, 1, 1, 1)
|
||||
self.dzh_checkBox = QtWidgets.QCheckBox(self.layoutWidget)
|
||||
self.dzh_checkBox.setObjectName("dzh_checkBox")
|
||||
self.gridLayout_2.addWidget(self.dzh_checkBox, 1, 0, 1, 1)
|
||||
self.groupBox = QtWidgets.QGroupBox(self.tab)
|
||||
self.groupBox.setGeometry(QtCore.QRect(10, 200, 511, 71))
|
||||
self.groupBox.setObjectName("groupBox")
|
||||
@ -189,7 +189,7 @@ class Ui_MainWindow(object):
|
||||
self.hdf5_weight_label.setObjectName("hdf5_weight_label")
|
||||
self.gridLayout.addWidget(self.hdf5_weight_label, 3, 1, 1, 1)
|
||||
self.groupBox_6 = QtWidgets.QGroupBox(self.tab)
|
||||
self.groupBox_6.setGeometry(QtCore.QRect(250, 20, 271, 51))
|
||||
self.groupBox_6.setGeometry(QtCore.QRect(210, 20, 271, 51))
|
||||
self.groupBox_6.setObjectName("groupBox_6")
|
||||
self.layoutWidget5 = QtWidgets.QWidget(self.groupBox_6)
|
||||
self.layoutWidget5.setGeometry(QtCore.QRect(20, 20, 244, 18))
|
||||
@ -211,10 +211,10 @@ class Ui_MainWindow(object):
|
||||
self.import_tick_checkBox.setObjectName("import_tick_checkBox")
|
||||
self.horizontalLayout_2.addWidget(self.import_tick_checkBox)
|
||||
self.groupBox_7 = QtWidgets.QGroupBox(self.tab)
|
||||
self.groupBox_7.setGeometry(QtCore.QRect(10, 20, 231, 51))
|
||||
self.groupBox_7.setGeometry(QtCore.QRect(10, 20, 181, 51))
|
||||
self.groupBox_7.setObjectName("groupBox_7")
|
||||
self.layoutWidget6 = QtWidgets.QWidget(self.groupBox_7)
|
||||
self.layoutWidget6.setGeometry(QtCore.QRect(20, 20, 208, 18))
|
||||
self.layoutWidget6.setGeometry(QtCore.QRect(20, 20, 151, 18))
|
||||
self.layoutWidget6.setObjectName("layoutWidget6")
|
||||
self.horizontalLayout_3 = QtWidgets.QHBoxLayout(self.layoutWidget6)
|
||||
self.horizontalLayout_3.setContentsMargins(0, 0, 0, 0)
|
||||
@ -225,9 +225,6 @@ class Ui_MainWindow(object):
|
||||
self.import_fund_checkBox = QtWidgets.QCheckBox(self.layoutWidget6)
|
||||
self.import_fund_checkBox.setObjectName("import_fund_checkBox")
|
||||
self.horizontalLayout_3.addWidget(self.import_fund_checkBox)
|
||||
self.import_bond_checkBox = QtWidgets.QCheckBox(self.layoutWidget6)
|
||||
self.import_bond_checkBox.setObjectName("import_bond_checkBox")
|
||||
self.horizontalLayout_3.addWidget(self.import_bond_checkBox)
|
||||
self.import_future_checkBox = QtWidgets.QCheckBox(self.layoutWidget6)
|
||||
self.import_future_checkBox.setEnabled(False)
|
||||
self.import_future_checkBox.setObjectName("import_future_checkBox")
|
||||
@ -251,11 +248,11 @@ class Ui_MainWindow(object):
|
||||
self.start_import_pushButton.setText(_translate("MainWindow", "执行导入"))
|
||||
self.groupBox_2.setTitle(_translate("MainWindow", "K线数据源"))
|
||||
self.select_dzh_dir_pushButton.setText(_translate("MainWindow", "选择"))
|
||||
self.label_3.setText(_translate("MainWindow", "大智慧安装目录:"))
|
||||
self.tdx_enable_checkBox.setText(_translate("MainWindow", "使用"))
|
||||
self.dzh_checkBox.setText(_translate("MainWindow", "使用"))
|
||||
self.label_2.setText(_translate("MainWindow", "通达信安装目录:"))
|
||||
self.select_tdx_dir_pushButton.setText(_translate("MainWindow", "选择"))
|
||||
self.label_3.setText(_translate("MainWindow", "大智慧安装目录:"))
|
||||
self.dzh_checkBox.setText(_translate("MainWindow", "使用"))
|
||||
self.groupBox.setTitle(_translate("MainWindow", "Pytdx配置(权息、财务数据源)"))
|
||||
self.label_10.setText(_translate("MainWindow", "行情服务器:"))
|
||||
self.label_11.setText(_translate("MainWindow", "端口:"))
|
||||
@ -285,7 +282,6 @@ class Ui_MainWindow(object):
|
||||
self.groupBox_7.setTitle(_translate("MainWindow", "导入行情"))
|
||||
self.import_stock_checkBox.setText(_translate("MainWindow", "股票"))
|
||||
self.import_fund_checkBox.setText(_translate("MainWindow", "基金"))
|
||||
self.import_bond_checkBox.setText(_translate("MainWindow", "债券"))
|
||||
self.import_future_checkBox.setText(_translate("MainWindow", "期货"))
|
||||
self.import_status_label.setText(_translate("MainWindow", "import_status_label"))
|
||||
self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab), _translate("MainWindow", "数据导入"))
|
||||
|
@ -72,13 +72,6 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QLabel" name="label_3">
|
||||
<property name="text">
|
||||
<string>大智慧安装目录:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="2">
|
||||
<widget class="QLineEdit" name="dzh_dir_lineEdit"/>
|
||||
</item>
|
||||
@ -89,13 +82,6 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QCheckBox" name="dzh_checkBox">
|
||||
<property name="text">
|
||||
<string>使用</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="text">
|
||||
@ -113,6 +99,20 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QLabel" name="label_3">
|
||||
<property name="text">
|
||||
<string>大智慧安装目录:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QCheckBox" name="dzh_checkBox">
|
||||
<property name="text">
|
||||
<string>使用</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
@ -442,7 +442,7 @@
|
||||
<widget class="QGroupBox" name="groupBox_6">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>250</x>
|
||||
<x>210</x>
|
||||
<y>20</y>
|
||||
<width>271</width>
|
||||
<height>51</height>
|
||||
@ -500,7 +500,7 @@
|
||||
<rect>
|
||||
<x>10</x>
|
||||
<y>20</y>
|
||||
<width>231</width>
|
||||
<width>181</width>
|
||||
<height>51</height>
|
||||
</rect>
|
||||
</property>
|
||||
@ -512,7 +512,7 @@
|
||||
<rect>
|
||||
<x>20</x>
|
||||
<y>20</y>
|
||||
<width>208</width>
|
||||
<width>151</width>
|
||||
<height>18</height>
|
||||
</rect>
|
||||
</property>
|
||||
@ -531,13 +531,6 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="import_bond_checkBox">
|
||||
<property name="text">
|
||||
<string>债券</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="import_future_checkBox">
|
||||
<property name="enabled">
|
||||
|
@ -16,13 +16,13 @@ class ProgressBar:
|
||||
self.src.queue.put([self.src.__class__.__name__, self.src.market, self.src.ktype, (cur+1) * 100 // total, 0])
|
||||
|
||||
class TdxImportTask:
|
||||
def __init__(self, queue, sqlitefile, market, ktype, quotation, src_dir, dest_dir):
|
||||
def __init__(self, queue, sqlitefile, market, ktype, quotations, src_dir, dest_dir):
|
||||
super(self.__class__, self).__init__()
|
||||
self.queue = queue
|
||||
self.sqlitefile = sqlitefile
|
||||
self.market = market.upper()
|
||||
self.ktype = ktype.upper()
|
||||
self.quotation = quotation
|
||||
self.quotations = quotations
|
||||
if self.market == 'SH':
|
||||
if self.ktype == 'DAY':
|
||||
self.src_dir = src_dir + "/vipdoc/sh/lday"
|
||||
@ -47,7 +47,7 @@ class TdxImportTask:
|
||||
try:
|
||||
connect = sqlite3.connect(self.sqlitefile)
|
||||
progress = ProgressBar(self)
|
||||
count = tdx_import_data(connect, self.market, self.ktype, self.quotation, self.src_dir, self.dest_dir, progress)
|
||||
count = tdx_import_data(connect, self.market, self.ktype, self.quotations, self.src_dir, self.dest_dir, progress)
|
||||
except Exception as e:
|
||||
print(e)
|
||||
self.queue.put([self.__class__.__name__, self.market, self.ktype, None, count])
|
||||
|
@ -15,17 +15,20 @@ STOCKTYPE_BOND = 7 #其他债券
|
||||
STOCKTYPE_GEM = 8 #创业板
|
||||
STOCKTYPE_BTC = 9 #数字币
|
||||
|
||||
def get_stktype_list(quotation=None):
|
||||
if not quotation:
|
||||
def get_stktype_list(quotations=None):
|
||||
if not quotations:
|
||||
return (1, 2, 3, 4, 5, 6, 7, 8, 9)
|
||||
|
||||
new_quotation = quotation.lower()
|
||||
if new_quotation == 'stock':
|
||||
return (STOCKTYPE_A, STOCKTYPE_INDEX, STOCKTYPE_B, STOCKTYPE_GEM)
|
||||
elif new_quotation == 'fund':
|
||||
return (STOCKTYPE_FUND, STOCKTYPE_ETF)
|
||||
elif new_quotation == 'bond':
|
||||
return (STOCKTYPE_ND, STOCKTYPE_BOND)
|
||||
else:
|
||||
print('Unknow quotation: {}'.format(quotation))
|
||||
return ()
|
||||
result = []
|
||||
for quotation in quotations:
|
||||
new_quotation = quotation.lower()
|
||||
if new_quotation == 'stock':
|
||||
result += [STOCKTYPE_A, STOCKTYPE_INDEX, STOCKTYPE_B, STOCKTYPE_GEM]
|
||||
elif new_quotation == 'fund':
|
||||
result += [STOCKTYPE_FUND, STOCKTYPE_ETF]
|
||||
elif new_quotation == 'bond':
|
||||
result += [STOCKTYPE_ND, STOCKTYPE_BOND]
|
||||
else:
|
||||
print('Unknow quotation: {}'.format(quotation))
|
||||
|
||||
return tuple(result)
|
@ -63,8 +63,8 @@ def get_marketid(connect, market):
|
||||
return marketid
|
||||
|
||||
|
||||
def get_codepre_list(connect, marketid, quotation):
|
||||
stktype_list = get_stktype_list(quotation)
|
||||
def get_codepre_list(connect, marketid, quotations):
|
||||
stktype_list = get_stktype_list(quotations)
|
||||
sql = "select codepre, type from coderuletype " \
|
||||
"where marketid={marketid} and type in {type_list}"\
|
||||
.format(marketid=marketid, type_list=stktype_list)
|
||||
@ -75,7 +75,7 @@ def get_codepre_list(connect, marketid, quotation):
|
||||
return sorted(a, key=lambda k: len(k[0]), reverse=True)
|
||||
|
||||
|
||||
def tdx_import_stock_name_from_file(connect, filename, market, quotation=None):
|
||||
def tdx_import_stock_name_from_file(connect, filename, market, quotations=None):
|
||||
"""更新每只股票的名称、当前是否有效性、起始日期及结束日期
|
||||
如果导入的代码表中不存在对应的代码,则认为该股已失效
|
||||
|
||||
@ -104,7 +104,9 @@ def tdx_import_stock_name_from_file(connect, filename, market, quotation=None):
|
||||
marketid = [i for i in a]
|
||||
marketid = marketid[0][0]
|
||||
|
||||
a = cur.execute("select stockid, code, name, valid from stock where marketid = %i" % marketid)
|
||||
stktype_list = get_stktype_list(quotations)
|
||||
a = cur.execute("select stockid, code, name, valid from stock where marketid={} and type in {}"
|
||||
.format(marketid, stktype_list))
|
||||
a = a.fetchall()
|
||||
oldStockDict = {}
|
||||
for oldstock in a:
|
||||
@ -124,7 +126,7 @@ def tdx_import_stock_name_from_file(connect, filename, market, quotation=None):
|
||||
cur.execute("update stock set valid=1, endDate=99999999 where stockid=%i" % oldstockid)
|
||||
|
||||
# 处理新出现的股票
|
||||
codepre_list = get_codepre_list(connect, marketid, quotation)
|
||||
codepre_list = get_codepre_list(connect, marketid, quotations)
|
||||
|
||||
today = datetime.date.today()
|
||||
today = today.year * 10000 + today.month * 100 + today.day
|
||||
@ -331,7 +333,7 @@ def tdx_import_min_data_from_file(connect, filename, h5file, market, stock_recor
|
||||
|
||||
return add_record_count
|
||||
|
||||
def tdx_import_data(connect, market, ktype, quotation, src_dir, dest_dir, progress=ProgressBar):
|
||||
def tdx_import_data(connect, market, ktype, quotations, src_dir, dest_dir, progress=ProgressBar):
|
||||
"""
|
||||
导入通达信日线数据,只导入基础信息数据库中存在的股票
|
||||
"""
|
||||
@ -353,7 +355,7 @@ def tdx_import_data(connect, market, ktype, quotation, src_dir, dest_dir, progre
|
||||
func_import_from_file = tdx_import_min_data_from_file
|
||||
|
||||
marketid = get_marketid(connect, market)
|
||||
stktype_list = get_stktype_list(quotation)
|
||||
stktype_list = get_stktype_list(quotations)
|
||||
sql = "select stockid, marketid, code, valid, type from stock where marketid={} and type in {}".format(marketid, stktype_list)
|
||||
|
||||
cur = connect.cursor()
|
||||
@ -617,12 +619,15 @@ if __name__ == '__main__':
|
||||
create_database(connect)
|
||||
|
||||
print("导入股票代码表")
|
||||
tdx_import_stock_name_from_file(connect, src_dir + "\\T0002\\hq_cache\\shm.tnf", 'SH', 'stock')
|
||||
tdx_import_stock_name_from_file(connect, src_dir + "\\T0002\\hq_cache\\szm.tnf", 'SZ', 'stock')
|
||||
tdx_import_stock_name_from_file(connect, src_dir + "\\T0002\\hq_cache\\shm.tnf", 'SH', ['stock', 'fund'])
|
||||
tdx_import_stock_name_from_file(connect, src_dir + "\\T0002\\hq_cache\\szm.tnf", 'SZ', ['stock', 'fund'])
|
||||
|
||||
print("\n导入上证日线数据")
|
||||
add_count = 0
|
||||
#add_count = tdx_import_data(connect, 'SH', 'DAY', 'stock', src_dir + "\\vipdoc\\sh\\lday", dest_dir)
|
||||
add_count = tdx_import_data(connect, 'SH', 'DAY', ['stock', 'fund'], src_dir + "\\vipdoc\\sh\\lday", dest_dir)
|
||||
#add_count = tdx_import_data(connect, 'SZ', 'DAY', 'stock', src_dir + "\\vipdoc\\sz\\lday", dest_dir)
|
||||
print("\n导入数量:", add_count)
|
||||
|
||||
print("\n导入上证5分钟数据")
|
||||
#add_count = tdx_import_data(connect, 'SH', '5MIN', 'stock', src_dir + "\\vipdoc\\sh\\fzline", dest_dir)
|
||||
print("\n导入数量:", add_count)
|
||||
@ -632,8 +637,9 @@ if __name__ == '__main__':
|
||||
print("\n导入数量:", add_count)
|
||||
|
||||
print("\n导入权息数据")
|
||||
total_count = qianlong_import_weight(connect, r'C:\stock\weight', 'SH')
|
||||
total_count += qianlong_import_weight(connect, r'C:\stock\weight', 'SZ')
|
||||
total_count = 0
|
||||
#total_count = qianlong_import_weight(connect, r'C:\stock\weight', 'SH')
|
||||
#total_count += qianlong_import_weight(connect, r'C:\stock\weight', 'SZ')
|
||||
print(total_count)
|
||||
|
||||
connect.close()
|
||||
|
@ -49,7 +49,6 @@ class MyMainWindow(QMainWindow, Ui_MainWindow):
|
||||
|
||||
#初始化导入行情数据类型配置
|
||||
self.import_stock_checkBox.setChecked(import_config.getboolean('quotation', 'stock', fallback=True))
|
||||
self.import_bond_checkBox.setChecked(import_config.getboolean('quotation', 'bond', fallback=False))
|
||||
self.import_fund_checkBox.setChecked(import_config.getboolean('quotation', 'fund', fallback=True))
|
||||
self.import_future_checkBox.setChecked(import_config.getboolean('quotation', 'future', fallback=False))
|
||||
|
||||
@ -103,7 +102,6 @@ class MyMainWindow(QMainWindow, Ui_MainWindow):
|
||||
def getCurrentConfig(self):
|
||||
import_config = ConfigParser()
|
||||
import_config['quotation'] = {'stock': self.import_stock_checkBox.isChecked(),
|
||||
'bond': self.import_bond_checkBox.isChecked(),
|
||||
'fund': self.import_fund_checkBox.isChecked(),
|
||||
'future': self.import_future_checkBox.isChecked()}
|
||||
import_config['ktype'] = {'day': self.import_day_checkBox.isChecked(),
|
||||
@ -178,6 +176,8 @@ class MyMainWindow(QMainWindow, Ui_MainWindow):
|
||||
self.hdf5_min_progressBar.setValue(0)
|
||||
self.hdf5_5min_progressBar.setValue(0)
|
||||
|
||||
self.import_count = {'SH': {'DAY': 0, '1MIN': 0, '5MIN': 0},
|
||||
'SZ': {'DAY': 0, '1MIN': 0, '5MIN': 0}}
|
||||
|
||||
def on_escapte_time(self, escape):
|
||||
self.import_status_label.setText("耗时:{:>.2f} 秒".format(escape))
|
||||
@ -190,10 +190,9 @@ class MyMainWindow(QMainWindow, Ui_MainWindow):
|
||||
msg_name, msg_task_name = msg[:2]
|
||||
if msg_name == 'ESCAPE_TIME':
|
||||
self.escape_time = msg_task_name
|
||||
self.import_status_label.setText("耗时:{:>.2f} 秒".format(self.escape_time))
|
||||
self.import_status_label.setText("耗时:{:>.2f} 秒 ({:>.2f}分钟)".format(self.escape_time, self.escape_time/60))
|
||||
|
||||
elif msg_name == 'HDF5_IMPORT':
|
||||
#self.import_status_label.setText("耗时:{:>.2f} 秒 {}".format(self.escape_time, msg_task_name))
|
||||
if msg_task_name == 'THREAD':
|
||||
status = msg[2]
|
||||
if status == 'FAILURE':
|
||||
@ -202,13 +201,15 @@ class MyMainWindow(QMainWindow, Ui_MainWindow):
|
||||
self.hdf5_import_thread = None
|
||||
self.escape_time_thread.stop()
|
||||
self.escape_time_thread = None
|
||||
self.start_import_pushButton.setEnabled(True)
|
||||
|
||||
elif msg_task_name == 'IMPORT_KDATA':
|
||||
ktype, progress = msg[2:4]
|
||||
if ktype != 'FINISHED':
|
||||
self.hdf5_import_progress_bar[ktype].setValue(progress)
|
||||
#else:
|
||||
# print('导入记录数:', ktype, progress)
|
||||
else:
|
||||
print('导入记录数:', msg[3:])
|
||||
#self.import_count[msg[3]][msg[4]] = msg[5]
|
||||
|
||||
elif msg_task_name == 'IMPORT_WEIGHT':
|
||||
self.hdf5_weight_label.setText(msg[2])
|
||||
@ -226,82 +227,10 @@ class MyMainWindow(QMainWindow, Ui_MainWindow):
|
||||
self.escape_time_thread.start()
|
||||
|
||||
config = self.getCurrentConfig()
|
||||
self.hdf5_import_thread = HDF5ImportThread(config, ['stock'], ['DAY', '1MIN', '5MIN'])
|
||||
self.hdf5_import_thread = HDF5ImportThread(config)
|
||||
self.hdf5_import_thread.message.connect(self.on_message_from_thread)
|
||||
self.hdf5_import_thread.start()
|
||||
|
||||
"""
|
||||
config = self.getCurrentConfig()
|
||||
src_dir = "D:\\TdxW_HuaTai"
|
||||
dest_dir = "c:\\stock"
|
||||
|
||||
hdf5_import_progress = {'SH': {'DAY': 0, '1MIN': 0, '5MIN': 0},
|
||||
'SZ': {'DAY': 0, '1MIN': 0, '5MIN': 0}}
|
||||
hdf5_import_progress_bar = {'DAY': self.hdf5_day_progressBar,
|
||||
'1MIN': self.hdf5_min_progressBar,
|
||||
'5MIN': self.hdf5_5min_progressBar}
|
||||
|
||||
|
||||
try:
|
||||
self.import_status_label.setText('正在导入代码表...')
|
||||
import sqlite3
|
||||
connect = sqlite3.connect(dest_dir + "\\hikyuu-stock.db")
|
||||
create_database(connect)
|
||||
tdx_import_stock_name_from_file(connect, src_dir + "\\T0002\\hq_cache\\shm.tnf", 'SH', 'stock')
|
||||
tdx_import_stock_name_from_file(connect, src_dir + "\\T0002\\hq_cache\\szm.tnf", 'SZ', 'stock')
|
||||
|
||||
self.import_status_label.setText('正在创建导入任务...')
|
||||
tasks = []
|
||||
tasks.append(self.tasks['DOWNLOAD_WEIGHT'])
|
||||
if self.import_day_checkBox.isChecked():
|
||||
tasks.append(self.tasks['HDF5_IMPORT_SH_DAY'])
|
||||
tasks.append(self.tasks['HDF5_IMPORT_SZ_DAY'])
|
||||
if self.import_min5_checkBox.isChecked():
|
||||
tasks.append(self.tasks['HDF5_IMPORT_SH_5MIN'])
|
||||
tasks.append(self.tasks['HDF5_IMPORT_SZ_5MIN'])
|
||||
if self.import_min_checkBox.isChecked():
|
||||
tasks.append(self.tasks['HDF5_IMPORT_SH_1MIN'])
|
||||
tasks.append(self.tasks['HDF5_IMPORT_SZ_1MIN'])
|
||||
|
||||
for task in tasks:
|
||||
p = Process(target=task)
|
||||
p.start()
|
||||
|
||||
start_time = time.time()
|
||||
finished_count = len(tasks)
|
||||
while finished_count > 0:
|
||||
QApplication.processEvents()
|
||||
message = self.queue.get()
|
||||
taskname, market, ktype, progress, total = message
|
||||
if progress is None:
|
||||
finished_count -= 1
|
||||
continue
|
||||
|
||||
if taskname == 'WeightDownloadTask':
|
||||
self.hdf5_weight_label.setText(market)
|
||||
elif taskname == 'TdxImportTask':
|
||||
hdf5_import_progress[market][ktype] = progress
|
||||
current_progress = (hdf5_import_progress['SH'][ktype] + hdf5_import_progress['SZ'][ktype]) // 2
|
||||
hdf5_import_progress_bar[ktype].setValue(current_progress)
|
||||
else:
|
||||
print("Unknow task: ", taskname)
|
||||
|
||||
current_time = time.time()
|
||||
self.import_status_label.setText("耗时:{:>.2f} 秒".format(current_time - start_time))
|
||||
|
||||
except Exception as e:
|
||||
print(e)
|
||||
|
||||
current_time = time.time()
|
||||
self.import_status_label.setText("耗时:{:>.2f} 秒 导入完毕!".format(current_time - start_time))
|
||||
self.start_import_pushButton.setEnabled(True)
|
||||
|
||||
escape_thread.stop()
|
||||
|
||||
#self.start_unrar_process()
|
||||
#print("self.unrar_future.result:", self.unrar_future.result())
|
||||
"""
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user