Skip to content

Commit

Permalink
调整 mysql 默认字符集;HikyuuTdX 控制台日志打印级别
Browse files Browse the repository at this point in the history
  • Loading branch information
fasiondog committed Apr 18, 2024
1 parent e80ed76 commit 69f9bae
Show file tree
Hide file tree
Showing 10 changed files with 2,704 additions and 791 deletions.
36 changes: 18 additions & 18 deletions hikyuu/data/common_mysql.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,20 +61,20 @@ def create_database(connect):
with open(filename, 'r', encoding='utf8') as f:
sql = f.read()
for x in cur.execute(sql, multi=True):
#print(x.statement)
# print(x.statement)
pass

db_version = get_db_version(connect)
files = [x for x in Path(sql_dir).iterdir() \
if x.is_file() \
and x.name != 'createdb.sql' \
and x.name != '__init__.py' \
and int(x.stem) > db_version and not x.is_dir()]
files = [x for x in Path(sql_dir).iterdir()
if x.is_file()
and x.name != 'createdb.sql'
and x.name != '__init__.py'
and int(x.stem) > db_version and not x.is_dir()]
files.sort()
for file in files:
sql = file.read_text(encoding='utf8')
for x in cur.execute(sql, multi=True):
#print(x.statement)
# print(x.statement)
pass

