# Path: alphaware/enums.py
# class FreqType(StrEnum):
#     EOD = 'D'
#     EOW = 'W'
#     EOM = 'M'
#     EOQ = 'Q'
#     EOSY = 'S'
#     EOY = 'Y'
# 
# class OutputDataFormat(IntEnum):
#     MULTI_INDEX_DF = 0
#     PITVOT_TABLE_DF = 1
# 
# Path: alphaware/utils/input_validation.py
# @expect_types(date=(str, datetime))
# def ensure_datetime(date, date_format='%Y-%m-%d'):
#     """
#     :param date: str, datetime, 日期
#     :param date_format: str, 时间格式
#     :return: datetime
#     """
#     if isinstance(date, datetime):
#         return date
#     else:
#         return datetime.strptime(date, date_format)
# 
# @expect_types(data=(pd.DataFrame, pd.Series), data_format=OutputDataFormat)
# def ensure_pd_index_names(data, data_format, valid_index):
#     if data_format == OutputDataFormat.MULTI_INDEX_DF:
#         data.index.names = valid_index.full_index
#     else:
#         data.index.name = valid_index.date_index
#     return data
# 
# Path: alphaware/utils/pandas_utils.py
# @expect_types(data=(pd.Series, pd.DataFrame))
# def convert_df_format(data, target_format=OutputDataFormat.MULTI_INDEX_DF, col_name='factor',
#                       multi_index=INDEX_FACTOR):
#     if target_format == OutputDataFormat.MULTI_INDEX_DF:
#         tmp = data.stack()
#         data_ = pd.DataFrame(tmp)
#         data_.index.names = multi_index.full_index
#         data_.columns = [col_name]
#     else:
#         tmp = data.unstack()
#         index = tmp.index
#         columns = tmp.columns.get_level_values(multi_index.sec_index).tolist()
#         data_ = pd.DataFrame(tmp.values, index=index, columns=columns)
# 
#     return data_
# 
# Path: alphaware/const.py
# INDEX_FACTOR = namedtuple('INDEX_FACTOR', ['date_index', 'sec_index', 'full_index', 'col_score'])
# 
# INDEX_INDUSTRY_WEIGHT = namedtuple('INDEX_INDUSTRY_WEIGHT',
#                                    ['date_index', 'industry_index', 'full_index', 'col_name'])


from collections import defaultdict
from toolz.dicttoolz import merge
from xutils import py_assert
from alphaware.enums import (FreqType,
                     OutputDataFormat)
from alphaware.utils import (convert_df_format,
                     ensure_datetime,
                     ensure_pd_index_names)
from alphaware.const import (INDEX_FACTOR,
                     INDEX_INDUSTRY_WEIGHT)
import numpy as np
# -*- coding: utf-8 -*-


_REQUIRED_BENCHMARK_PROPERTY = {'data_format': OutputDataFormat.MULTI_INDEX_DF,
                                'freq': FreqType.EOM}


class Benchmark(object):
    def __init__(self, name, hist_return=None, industry_weight=None, property_dict=defaultdict(str), **kwargs):
        self.name = name
        self.property = merge(_REQUIRED_BENCHMARK_PROPERTY, property_dict)

# Path: alphaware/enums.py
# class FreqType(StrEnum):
#     EOD = 'D'
#     EOW = 'W'
#     EOM = 'M'
#     EOQ = 'Q'
#     EOSY = 'S'
#     EOY = 'Y'
# 
# class OutputDataFormat(IntEnum):
#     MULTI_INDEX_DF = 0
#     PITVOT_TABLE_DF = 1
# 
# Path: alphaware/utils/input_validation.py
# @expect_types(date=(str, datetime))
# def ensure_datetime(date, date_format='%Y-%m-%d'):
#     """
#     :param date: str, datetime, 日期
#     :param date_format: str, 时间格式
#     :return: datetime
#     """
#     if isinstance(date, datetime):
#         return date
#     else:
#         return datetime.strptime(date, date_format)
# 
# @expect_types(data=(pd.DataFrame, pd.Series), data_format=OutputDataFormat)
# def ensure_pd_index_names(data, data_format, valid_index):
#     if data_format == OutputDataFormat.MULTI_INDEX_DF:
#         data.index.names = valid_index.full_index
#     else:
#         data.index.name = valid_index.date_index
#     return data
# 
# Path: alphaware/utils/pandas_utils.py
# @expect_types(data=(pd.Series, pd.DataFrame))
# def convert_df_format(data, target_format=OutputDataFormat.MULTI_INDEX_DF, col_name='factor',
#                       multi_index=INDEX_FACTOR):
#     if target_format == OutputDataFormat.MULTI_INDEX_DF:
#         tmp = data.stack()
#         data_ = pd.DataFrame(tmp)
#         data_.index.names = multi_index.full_index
#         data_.columns = [col_name]
#     else:
#         tmp = data.unstack()
#         index = tmp.index
#         columns = tmp.columns.get_level_values(multi_index.sec_index).tolist()
#         data_ = pd.DataFrame(tmp.values, index=index, columns=columns)
# 
#     return data_
# 
# Path: alphaware/const.py
# INDEX_FACTOR = namedtuple('INDEX_FACTOR', ['date_index', 'sec_index', 'full_index', 'col_score'])
# 
# INDEX_INDUSTRY_WEIGHT = namedtuple('INDEX_INDUSTRY_WEIGHT',
#                                    ['date_index', 'industry_index', 'full_index', 'col_name'])


# Path: alphaware/preprocess/benchmark.py
from collections import defaultdict
from toolz.dicttoolz import merge
from xutils import py_assert
from alphaware.enums import (FreqType,
                     OutputDataFormat)
from alphaware.utils import (convert_df_format,
                     ensure_datetime,
                     ensure_pd_index_names)
from alphaware.const import (INDEX_FACTOR,
                     INDEX_INDUSTRY_WEIGHT)
import numpy as np

# -*- coding: utf-8 -*-


_REQUIRED_BENCHMARK_PROPERTY = {'data_format': OutputDataFormat.MULTI_INDEX_DF,
                                'freq': FreqType.EOM}


class Benchmark(object):
    def __init__(self, name, hist_return=None, industry_weight=None, property_dict=defaultdict(str), **kwargs):
        self.name = name
        self.property = merge(_REQUIRED_BENCHMARK_PROPERTY, property_dict)

        self.production_data_format = kwargs.get('production_data_format', OutputDataFormat.MULTI_INDEX_DF)