# -*- coding: utf-8 -*-
# @Time    : 2020/10/27 16:49
# @Author  : Hou Jue
# @Email   : 382062104@qq.com
# @File    : all_combination_3.py
# @Software: PyCharm
# -*- coding: utf-8 -*-
# import numpy as np
import numpy as np
from sklearn.cluster import KMeans
# import sklearn.preprocessing.MinMaxScaler
# import sklearn.preprocessing.StandardScaler
# import sklearn
from sklearn import preprocessing
# -*- coding: utf-8 -*-

def sub_sets(a,b,idx):
    # if(idx==len(a)):
    # if(idx==a.shape[0]):
    if(idx==a.shape[1]):
        # print(b)
        k_means(b)
        # pass

    else:
        c=b[:]
        b.append(a[:,idx])
        # print(b)
        sub_sets(a,b,idx+1)
        sub_sets(a,c,idx+1)


def k_means(b):
    b=np.array(b)
    # print(b)
    kmeans = KMeans(
        n_clusters=2,  # 簇的个数，默认值为8
        random_state=0
    ).fit(b.T)

    # print(kmeans.labels_)
    label = kmeans.labels_
    print(label)
    label = list(label)

    acc_0 = accuracy_0(label)
    acc_1 = accuracy_1(label)
    print('accuracy_0: {}'.format(acc_0))
    print('accuracy_1: {}'.format(acc_1))

def accuracy_0(label):
    n=0
    m=0
    label_0=list([0,0,0,0,0,1,0,1,1,0,1,0,0,0,0,1,1,0,0,0,0,0,0,0,0])
    for i in label:
        if i == label_0[n] :
            m = m + 1
        n=n+1
    acc_0=m/25
    # count+=1
    return acc_0

def accuracy_1(label):
    m=0
    n=0
    label_1=list([0,1,1,0,0,2,1,2,2,0,2,1,0,0,0,2,2,1,1,0,0,1,0,1,1])
    for i in label:
        if i == label_1[n]:
            m = m + 1
        n=n+1
    acc_1=m/25
    return acc_1

