# 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)
# 
# def datetime_2_yyyyMMddHHmm(dt):
#     """
#     将时间转换成float类型
#     :param dt:
#     :return:
#     """
#     t = dt.timetuple()
#     return float((t.tm_year * 10000.0 + t.tm_mon * 100 + t.tm_mday) * 10000.0) + t.tm_hour * 100 + t.tm_min
# 
# def tic():
#     """
#     对应MATLAB中的tic
#     :return:
#     """
#     globals()['tt'] = time.clock()
# 
# def toc():
#     """
#     对应MATLAB中的toc
#     :return:
#     """
#     t = time.clock() - globals()['tt']
#     print('\nElapsed time: %.8f seconds\n' % t)
#     return t
# 
# Path: kquant_data/xio/csv.py
# def read_data_dataframe(path, sep=','):
#     """
#     读取季报的公告日
#     注意：有些股票多个季度一起发，一般是公司出问题了，特别是600878，四个报告同一天发布
#     年报与一季报很有可能一起发
#     :param path:
#     :param sep:
#     :return:
#     """
#     try:
#         df = pd.read_csv(path, index_col=0, parse_dates=True, encoding='utf-8-sig', sep=sep)
#     except (FileNotFoundError, OSError):
#         return None
# 
#     return df


import os
import datetime
import numpy as np
import pandas as pd
import multiprocessing
from functools import partial
from ..utils.xdatetime import yyyyMMddHHmm_2_datetime, datetime_2_yyyyMMddHHmm, tic, toc
from ..xio.csv import read_data_dataframe
    toc()



def dataframe_align_copy(df1, df2):
    """
    两个DataFrame，将其中的数据复制到另一个
    :param df1:
    :param df2:
    :return:
    """
    index = df1.index.intersection(df2.index)
    columns = df1.columns.intersection(df2.columns)

    # 由于两边的数据不配套，所以只能复制重合部分
    df1.ix[index, columns] = df2.ix[index, columns]

    return df1


def read_fill_from_file(path, date, field, df):
    """
    将一个文件中的内容合并到一个df中
    :param path:
    :param date:
    :param field:
    :param df:
    :return:
    """
    _path = path % date

# 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)
# 
# def datetime_2_yyyyMMddHHmm(dt):
#     """
#     将时间转换成float类型
#     :param dt:
#     :return:
#     """
#     t = dt.timetuple()
#     return float((t.tm_year * 10000.0 + t.tm_mon * 100 + t.tm_mday) * 10000.0) + t.tm_hour * 100 + t.tm_min
# 
# def tic():
#     """
#     对应MATLAB中的tic
#     :return:
#     """
#     globals()['tt'] = time.clock()
# 
# def toc():
#     """
#     对应MATLAB中的toc
#     :return:
#     """
#     t = time.clock() - globals()['tt']
#     print('\nElapsed time: %.8f seconds\n' % t)
#     return t
# 
# Path: kquant_data/xio/csv.py
# def read_data_dataframe(path, sep=','):
#     """
#     读取季报的公告日
#     注意：有些股票多个季度一起发，一般是公司出问题了，特别是600878，四个报告同一天发布
#     年报与一季报很有可能一起发
#     :param path:
#     :param sep:
#     :return:
#     """
#     try:
#         df = pd.read_csv(path, index_col=0, parse_dates=True, encoding='utf-8-sig', sep=sep)
#     except (FileNotFoundError, OSError):
#         return None
# 
#     return df


# Path: kquant_data/processing/utils.py
import os
import datetime
import numpy as np
import pandas as pd
import multiprocessing
from functools import partial
from ..utils.xdatetime import yyyyMMddHHmm_2_datetime, datetime_2_yyyyMMddHHmm, tic, toc
from ..xio.csv import read_data_dataframe

    toc()



def dataframe_align_copy(df1, df2):
    """
    两个DataFrame，将其中的数据复制到另一个
    :param df1:
    :param df2:
    :return:
    """
    index = df1.index.intersection(df2.index)
    columns = df1.columns.intersection(df2.columns)

    # 由于两边的数据不配套，所以只能复制重合部分
    df1.ix[index, columns] = df2.ix[index, columns]

    return df1


def read_fill_from_file(path, date, field, df):
    """
    将一个文件中的内容合并到一个df中
    :param path:
    :param date:
    :param field:
    :param df:
    :return:
    """
    _path = path % date

    x = read_data_dataframe(_path)