# Path: kquant_data/processing/merge.py
# def merge_sector(rule, sector_name, dataset_name):
#     """
#     合并一级文件夹
#     :param rule:
#     :param sector_name:
#     :param dataset_name:
#     :return:
#     """
#     path = os.path.join(__CONFIG_H5_STK_DIR__, rule, 'Symbol.csv')
#     symbols = all_instruments(path)
# 
#     path = os.path.join(__CONFIG_H5_STK_DIR__, rule, 'DateTime.csv')
#     DateTime = get_datetime(path)
# 
#     tic()
#     path = os.path.join(__CONFIG_H5_STK_SECTOR_DIR__, sector_name)
#     df = load_sector(path, 1)
#     print("数据加载完成")
#     toc()
# 
#     df = expand_dataframe_according_to(df, DateTime.index, symbols['wind_code'])
#     # 有些股票从来没有被ST过，比如浦发银行，或一些新股
#     df.fillna(0, inplace=True)
# 
#     print("数据加载完成")
#     toc()
# 
#     path = os.path.join(__CONFIG_H5_STK_DIR__, rule, "%s.h5" % dataset_name)
#     write_dataframe_set_dtype_remove_head(path, df, np.int8, dataset_name)
# 
#     toc()
# 
# def merge_sectors(rule, sector_name, dataset_name):
#     """
#     合并二级文件夹
#     :param rule:
#     :param sector_name:
#     :param dataset_name:
#     :return:
#     """
#     path = os.path.join(__CONFIG_H5_STK_DIR__, rule, 'Symbol.csv')
#     symbols = all_instruments(path)
# 
#     path = os.path.join(__CONFIG_H5_STK_DIR__, rule, 'DateTime.csv')
#     DateTime = get_datetime(path)
# 
#     tic()
#     path = os.path.join(__CONFIG_H5_STK_SECTOR_DIR__, sector_name)
#     df = load_sectors(path)
#     print("数据加载完成")
#     toc()
# 
#     df = expand_dataframe_according_to(df, DateTime.index, symbols['wind_code'])
#     # df.to_csv(r"D:\1.csv")
#     # 有些股票从来没有被ST过，比如浦发银行，或一些新股
#     df.fillna(0, inplace=True)
# 
#     print("数据加载完成")
#     toc()
# 
#     path = os.path.join(__CONFIG_H5_STK_DIR__, rule, "%s.h5" % dataset_name)
#     write_dataframe_set_dtype_remove_head(path, df, np.int16, dataset_name)
# 
#     toc()


import sys
from kquant_data.processing.merge import merge_sector, merge_sectors
﻿#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
指定数据目录，生成对应的合约行业数据
"""

# 解决Python 3.6的pandas不支持中文路径的问题
print(sys.getfilesystemencoding())  # 查看修改前的
try:
    sys._enablelegacywindowsfsencoding()  # 修改
    print(sys.getfilesystemencoding())  # 查看修改后的
except:
    pass

if __name__ == '__main__':
    rule = '1day'
    if False:
        sector_name = '风险警示股票'

# Path: kquant_data/processing/merge.py
# def merge_sector(rule, sector_name, dataset_name):
#     """
#     合并一级文件夹
#     :param rule:
#     :param sector_name:
#     :param dataset_name:
#     :return:
#     """
#     path = os.path.join(__CONFIG_H5_STK_DIR__, rule, 'Symbol.csv')
#     symbols = all_instruments(path)
# 
#     path = os.path.join(__CONFIG_H5_STK_DIR__, rule, 'DateTime.csv')
#     DateTime = get_datetime(path)
# 
#     tic()
#     path = os.path.join(__CONFIG_H5_STK_SECTOR_DIR__, sector_name)
#     df = load_sector(path, 1)
#     print("数据加载完成")
#     toc()
# 
#     df = expand_dataframe_according_to(df, DateTime.index, symbols['wind_code'])
#     # 有些股票从来没有被ST过，比如浦发银行，或一些新股
#     df.fillna(0, inplace=True)
# 
#     print("数据加载完成")
#     toc()
# 
#     path = os.path.join(__CONFIG_H5_STK_DIR__, rule, "%s.h5" % dataset_name)
#     write_dataframe_set_dtype_remove_head(path, df, np.int8, dataset_name)
# 
#     toc()
# 
# def merge_sectors(rule, sector_name, dataset_name):
#     """
#     合并二级文件夹
#     :param rule:
#     :param sector_name:
#     :param dataset_name:
#     :return:
#     """
#     path = os.path.join(__CONFIG_H5_STK_DIR__, rule, 'Symbol.csv')
#     symbols = all_instruments(path)
# 
#     path = os.path.join(__CONFIG_H5_STK_DIR__, rule, 'DateTime.csv')
#     DateTime = get_datetime(path)
# 
#     tic()
#     path = os.path.join(__CONFIG_H5_STK_SECTOR_DIR__, sector_name)
#     df = load_sectors(path)
#     print("数据加载完成")
#     toc()
# 
#     df = expand_dataframe_according_to(df, DateTime.index, symbols['wind_code'])
#     # df.to_csv(r"D:\1.csv")
#     # 有些股票从来没有被ST过，比如浦发银行，或一些新股
#     df.fillna(0, inplace=True)
# 
#     print("数据加载完成")
#     toc()
# 
#     path = os.path.join(__CONFIG_H5_STK_DIR__, rule, "%s.h5" % dataset_name)
#     write_dataframe_set_dtype_remove_head(path, df, np.int16, dataset_name)
# 
#     toc()


# Path: demo_stock/A_1day/B05_merge_sector.py
import sys
from kquant_data.processing.merge import merge_sector, merge_sectors

﻿#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
指定数据目录，生成对应的合约行业数据
"""

# 解决Python 3.6的pandas不支持中文路径的问题
print(sys.getfilesystemencoding())  # 查看修改前的
try:
    sys._enablelegacywindowsfsencoding()  # 修改
    print(sys.getfilesystemencoding())  # 查看修改后的
except:
    pass

if __name__ == '__main__':
    rule = '1day'
    if False:
        sector_name = '风险警示股票'

        merge_sector(rule, sector_name, 'ST')