import datetime


START_DATE = datetime.datetime.strptime('2017-11-30', '%Y-%m-%d')

TARGET = 'isFraud'

CATEGORICAL_FEATURES = [
    'id_31_BROWSER_NAME',
    'device_name',
    'ProductCD',
    'card1',
    'card2',
    'card3',
    'card4',
    'card5',
    'card6',
    'addr1',
    'addr2',
    'P_emaildomain',
    'R_emaildomain',
    'M1',
    'M2',
    'M3',
    'M4',
    'M5',
    'M6',
    'M7',
    'M8',
    'M9',
    # identity
    'DeviceType',
    'DeviceInfo',
    # derived
    'OS_NAME',
    'OS_V_MAJOR',
    'OS_V0',
    'OS_V1',
    'OS_V2',
    'is_foreign',
    'is_holiday',
    #
    'P_emaildomain_1',
    'P_emaildomain_2',
    'P_emaildomain_3',
    'R_emaildomain_1',
    'R_emaildomain_2',
    'R_emaildomain_3',
    #
    'cents_categorical',
    'subcard_categorical',
    'OS_VERSION_FULL',
    'OS_VERSION_MINIMAL',
    'dollars'
] + [f'id_{i}' for i in range(12, 39)]


COLUMNS_TO_REMOVE = [
    'TransactionID',
    'TransactionDT',
    TARGET,
    'TransactionDT_split',
    'TransactionDT_year',
    'TransactionDT_to_datetime',
    'TransactionDT_month'
]


V_GROUPS_BY_NOTNULL = {
    f'{min_i}-{max_i}': [f'V{i}' for i in range(min_i, max_i + 1)]
    for min_i, max_i in [
        (1, 11),
        (12, 34),
        (35, 52),
        (53, 74),
        (75, 94),
        (95, 125),
        (126, 137),
        (138, 166),
        (167, 216),
        (217, 278),
        (279, 305),
        (306, 321),
        (322, 339)
    ]
}


