mirror of
https://gitee.com/fasiondog/hikyuu.git
synced 2024-11-30 02:48:57 +08:00
更改数据导入工具
This commit is contained in:
parent
f1a6eb3d90
commit
4d438971c1
@ -117,7 +117,7 @@ def get_stock_list(connect, market, quotations):
|
||||
|
||||
|
||||
def get_table(connect, market, code, ktype):
|
||||
"""note: market: 'DAY' | 'MIN' | 'MIN5' """
|
||||
"""note: ktype: 'DAY' | 'MIN' | 'MIN5' """
|
||||
cur = connect.cursor()
|
||||
schema = "{market}_{ktype}".format(market=market, ktype=ktype).lower()
|
||||
cur.execute("SELECT 1 FROM information_schema.SCHEMATA where SCHEMA_NAME='{}'".format(schema))
|
||||
|
@ -64,10 +64,9 @@ sh_trans = {dir}/sh_trans.h5
|
||||
sz_trans = {dir}/sz_trans.h5
|
||||
"""
|
||||
|
||||
|
||||
mysql_template = """
|
||||
[hikyuu]
|
||||
tmpdir = {dir}/tmp
|
||||
tmpdir = {dir}
|
||||
|
||||
[block]
|
||||
type = qianlong
|
||||
|
@ -75,7 +75,7 @@ def pytdx_import_weight_to_mysql(pytdx_api, connect, market):
|
||||
records = {}
|
||||
for xdxr in xdxr_list:
|
||||
try:
|
||||
date = xdxr['year'] * 1000 + xdxr['month'] * 100 + xdxr['day']
|
||||
date = xdxr['year'] * 10000 + xdxr['month'] * 100 + xdxr['day']
|
||||
if date < db_last_date:
|
||||
continue
|
||||
if date == db_last_date and new_last_db_weight is not None:
|
||||
|
@ -74,7 +74,7 @@ def pytdx_import_weight_to_sqlite(pytdx_api, connect, market):
|
||||
records = {}
|
||||
for xdxr in xdxr_list:
|
||||
try:
|
||||
date = xdxr['year'] * 1000 + xdxr['month'] * 100 + xdxr['day']
|
||||
date = xdxr['year'] * 10000 + xdxr['month'] * 100 + xdxr['day']
|
||||
if date < db_last_date:
|
||||
continue
|
||||
if date == db_last_date and new_last_db_weight is not None:
|
||||
|
@ -57,15 +57,31 @@ class MyMainWindow(QMainWindow, Ui_MainWindow):
|
||||
current_config.write(f)
|
||||
|
||||
filename = self.getUserConfigDir() + '/hikyuu.ini'
|
||||
data_dir = current_config['hdf5']['dir']
|
||||
if current_config.getboolean('hdf5', 'enable', fallback=True):
|
||||
data_dir = current_config['hdf5']['dir']
|
||||
if not os.path.lexists(data_dir + '/tmp'):
|
||||
os.mkdir(data_dir + '/tmp')
|
||||
|
||||
# 此处不能使用 utf-8 参数,否则导致Windows下getBlock无法找到板块分类
|
||||
# with open(filename, 'w', encoding='utf-8') as f:
|
||||
with open(filename, 'w') as f:
|
||||
f.write(hku_config_template.hdf5_template.format(dir=data_dir))
|
||||
else:
|
||||
data_dir = current_config['mysql']['tmpdir']
|
||||
with open(filename, 'w') as f:
|
||||
f.write(
|
||||
hku_config_template.mysql_template.format(
|
||||
dir=data_dir,
|
||||
host=current_config['mysql']['host'],
|
||||
port=current_config['mysql']['port'],
|
||||
usr=current_config['mysql']['usr'],
|
||||
pwd=current_config['mysql']['pwd']
|
||||
)
|
||||
)
|
||||
|
||||
if not os.path.lexists(data_dir):
|
||||
os.makedirs(data_dir)
|
||||
|
||||
# 此处不能使用 utf-8 参数,否则导致Windows下getBlock无法找到板块分类
|
||||
# with open(filename, 'w', encoding='utf-8') as f:
|
||||
with open(filename, 'w') as f:
|
||||
f.write(hku_config_template.hdf5_template.format(dir=data_dir))
|
||||
|
||||
if not os.path.lexists(data_dir + '/block'):
|
||||
current_dir = os.path.dirname(os.path.abspath(__file__))
|
||||
dirname, _ = os.path.split(current_dir)
|
||||
@ -73,9 +89,6 @@ class MyMainWindow(QMainWindow, Ui_MainWindow):
|
||||
shutil.copytree(dirname, data_dir + '/block')
|
||||
os.remove(data_dir + '/block/__init__.py')
|
||||
|
||||
if not os.path.lexists(data_dir + '/tmp'):
|
||||
os.mkdir(data_dir + '/tmp')
|
||||
|
||||
def initUI(self):
|
||||
current_dir = os.path.dirname(__file__)
|
||||
self.setWindowIcon(QIcon("{}/hikyuu.ico".format(current_dir)))
|
||||
@ -164,7 +177,10 @@ class MyMainWindow(QMainWindow, Ui_MainWindow):
|
||||
if hdf5_enable:
|
||||
mysql_enable = False
|
||||
self.enable_mysql_radioButton.setChecked(mysql_enable)
|
||||
mysql_ip = import_config.get('mysql', 'ip', fallback='127.0.0.1')
|
||||
self.mysql_tmpdir_lineEdit.setText(
|
||||
import_config.get('mysql', 'tmpdir', fallback='c:\stock')
|
||||
)
|
||||
mysql_ip = import_config.get('mysql', 'host', fallback='127.0.0.1')
|
||||
self.mysql_ip_lineEdit.setText(mysql_ip)
|
||||
self.mysql_ip_lineEdit.setEnabled(mysql_enable)
|
||||
mysql_port = import_config.get('mysql', 'port', fallback='3306')
|
||||
@ -216,7 +232,8 @@ class MyMainWindow(QMainWindow, Ui_MainWindow):
|
||||
}
|
||||
import_config['mysql'] = {
|
||||
'enable': self.enable_mysql_radioButton.isChecked(),
|
||||
'ip': self.mysql_ip_lineEdit.text(),
|
||||
'tmpdir': self.mysql_tmpdir_lineEdit.text(),
|
||||
'host': self.mysql_ip_lineEdit.text(),
|
||||
'port': self.mysql_port_lineEdit.text(),
|
||||
'usr': self.mysql_usr_lineEdit.text(),
|
||||
'pwd': self.mysql_pwd_lineEdit.text()
|
||||
@ -299,6 +316,16 @@ class MyMainWindow(QMainWindow, Ui_MainWindow):
|
||||
self.mysql_pwd_lineEdit.setEnabled(mysql_enable)
|
||||
self.mysql_test_pushButton.setEnabled(mysql_enable)
|
||||
|
||||
@pyqtSlot()
|
||||
def on_mysql_tmpdir_pushButton_clicked(self):
|
||||
dlg = QFileDialog()
|
||||
dlg.setFileMode(QFileDialog.Directory)
|
||||
config = self.getCurrentConfig()
|
||||
dlg.setDirectory(config['mysql']['tmpdir'])
|
||||
if dlg.exec_():
|
||||
dirname = dlg.selectedFiles()
|
||||
self.mysql_tmpdir_lineEdit.setText(dirname[0])
|
||||
|
||||
@pyqtSlot()
|
||||
def on_mysql_test_pushButton_clicked(self):
|
||||
"""测试数据库连接"""
|
||||
|
@ -64,7 +64,7 @@ class ImportPytdxToH5:
|
||||
db_config = {
|
||||
'user': self.config['mysql']['usr'],
|
||||
'password': self.config['mysql']['pwd'],
|
||||
'host': self.config['mysql']['ip'],
|
||||
'host': self.config['mysql']['host'],
|
||||
'port': self.config['mysql']['port']
|
||||
}
|
||||
connect = mysql.connector.connect(**db_config)
|
||||
|
@ -55,7 +55,7 @@ class ImportWeightToSqliteTask:
|
||||
db_config = {
|
||||
'user': self.config['mysql']['usr'],
|
||||
'password': self.config['mysql']['pwd'],
|
||||
'host': self.config['mysql']['ip'],
|
||||
'host': self.config['mysql']['host'],
|
||||
'port': self.config['mysql']['port']
|
||||
}
|
||||
connect = mysql.connector.connect(**db_config)
|
||||
|
@ -168,10 +168,10 @@ class Ui_MainWindow(object):
|
||||
self.tab_3 = QtWidgets.QWidget()
|
||||
self.tab_3.setObjectName("tab_3")
|
||||
self.groupBox = QtWidgets.QGroupBox(self.tab_3)
|
||||
self.groupBox.setGeometry(QtCore.QRect(20, 250, 551, 191))
|
||||
self.groupBox.setGeometry(QtCore.QRect(20, 240, 551, 241))
|
||||
self.groupBox.setObjectName("groupBox")
|
||||
self.layoutWidget = QtWidgets.QWidget(self.groupBox)
|
||||
self.layoutWidget.setGeometry(QtCore.QRect(20, 30, 401, 131))
|
||||
self.layoutWidget.setGeometry(QtCore.QRect(20, 80, 421, 131))
|
||||
self.layoutWidget.setObjectName("layoutWidget")
|
||||
self.gridLayout_5 = QtWidgets.QGridLayout(self.layoutWidget)
|
||||
self.gridLayout_5.setContentsMargins(0, 0, 0, 0)
|
||||
@ -201,8 +201,23 @@ class Ui_MainWindow(object):
|
||||
self.mysql_pwd_lineEdit.setObjectName("mysql_pwd_lineEdit")
|
||||
self.gridLayout_5.addWidget(self.mysql_pwd_lineEdit, 3, 1, 1, 1)
|
||||
self.mysql_test_pushButton = QtWidgets.QPushButton(self.groupBox)
|
||||
self.mysql_test_pushButton.setGeometry(QtCore.QRect(450, 80, 75, 23))
|
||||
self.mysql_test_pushButton.setGeometry(QtCore.QRect(450, 130, 75, 23))
|
||||
self.mysql_test_pushButton.setObjectName("mysql_test_pushButton")
|
||||
self.widget = QtWidgets.QWidget(self.groupBox)
|
||||
self.widget.setGeometry(QtCore.QRect(20, 30, 501, 25))
|
||||
self.widget.setObjectName("widget")
|
||||
self.horizontalLayout_5 = QtWidgets.QHBoxLayout(self.widget)
|
||||
self.horizontalLayout_5.setContentsMargins(0, 0, 0, 0)
|
||||
self.horizontalLayout_5.setObjectName("horizontalLayout_5")
|
||||
self.label_20 = QtWidgets.QLabel(self.widget)
|
||||
self.label_20.setObjectName("label_20")
|
||||
self.horizontalLayout_5.addWidget(self.label_20)
|
||||
self.mysql_tmpdir_lineEdit = QtWidgets.QLineEdit(self.widget)
|
||||
self.mysql_tmpdir_lineEdit.setObjectName("mysql_tmpdir_lineEdit")
|
||||
self.horizontalLayout_5.addWidget(self.mysql_tmpdir_lineEdit)
|
||||
self.mysql_tmpdir_pushButton = QtWidgets.QPushButton(self.widget)
|
||||
self.mysql_tmpdir_pushButton.setObjectName("mysql_tmpdir_pushButton")
|
||||
self.horizontalLayout_5.addWidget(self.mysql_tmpdir_pushButton)
|
||||
self.groupBox_3 = QtWidgets.QGroupBox(self.tab_3)
|
||||
self.groupBox_3.setGeometry(QtCore.QRect(20, 130, 551, 71))
|
||||
self.groupBox_3.setObjectName("groupBox_3")
|
||||
@ -333,6 +348,8 @@ class Ui_MainWindow(object):
|
||||
self.label_11.setText(_translate("MainWindow", "用户名:"))
|
||||
self.label_13.setText(_translate("MainWindow", "密码"))
|
||||
self.mysql_test_pushButton.setText(_translate("MainWindow", "测试连接"))
|
||||
self.label_20.setText(_translate("MainWindow", "临时文件目录:"))
|
||||
self.mysql_tmpdir_pushButton.setText(_translate("MainWindow", "选择"))
|
||||
self.groupBox_3.setTitle(_translate("MainWindow", "HDF5存储设置"))
|
||||
self.hdf5_dir_pushButton.setText(_translate("MainWindow", "选择"))
|
||||
self.label.setText(_translate("MainWindow", "目标数据(HDF5)存放目录:"))
|
||||
|
@ -372,9 +372,9 @@
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>20</x>
|
||||
<y>250</y>
|
||||
<y>240</y>
|
||||
<width>551</width>
|
||||
<height>191</height>
|
||||
<height>241</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="title">
|
||||
@ -384,8 +384,8 @@
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>20</x>
|
||||
<y>30</y>
|
||||
<width>401</width>
|
||||
<y>80</y>
|
||||
<width>421</width>
|
||||
<height>131</height>
|
||||
</rect>
|
||||
</property>
|
||||
@ -436,7 +436,7 @@
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>450</x>
|
||||
<y>80</y>
|
||||
<y>130</y>
|
||||
<width>75</width>
|
||||
<height>23</height>
|
||||
</rect>
|
||||
@ -445,6 +445,35 @@
|
||||
<string>测试连接</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QWidget" name="">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>20</x>
|
||||
<y>30</y>
|
||||
<width>501</width>
|
||||
<height>25</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_5">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_20">
|
||||
<property name="text">
|
||||
<string>临时文件目录:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="mysql_tmpdir_lineEdit"/>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="mysql_tmpdir_pushButton">
|
||||
<property name="text">
|
||||
<string>选择</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
<widget class="QGroupBox" name="groupBox_3">
|
||||
<property name="geometry">
|
||||
|
@ -257,7 +257,7 @@ class UsePytdxImportToH5Thread(QThread):
|
||||
db_config = {
|
||||
'user': self.config['mysql']['usr'],
|
||||
'password': self.config['mysql']['pwd'],
|
||||
'host': self.config['mysql']['ip'],
|
||||
'host': self.config['mysql']['host'],
|
||||
'port': self.config['mysql']['port']
|
||||
}
|
||||
connect = mysql.connector.connect(**db_config)
|
||||
|
Loading…
Reference in New Issue
Block a user