connect.commit()
Expand Down Expand Up @@ -177,7 +177,7 @@ def get_table(connect, market, code, ktype):
`count` DOUBLE UNSIGNED NOT NULL,
PRIMARY KEY (`date`)
)
COLLATE='utf8_general_ci'
COLLATE='utf8mb4_general_ci'
ENGINE=MyISAM
;
""".format(schema=schema, name=tablename)
Expand Down Expand Up @@ -252,7 +252,7 @@ def getMin60Date(olddate):
startdate = newdate + 1401
enddate = newdate + 1500
return (startdate, enddate)

def getHour2Date(olddate):
mint = olddate - olddate // 10000 * 10000
newdate = olddate // 10000 * 10000
Expand All @@ -263,7 +263,7 @@ def getHour2Date(olddate):
startdate = newdate + 1301
enddate = newdate + 1500
return (startdate, enddate)

def getMin15Date(olddate):
mint = olddate - olddate // 10000 * 10000
newdate = olddate // 10000 * 10000
Expand Down Expand Up @@ -374,7 +374,7 @@ def getNewDate(index_type, olddate):
base_table = get_table(connect, market, code, 'day')
else:
index_list = ('min15', 'min30', 'min60', 'hour2')
#index_list = ('min15', )
# index_list = ('min15', )
base_table = get_table(connect, market, code, 'min5')

base_lastdate = get_lastdatetime(connect, base_table)
Expand Down Expand Up @@ -407,23 +407,23 @@ def getNewDate(index_type, olddate):

update_buffer = []
insert_buffer = []
#for current_base in base_list:
# for current_base in base_list:
length_base_all = len(base_list)
for x in range(length_base_all):
current_date = base_list[x][0]
if current_date <= last_end_date:
continue
last_start_date, last_end_date = getNewDate(index_type, current_date)

#cur = connect.cursor()
#cur.execute(
# cur = connect.cursor()
# cur.execute(
# 'select date, open, high, low, close, amount, count from {} \
# where date>={} and date<={} order by date asc'.format(
# base_table, last_start_date, last_end_date
# )
#)
#base_record_list = [r for r in cur]
#cur.close()
# )
# base_record_list = [r for r in cur]
# cur.close()
base_record_list = []
start_ix = x
ix_date = current_date
Expand Down Expand Up @@ -482,4 +482,4 @@ def getNewDate(index_type, olddate):
cnx = mysql.connector.connect(user=usr, password=pwd, host=host, port=port)

update_extern_data(cnx, 'SH', '000001', 'day')
cnx.close()
cnx.close()
9 changes: 4 additions & 5 deletions hikyuu/data/mysql_upgrade/0001.sql
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
CREATE TABLE `hku_base`.`version` (
`version` INT(11) UNSIGNED NOT NULL
)
COLLATE='utf8_general_ci'
ENGINE=InnoDB;
INSERT INTO `hku_base`.`version` (version) VALUES (1);
`version` INT(11) UNSIGNED NOT NULL
) COLLATE = 'utf8mb4_general_ci' ENGINE = InnoDB;

INSERT INTO `hku_base`.`version` (version) VALUES (1);
78 changes: 33 additions & 45 deletions hikyuu/data/mysql_upgrade/0009.sql
Original file line number Diff line number Diff line change
@@ -1,48 +1,36 @@
CREATE TABLE IF NOT EXISTS `hku_base`.`stkfinance` (
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
`stockid` INT UNSIGNED NOT NULL,
`updated_date` INT NOT NULL,
`ipo_date` INT NOT NULL, -- 42.上市日期
`province` DOUBLE NOT NULL,
`industry` DOUBLE NOT NULL,
`zongguben` DOUBLE NOT NULL, -- 1.总股本(股)
`liutongguben` DOUBLE NOT NULL, -- 7.流通A股(股)
`guojiagu` DOUBLE NOT NULL, -- 2.国家股(股)
`faqirenfarengu` DOUBLE NOT NULL, -- 3.发起人法人股(股)
`farengu` DOUBLE NOT NULL, -- 4.法人股(股)
`bgu` DOUBLE NOT NULL, -- 5.B股(股)
`hgu` DOUBLE NOT NULL, -- 6.H股(股)
`zhigonggu` DOUBLE NOT NULL, -- 8.职工股(股)
`zongzichan` DOUBLE NOT NULL, -- 10.总资产(元)
`liudongzichan` DOUBLE NOT NULL, -- 11.流动资产(元)
`gudingzichan` DOUBLE NOT NULL, -- 12.固定资产(元)
`wuxingzichan` DOUBLE NOT NULL, -- 13.无形资产(元)
`gudongrenshu` DOUBLE NOT NULL, -- 股东人数
`liudongfuzhai` DOUBLE NOT NULL, -- 15.流动负债
`changqifuzhai` DOUBLE NOT NULL, -- 16.长期负债
`zibengongjijin` DOUBLE NOT NULL, -- 17.资本公积金
`jingzichan` DOUBLE NOT NULL, -- 净资产(元)
`zhuyingshouru` DOUBLE NOT NULL, -- 20.主营收入
`zhuyinglirun` DOUBLE NOT NULL, -- 21.主营利润
`yingshouzhangkuan` DOUBLE NOT NULL, -- 应收账款
`yingyelirun` DOUBLE NOT NULL, -- 23.营业利润
`touzishouyu` DOUBLE NOT NULL, -- 投资收益
`jingyingxianjinliu` DOUBLE NOT NULL, -- 经营现金流
`zongxianjinliu` DOUBLE NOT NULL, -- 总现金流
`cunhuo` DOUBLE NOT NULL, -- 存货
`lirunzonghe` DOUBLE NOT NULL, -- 28.利润总额
`shuihoulirun` DOUBLE NOT NULL, -- 29.税后利润
`jinglirun` DOUBLE NOT NULL, -- 30.净利润
`weifenpeilirun` DOUBLE NOT NULL, -- 31.未分配利润
`meigujingzichan` DOUBLE NOT NULL, -- 34.每股净资产
`baoliu2` DOUBLE NOT NULL,
PRIMARY KEY (`id`),
FOREIGN KEY(`stockid`) REFERENCES `hku_base`.`stock` (`stockid`),
INDEX `ix_stkfinance_date` (`updated_date`),
INDEX `ix_stkfinance_stock_date` (`stockid`, `updated_date`)
)
COLLATE='utf8_general_ci'
ENGINE=InnoDB
;
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT, `stockid` INT UNSIGNED NOT NULL, `updated_date` INT NOT NULL, `ipo_date` INT NOT NULL, -- 42.上市日期
`province` DOUBLE NOT NULL, `industry` DOUBLE NOT NULL, `zongguben` DOUBLE NOT NULL, -- 1.总股本(股)
`liutongguben` DOUBLE NOT NULL, -- 7.流通A股(股)
`guojiagu` DOUBLE NOT NULL, -- 2.国家股(股)
`faqirenfarengu` DOUBLE NOT NULL, -- 3.发起人法人股(股)
`farengu` DOUBLE NOT NULL, -- 4.法人股(股)
`bgu` DOUBLE NOT NULL, -- 5.B股(股)
`hgu` DOUBLE NOT NULL, -- 6.H股(股)
`zhigonggu` DOUBLE NOT NULL, -- 8.职工股(股)
`zongzichan` DOUBLE NOT NULL, -- 10.总资产(元)
`liudongzichan` DOUBLE NOT NULL, -- 11.流动资产(元)
`gudingzichan` DOUBLE NOT NULL, -- 12.固定资产(元)
`wuxingzichan` DOUBLE NOT NULL, -- 13.无形资产(元)
`gudongrenshu` DOUBLE NOT NULL, -- 股东人数
`liudongfuzhai` DOUBLE NOT NULL, -- 15.流动负债
`changqifuzhai` DOUBLE NOT NULL, -- 16.长期负债
`zibengongjijin` DOUBLE NOT NULL, -- 17.资本公积金
`jingzichan` DOUBLE NOT NULL, -- 净资产(元)
`zhuyingshouru` DOUBLE NOT NULL, -- 20.主营收入
`zhuyinglirun` DOUBLE NOT NULL, -- 21.主营利润
`yingshouzhangkuan` DOUBLE NOT NULL, -- 应收账款
`yingyelirun` DOUBLE NOT NULL, -- 23.营业利润
`touzishouyu` DOUBLE NOT NULL, -- 投资收益
`jingyingxianjinliu` DOUBLE NOT NULL, -- 经营现金流
`zongxianjinliu` DOUBLE NOT NULL, -- 总现金流
`cunhuo` DOUBLE NOT NULL, -- 存货
`lirunzonghe` DOUBLE NOT NULL, -- 28.利润总额
`shuihoulirun` DOUBLE NOT NULL, -- 29.税后利润
`jinglirun` DOUBLE NOT NULL, -- 30.净利润
`weifenpeilirun` DOUBLE NOT NULL, -- 31.未分配利润
`meigujingzichan` DOUBLE NOT NULL, -- 34.每股净资产
`baoliu2` DOUBLE NOT NULL, PRIMARY KEY (`id`), FOREIGN KEY (`stockid`) REFERENCES `hku_base`.`stock` (`stockid`), INDEX `ix_stkfinance_date` (`updated_date`), INDEX `ix_stkfinance_stock_date` (`stockid`, `updated_date`)
) COLLATE = 'utf8mb4_general_ci' ENGINE = InnoDB;

UPDATE `hku_base`.`version` set `version` = 9;
12 changes: 3 additions & 9 deletions hikyuu/data/mysql_upgrade/0010.sql
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
CREATE TABLE
IF NOT EXISTS `hku_base`.`block` (
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
`category` VARCHAR(100) NOT NULL,
`name` VARCHAR(100) NOT NULL,
`market_code` VARCHAR(30) NOT NULL,
PRIMARY KEY (`id`),
INDEX `ix_block` (`category`, `name`)
) COLLATE = 'utf8_general_ci' ENGINE = InnoDB;
CREATE TABLE IF NOT EXISTS `hku_base`.`block` (
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT, `category` VARCHAR(100) NOT NULL, `name` VARCHAR(100) NOT NULL, `market_code` VARCHAR(30) NOT NULL, PRIMARY KEY (`id`), INDEX `ix_block` (`category`, `name`)
) COLLATE = 'utf8mb4_general_ci' ENGINE = InnoDB;

UPDATE `hku_base`.`version` set `version` = 10;
11 changes: 3 additions & 8 deletions hikyuu/data/mysql_upgrade/0011.sql
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
CREATE TABLE
IF NOT EXISTS `hku_base`.`zh_bond10` (
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
`date` INT UNSIGNED NOT NULL,
`value` INT NOT NULL,
PRIMARY KEY (`id`),
INDEX `ix_date_on_zh_bond10` (`date`)
) COLLATE = 'utf8_general_ci' ENGINE = InnoDB;
CREATE TABLE IF NOT EXISTS `hku_base`.`zh_bond10` (
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT, `date` INT UNSIGNED NOT NULL, `value` INT NOT NULL, PRIMARY KEY (`id`), INDEX `ix_date_on_zh_bond10` (`date`)
) COLLATE = 'utf8mb4_general_ci' ENGINE = InnoDB;

UPDATE `hku_base`.`version` set `version` = 11;
Loading

0 comments on commit 69f9bae

Please sign in to comment.