USELESS_FEATURES_ACCORDING_TO_PERMUTATIONS = USELESS_FEATURES_PERMUTATION = [
    'smoothed_encoded_card1_on_subcard_categorical_nunique',
    'smoothed_encoded_card2_card3_on_card1_nunique',
    'smoothed_encoded_addr1_on_card1_nunique',
    'smoothed_encoded_card4_on_card1_nunique',
    'smoothed_encoded_card6_on_card1_nunique',
    'smoothed_encoded_P_emaildomain_on_R_emaildomain_nunique',
    'smoothed_encoded_card2_on_card1_nunique',
    'smoothed_encoded_addr1_on_ProductCD_nunique',
    'smoothed_encoded_R_emaildomain_on_P_emaildomain_nunique',
    'smoothed_encoded_addr1_on_P_emaildomain_nunique',
    'smoothed_encoded_addr1_on_R_emaildomain_nunique',
    'smoothed_encoded_card2_on_R_emaildomain_nunique',
    'smoothed_encoded_card2_on_ProductCD_nunique',
    'smoothed_encoded_subcard_categorical_on_card2_nunique',
    'smoothed_encoded_card1_on_ProductCD_nunique',
    'smoothed_encoded_card1_on_P_emaildomain_nunique',
    'smoothed_encoded_card2_on_P_emaildomain_nunique',
    'smoothed_encoded_subcard_categorical_on_ProductCD_nunique',
    'smoothed_encoded_card1_on_dist1_mean', 'smoothed_encoded_card1_on_card2_nunique',
    'smoothed_encoded_TransactionDT_weekOfMonth_on_TransactionAmt_std',
    'smoothed_encoded_TransactionDT_weekOfMonth_on_TransactionAmt_nanmedian',
    'smoothed_encoded_TransactionDT_weekOfMonth_on_TransactionAmt_mean',
    'smoothed_encoded_TransactionDT_dayOfMonth_on_TransactionAmt_nanmedian',
    'smoothed_encoded_TransactionDT_dayOfMonth_on_TransactionAmt_mean',
    'smoothed_encoded_TransactionDT_dayOfMonth_on_TransactionAmt_std',
    'smoothed_encoded_TransactionDT_hour_on_TransactionAmt_nanmedian',
    'smoothed_encoded_TransactionDT_hour_on_TransactionAmt_mean',
    'smoothed_encoded_TransactionDT_hour_on_TransactionAmt_std',
    'smoothed_encoded_card5_on_TransactionAmt_std',
    'smoothed_encoded_card5_on_TransactionAmt_nanmedian',
    'smoothed_encoded_card3_on_TransactionAmt_nanmedian',
    'smoothed_encoded_card5_on_TransactionAmt_mean',
    'smoothed_encoded_card3_on_TransactionAmt_mean',
    'smoothed_encoded_card3_on_TransactionAmt_std',
    'smoothed_encoded_card2_on_TransactionAmt_std',
    'smoothed_encoded_card2_on_TransactionAmt_nanmedian',
    'smoothed_encoded_card1_on_TransactionAmt_std',
    'smoothed_encoded_card2_on_TransactionAmt_mean',
    'card1_C13_count', 'card1_C13_count_how_typical', 'card1_C14_count_how_typical',
    'smoothed_encoded_card1_on_TransactionAmt_mean',
    "id_01_isnull", "id_02_isnull", "id_03_isnull", "id_04_isnull", "id_05_isnull",
    "id_06_isnull", "id_07_isnull",
    "id_08_isnull", "id_09_isnull", "id_10_isnull", "id_11_isnull", "id_12_isnull",
    "id_13_isnull", "id_14_isnull",
    "id_15_isnull", "id_16_isnull", "id_17_isnull", "id_18_isnull", "id_19_isnull",
    "id_20_isnull", "id_21_isnull",
    "id_22_isnull", "id_23_isnull", "id_24_isnull", "id_25_isnull", "id_26_isnull",
    "id_27_isnull", "id_28_isnull",
    "id_29_isnull", "id_30_isnull", "id_31_isnull", "id_32_isnull", "id_33_isnull",
    "id_34_isnull", "id_35_isnull",
    "id_36_isnull", "id_37_isnull", "id_38_isnull", "DeviceType_isnull",
    "DeviceInfo_isnull", "device_name",
    "1-11_notnull", "12-34_notnull", "35-52_notnull", "53-74_notnull", "75-94_notnull",
    "95-125_notnull",
    "126-137_notnull", "138-166_notnull", "167-216_notnull", "217-278_notnull",
    "279-305_notnull",
    "306-321_notnull", "322-339_notnull", "prev_1_card1_ProductCD_TransactionAmt",
    "next_1_card1_ProductCD_TransactionAmt", "card1_count", "card2_count", "card4_count",
    "card5_count",
    "card6_count", "addr1_count", "addr2_count", "card1_TransactionDT_hour_count",
    "card1_TransactionDT_hour_count_how_typical", "TransactionDT_dayOfMonth_count",
    "TransactionDT_weekOfMonth_count", "DeviceInfo_count", "device_name_count",
    "R_emaildomain_count",
    "card1_addr1_count", "card3_addr1_count", "card3_addr1_count_how_typical",
    "card4_addr1_count",
    "card6_addr1_count_how_typical", "card1_P_emaildomain_count", "card1_R_emaildomain_count",
    "card1_is_foreign_count", "card1_is_foreign_count_how_typical", "card1_ProductCD_count",
    "card1_ProductCD_count_how_typical", "card1_ProductCD_addr1_count",
    "card1_ProductCD_addr1_count_how_typical", "ProductCD_addr1_count",
    "card1_subcard_categorical_count_how_typical", "subcard_categorical_C1_count_how_typical",
    "subcard_categorical_C2_count_how_typical", "subcard_categorical_C3_count",
    "subcard_categorical_C3_count_how_typical", "subcard_categorical_C4_count",
    "subcard_categorical_C4_count_how_typical", "subcard_categorical_C7_count",
    "subcard_categorical_C7_count_how_typical", "subcard_categorical_C8_count",
    "subcard_categorical_C8_count_how_typical", "subcard_categorical_C9_count_how_typical",
    "subcard_categorical_C10_count", "subcard_categorical_C10_count_how_typical",
    "subcard_categorical_C12_count", "subcard_categorical_C12_count_how_typical",
    "subcard_categorical_C13_count_how_typical", "subcard_categorical_C14_count_how_typical",
    "card1_C2_count", "card1_C3_count", "card1_C3_count_how_typical", "card1_C4_count",
    "card1_C4_count_how_typical", "card1_C5_count", "card1_C6_count", "card1_C7_count",
    "card1_C7_count_how_typical", "card1_C8_count", "card1_C8_count_how_typical",
    "card1_C9_count", "card1_C9_count_how_typical", "card1_C10_count", "card1_C10_count_how_typical",
    "card1_C12_count",
    'addr1_isnull', 'addr2_isnull', 'dist1_isnull', 'dist2_isnull', 'D1_isnull',
    'D2_isnull', 'D3_isnull',
    'is_foreign', 'OS_NAME', 'OS_V0', 'OS_V1', 'OS_V2', 'OS_V_COMBINED',
    'OS_V_MAJOR', 'OS_VERSION_FULL',
    'time_from_prev_transaction_by_card1_subcard_categorical_ratio_to_median',
    'OS_VERSION_MINIMAL',
    'TransactionAmt_count_within_7d', 'P_emaildomain_3', 'R_emaildomain_2',
    'R_emaildomain_3', 'R=P', 'R1=P1',
    'TransactionAmt_sum_within_7d', 'D5_isnull', 'D6_isnull', 'D7_isnull', 'D8_isnull',
    'D9_isnull', 'D10_isnull',
    'TransactionAmt_mean_within_7d', 'D11_isnull', 'D12_isnull', 'D13_isnull',
    'D14_isnull', 'D15_isnull',
    'TransactionAmt_std_within_7d', 'M1_isnull', 'M4_isnull', 'M6_isnull',
    'M7_isnull'
    'TransactionAmt_count_within_1min',
    'TransactionAmt_std_within_1min',
    'TransactionAmt_unique_within_1min',
    'TransactionAmt_count_within_10min',
    'TransactionAmt_std_within_10min',
    'TransactionAmt_unique_within_10min',
    'TransactionAmt_unique_within_7d',
    'time_to_next_transaction_by_card1_subcard_categorical_ratio_to_mean',
    'time_to_next_transaction_by_card1_subcard_categorical_ratio_to_median',
    'time_from_prev_transaction_by_card1_subcard_categorical_ratio_to_mean',
    'time_to_next_transaction_by_card1_ratio_to_mean',
    'time_to_next_transaction_by_card1_ratio_to_median',
    'card1_mean_time_between_transactions', 'card1_median_time_between_transactions',
    'is_holiday', 'time_from_prev_transaction_by_card1_ratio_to_mean',
    'TransactionDT_hour', 'time_from_prev_transaction_by_card1_ratio_to_median',
    'DeviceType', 'M1', 'M2', 'M7', 'M8', 'M9', 'V1', 'V10', 'V100', 'V101',
    'V104', 'V105', 'V106', 'V107',
    'V108', 'V109', 'V11', 'V110', 'V111', 'V112', 'V113', 'V114', 'V115', 'V116',
    'V117', 'V118', 'V119',
    'V12', 'V120', 'V121', 'V122', 'V123', 'V124', 'V125', 'V126', 'V126_diff1',
    'V127', 'V127_diff1', 'V128_diff1',
    'V129_diff1', 'V13', 'V130', 'V130_diff1', 'V131_diff1', 'V132', 'V132_diff1',
    'V131_diff1', 'V134', 'V134_diff1',
    'V135', 'V135_diff1', 'V136', 'V136_diff1', 'V137', 'V137_diff1', 'V138', 'V139',
    'V14', 'V140', 'V141', 'V142',
    'V143', 'V144', 'V145', 'V146', 'V147', 'V148', 'V149', 'V15', 'V150', 'V151',
    'V153', 'V154', 'V155', 'V156',
    'V157', 'V159', 'V16', 'V160', 'V161', 'V162', 'V163', 'V164', 'V166', 'V167',
    'V168', 'V169', 'V17', 'V170',
    'V171', 'V173', 'V174', 'V175', 'V176', 'V177', 'V178', 'V179', 'V18', 'V180',
    'V181', 'V182', 'V183', 'V184',
    'V185', 'V186', 'V188', 'V189', 'V19', 'V190', 'V191', 'V192', 'V193', 'V194',
    'V195', 'V196', 'V197', 'V198',
    'V199', 'V2', 'V20', 'V200', 'V201', 'V202', 'V203', 'V204', 'V205', 'V206',
    'V207', 'V208', 'V209', 'V21',
    'V210', 'V211', 'V212', 'V213', 'V214', 'V215', 'V216', 'V217', 'V218', 'V219',
    'V22', 'V220', 'V221', 'V222',
    'V223', 'V224', 'V226', 'V227', 'V228', 'V229', 'V23', 'V230', 'V231', 'V232',
    'V233', 'V234', 'V235', 'V236',
    'V237', 'V238', 'V239', 'V24', 'V240', 'V241', 'V242', 'V243', 'V244', 'V246',
    'V247', 'V248', 'V249', 'V25',
    'V250', 'V251', 'V252', 'V253', 'V254', 'V255', 'V256', 'V257', 'V259', 'V26',
    'V260', 'V261', 'V262', 'V263',
    'V264', 'V265', 'V266', 'V267', 'V268', 'V269', 'V27', 'V270', 'V271', 'V272',
    'V273', 'V274', 'V275', 'V276',
    'V277', 'V278', 'V279', 'V28', 'V280', 'V282', 'V284', 'V285', 'V286', 'V287',
    'V288', 'V289', 'V29', 'V290',
    'V291', 'V292', 'V293', 'V294', 'V295', 'V296', 'V297', 'V298', 'V299', 'V3',
    'V30', 'V300', 'V301', 'V302',
    'V303', 'V304', 'V305', 'V306', 'V307', 'V309', 'V31', 'V311', 'V314', 'V316',
    'V318', 'V319', 'V32', 'V320',
    'V321', 'V322', 'V323', 'V324', 'V325', 'V326', 'V327', 'V328', 'V329', 'V33',
    'V330', 'V331', 'V332', 'V333',
    'V334', 'V335', 'V336', 'V337', 'V338', 'V339', 'V35', 'V36', 'V37', 'V38',
    'V39', 'V4', 'V40', 'V41', 'V42',
    'V42', 'V43', 'V44', 'V45', 'V46', 'V47', 'V5', 'V50', 'V51', 'V52', 'V53',
    'V55', 'V56', 'V57', 'V58', 'V59',
    'V6', 'V60', 'V61', 'V63', 'V64', 'V65', 'V66', 'V68', 'V7', 'V71', 'V72',
    'V73', 'V74', 'V75', 'V76', 'V78',
    'V79', 'V8', 'V80', 'V81', 'V82', 'V84', 'V85', 'V86', 'V88', 'V89', 'V9',
    'V90', 'V92', 'V93', 'V94', 'V95',
    'V96', 'V97', 'V99', 'addr2', 'card3', 'card4', 'card6', 'dist1', 'dist2',
    'id_03', 'id_04', 'id_05', 'id_07',
    'id_08', 'id_09', 'id_10', 'id_11', 'id_12', 'id_14', 'id_15', 'id_16', 'id_17',
    'id_18', 'id_21', 'id_22',
    'id_23', 'id_24', 'id_25', 'id_26', 'id_27', 'id_28', 'id_29', 'id_31', 'id_32',
    'id_34', 'id_35', 'id_36',
    'id_37', 'id_38', 'time_from_prev_transaction_by_card1',
    'time_from_prev_transaction_by_card1_ProductCD',
    'time_from_prev_transaction_by_card1_ProductCD_addr1',
    'time_to_next_transaction_by_card1',
    'time_to_next_transaction_by_card1_ProductCD', 'TransactionDT_weekOfMonth'
]