if __name__ == '__main__':
    '''BEV特征提取'''
    BEV_daily_distance_mean = [41.892324610306204, 110.16444820582977, 69.78551132095026, 145.66666666666666, 183.41211672942447, 49.904594049128626, 83.90899489850094, 30.512052067938093, 265.8729281767956, 58.30399373472203, 50.35589053832971, 156.41914294886433, 191.0923586553264, 231.0810810810811, 204.11354156702447, 211.70833333333334, 35.59711914970184, 104.04147499949894, 93.87905989150414, 276.85795454545456, 129.9693611510114, 158.3257142857143, 202.70343287512443, 94.6995941675841, 174.05210859636338] # 统计日均里程
    BEV_daily_distance_std =[28.83411807975291, 64.02990260168988, 54.372530897435766, 61.74442702791765, 100.91271585025808, 43.949194118403355, 66.85381282422154, 36.049554283960816, 95.0150926466543, 35.17078352059293, 44.66150530793822, 85.65792445260492, 101.45190120220495, 114.66976754149479, 112.37106035632547, 108.79088471568849, 15.042547184677368, 64.75660357722944, 71.87932993607896, 81.79872223606233, 79.2966845710318, 49.52266057275277, 103.045187036343, 41.28763187024484, 60.7071978139812]# 统计日里程标准差
    BEV_night_distance_mean =[3.0640569395018247, 4.505195057862004, 19.928410360355485, 35.51428571428571, 33.43181818181818, 16.333333333333332, 11.791548244211477, 3.7656010927041113, 17.90909090909091, 5.438198336099288, 11.620263000875104, 12.217580388922944, 8.583231700793679, 10.031746031746032, 46.1234675262453, 58.30952380952381, 1.6947919997223835, 14.732578884072051, 21.352004820352178, 30.384615384615383, 4.9728586436410245, 0, 23.616811277773778, 14.879481591551277, 8.885749914720305] ##统计夜间日均里程
    BEV_night_distance_percentage = [0.0017414583061083587, 0.031023930473837613, 0.1392137116541659, 0.09980328395359107, 0.09491348954524038, 0.006963642067789184, 0.07733745872596799, 0.03232260011280283, 0.012281029860981235, 0.04097549677399499, 0.05811802203256251, 0.06284548623149884, 0.01402023109058906, 0.01847953216374269, 0.14517603834902942, 0.1377119239744707, 0.004255675495750087, 0.02494142717256579, 0.11523708398317135, 0.0972766638619246, 0.018478698860871248, 0.0, 0.07390011011654632, 0.025578158075691523, 0.03585129170776987]  # 统计夜间里程占比 0：00-5：00
    BEV_am_peak_percentage = [0.26026120613496495, 0.10491108023138275, 0.08815592227657747, 0.008832149022441688, 0.0714593403612194, 0.2835862463541603, 0.10287578231042382, 0.09098105593694635, 0.11283585811358395, 0.11761416147279986, 0.13419653817686483, 0.003110088320324839, 0.10027533202175248, 0.01888888888888889, 0.08624060467481451, 0.08257654567436107, 0.1807942424463874, 0.13542247171922903, 0.09654363898837459, 0.07031009501918854, 0.2940546872951314, 0.26928213086945535, 0.05516856317744923, 0.2938164508245289, 0.05219281591117221] # 统计早高峰里程占比  7：00-9：00
    BEV_pm_peak_percentage =[0.17111486777761553, 0.0871556601508764, 0.10389316331425018, 0.13523224537315814, 0.08650383268606333, 0.10496995238364104, 0.09925677862225159, 0.08509951545636331, 0.10882530183072543, 0.08955997043955286, 0.13612754949906225, 0.15165867312699144, 0.11158844640369378, 0.1317543859649123, 0.10526392591699166, 0.03106812494728259, 0.22879941273671522, 0.10469388638970142, 0.08667728381186073, 0.11055472325404807, 0.14439584479897136, 0.1575053235644422, 0.10450899505653219, 0.10539035658456712, 0.05853296943655156] # 统计晚高峰里程占比  17：00-19：00
    BEV_weekends_distance_percentage =[0.28296578606637257, 0.2159349058205562, 0.3706304325561185, 0.2694206913163917, 0.26595397962756245, 0.13387246587464105, 0.3803509054812101, 0.35965257983455895, 0.3161274234773393, 0.21765114306299427, 0.3186434696821426, 0.220826469034075, 0.2737066333367647, 0.20973684210526317, 0.298943114100325, 0.2168864396772289, 0.23273354367765073, 0.2640099710354632, 0.362599404989539, 0.31563609497814354, 0.2267653826484442, 0.3021619085429675, 0.2951859401120313, 0.18874765404112018, 0.29996071180877976] # 统计周末里程占比
    BEV_charging_rate_mean =[0.0018824654165695534, 0.003473735482599176, 0.005975798020707875, 0.01659672392098708, 0.012747096647658523, 0.0038202115847293786, 0.0024721833976432484, 0.0032150060041909864, 0.0231713889150768, 0.0020603801740650533, 0.0019888564627050264, 0.005944752727849893, 0.014142039901028964, 0.018796867419495007, 0.013323836776438884, 0.01635953227368874, 0.0037077369844998164, 0.0034400986901577304, 0.0028078304077617383, 0.014177296999702528, 0.0017918280392757537, 0.013138218101316107, 0.012934083184318872, 0.0034539915215831387, 0.0054876546657298625]  #  # 统计充电速率


    BEV_daily_distance_mean=preprocessing.scale(BEV_daily_distance_mean)
    BEV_daily_distance_std=preprocessing.scale(BEV_daily_distance_std)
    BEV_night_distance_mean=preprocessing.scale(BEV_night_distance_mean)
    BEV_night_distance_percentage=preprocessing.scale(BEV_night_distance_percentage)
    BEV_am_peak_percentage=preprocessing.scale(BEV_am_peak_percentage)
    BEV_pm_peak_percentage=preprocessing.scale(BEV_pm_peak_percentage)
    BEV_weekends_distance_percentage=preprocessing.scale(BEV_weekends_distance_percentage)
    BEV_charging_rate_mean=preprocessing.scale(BEV_charging_rate_mean)



    X = np.array([BEV_daily_distance_mean, \
                  BEV_daily_distance_std, \
                  BEV_night_distance_mean, \
                  BEV_night_distance_percentage, \
                  BEV_am_peak_percentage, \
                  BEV_pm_peak_percentage, \
                  BEV_weekends_distance_percentage, \
                  BEV_charging_rate_mean])

    XX = {0: BEV_daily_distance_mean,
          1: BEV_daily_distance_std,
          2: BEV_night_distance_mean,
          3: BEV_night_distance_percentage,
          4: BEV_am_peak_percentage,
          5: BEV_pm_peak_percentage,
          6: BEV_weekends_distance_percentage,
          7: BEV_charging_rate_mean,
          }
    
    X_key = [XX[i] for i in range(8)]
    # sub_sets([1,2,3],[],0)
    X_key=np.array(X_key)
    # x=np.array([])
    # print(X_key.T)
    x=[]
    # print(BEV_charging_rate_mean)
    sub_sets(X_key.T,x,0)
    # sub_sets(X_key.T,[],0)