# Path: kquant_data/xio/h5.py
# def write_dataframe_set_struct_keep_head(path, data, dtype, dateset_name):
#     """
#     保存DataFrame数据
#     保留表头
#     可以用来存K线，除权除息等信息
#     :param path:
#     :param data:
#     :param dtype:
#     :param dateset_name:
#     :return:
#     """
#     f = h5py.File(path, 'w')
# 
#     r = data.to_records(index=False)
#     d = np.array(r, dtype=dtype)
# 
#     f.create_dataset(dateset_name, data=d, compression="gzip", compression_opts=6)
#     f.close()
#     return
# 
# Path: kquant_data/utils/xdatetime.py
# def yyyyMMddHHmm_2_datetime(dt):
#     """
#     输入一个长整型yyyyMMddhmm，返回对应的时间
#     :param dt:
#     :return:
#     """
#     dt = int(dt)  # FIXME：在python2下会有问题吗？
#     (yyyyMMdd, hh) = divmod(dt, 10000)
#     (yyyy, MMdd) = divmod(yyyyMMdd, 10000)
#     (MM, dd) = divmod(MMdd, 100)
#     (hh, mm) = divmod(hh, 100)
# 
#     return datetime(yyyy, MM, dd, hh, mm)


import os
import numpy as np
import pandas as pd
from ..xio.h5 import write_dataframe_set_struct_keep_head
from ..utils.xdatetime import yyyyMMddHHmm_2_datetime
# -*- coding: utf-8 -*-
"""
处理通达信数据相关的操作

http://www.cnblogs.com/zeroone/archive/2013/07/10/3181251.html
文件路径
-------
D:\new_hbzq\vipdoc\sh\lday
D:\new_hbzq\vipdoc\sh\fzline
D:\new_hbzq\vipdoc\sh\minline

"""



# 保存成h5格式时的类型
tdx_h5_type = np.dtype([
    ('DateTime', np.uint64),
    ('Open', np.float32),
    ('High', np.float32),
    ('Low', np.float32),
    ('Close', np.float32),
    ('Amount', np.float32),
    ('Volume', np.uint32),
    ('backward_factor', np.float32),
    ('forward_factor', np.float32),
])


def bars_to_h5(input_path, data):  # 保存日线

# Path: kquant_data/xio/h5.py
# def write_dataframe_set_struct_keep_head(path, data, dtype, dateset_name):
#     """
#     保存DataFrame数据
#     保留表头
#     可以用来存K线，除权除息等信息
#     :param path:
#     :param data:
#     :param dtype:
#     :param dateset_name:
#     :return:
#     """
#     f = h5py.File(path, 'w')
# 
#     r = data.to_records(index=False)
#     d = np.array(r, dtype=dtype)
# 
#     f.create_dataset(dateset_name, data=d, compression="gzip", compression_opts=6)
#     f.close()
#     return
# 
# Path: kquant_data/utils/xdatetime.py
# def yyyyMMddHHmm_2_datetime(dt):
#     """
#     输入一个长整型yyyyMMddhmm，返回对应的时间
#     :param dt:
#     :return:
#     """
#     dt = int(dt)  # FIXME：在python2下会有问题吗？
#     (yyyyMMdd, hh) = divmod(dt, 10000)
#     (yyyy, MMdd) = divmod(yyyyMMdd, 10000)
#     (MM, dd) = divmod(MMdd, 100)
#     (hh, mm) = divmod(hh, 100)
# 
#     return datetime(yyyy, MM, dd, hh, mm)


# Path: kquant_data/stock/tdx.py
import os
import numpy as np
import pandas as pd
from ..xio.h5 import write_dataframe_set_struct_keep_head
from ..utils.xdatetime import yyyyMMddHHmm_2_datetime

# -*- coding: utf-8 -*-
"""
处理通达信数据相关的操作

http://www.cnblogs.com/zeroone/archive/2013/07/10/3181251.html
文件路径
-------
D:\new_hbzq\vipdoc\sh\lday
D:\new_hbzq\vipdoc\sh\fzline
D:\new_hbzq\vipdoc\sh\minline

"""



# 保存成h5格式时的类型
tdx_h5_type = np.dtype([
    ('DateTime', np.uint64),
    ('Open', np.float32),
    ('High', np.float32),
    ('Low', np.float32),
    ('Close', np.float32),
    ('Amount', np.float32),
    ('Volume', np.uint32),
    ('backward_factor', np.float32),
    ('forward_factor', np.float32),
])


def bars_to_h5(input_path, data):  # 保存日线

    write_dataframe_set_struct_keep_head(input_path, data, tdx_h5_type, 'BarData')