diff --git a/hikyuu/data/common_mysql.py b/hikyuu/data/common_mysql.py index 6a1fee3e..54dc4d69 100644 --- a/hikyuu/data/common_mysql.py +++ b/hikyuu/data/common_mysql.py @@ -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)) diff --git a/hikyuu/data/hku_config_template.py b/hikyuu/data/hku_config_template.py index 0da40785..99390ae8 100644 --- a/hikyuu/data/hku_config_template.py +++ b/hikyuu/data/hku_config_template.py @@ -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 diff --git a/hikyuu/data/pytdx_weight_to_mysql.py b/hikyuu/data/pytdx_weight_to_mysql.py index 0164efb2..6d87f30e 100644 --- a/hikyuu/data/pytdx_weight_to_mysql.py +++ b/hikyuu/data/pytdx_weight_to_mysql.py @@ -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: diff --git a/hikyuu/data/pytdx_weight_to_sqlite.py b/hikyuu/data/pytdx_weight_to_sqlite.py index 9c737b30..26d1dfe0 100644 --- a/hikyuu/data/pytdx_weight_to_sqlite.py +++ b/hikyuu/data/pytdx_weight_to_sqlite.py @@ -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: diff --git a/hikyuu/gui/HikyuuTDX.py b/hikyuu/gui/HikyuuTDX.py index 551d43bd..ba8736ec 100644 --- a/hikyuu/gui/HikyuuTDX.py +++ b/hikyuu/gui/HikyuuTDX.py @@ -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): """测试数据库连接""" diff --git a/hikyuu/gui/data/ImportPytdxToH5Task.py b/hikyuu/gui/data/ImportPytdxToH5Task.py index b83d6f1d..63523d6d 100644 --- a/hikyuu/gui/data/ImportPytdxToH5Task.py +++ b/hikyuu/gui/data/ImportPytdxToH5Task.py @@ -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) diff --git a/hikyuu/gui/data/ImportWeightToSqliteTask.py b/hikyuu/gui/data/ImportWeightToSqliteTask.py index da7bf2c2..c2834f1c 100644 --- a/hikyuu/gui/data/ImportWeightToSqliteTask.py +++ b/hikyuu/gui/data/ImportWeightToSqliteTask.py @@ -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) diff --git a/hikyuu/gui/data/MainWindow.py b/hikyuu/gui/data/MainWindow.py index ace48502..c914b275 100644 --- a/hikyuu/gui/data/MainWindow.py +++ b/hikyuu/gui/data/MainWindow.py @@ -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)存放目录:")) diff --git a/hikyuu/gui/data/MainWindow.ui b/hikyuu/gui/data/MainWindow.ui index 9d1324ae..dc9fb695 100644 --- a/hikyuu/gui/data/MainWindow.ui +++ b/hikyuu/gui/data/MainWindow.ui @@ -372,9 +372,9 @@ 20 - 250 + 240 551 - 191 + 241 @@ -384,8 +384,8 @@ 20 - 30 - 401 + 80 + 421 131 @@ -436,7 +436,7 @@ 450 - 80 + 130 75 23 @@ -445,6 +445,35 @@ 测试连接 + + + + 20 + 30 + 501 + 25 + + + + + + + 临时文件目录: + + + + + + + + + + 选择 + + + + + diff --git a/hikyuu/gui/data/UsePytdxImportToH5Thread.py b/hikyuu/gui/data/UsePytdxImportToH5Thread.py index 3c3c5003..55af701f 100644 --- a/hikyuu/gui/data/UsePytdxImportToH5Thread.py +++ b/hikyuu/gui/data/UsePytdxImportToH5Thread.py @@ -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)