import random
import numpy as np
import pandas as pd

# def get_client_characteristic(count):
#     # count: client的个数
#     client_characteristic = np.zeros((count, 6))
#     # 生成cpu的备选集
#     cpu_list = []
#     for i in range(51):
#          cpu_list.append(50+i*2) # 范围[50, 150] 核数，偶数
#     # 生成memory的备选集
#     memory_list = [128, 256, 512, 1024] 
#     # 生成gpu的备选集
#     gpu_list = [2,4,6,8]
#     # 生成datasize的备选集
#     datasize_list = []
#     for i in range(20):
#          datasize_list.append(0.5+i*0.5)  # 范围[0.5, 10] GB
#     # 生成batch size的备选集
#     batchsize_list = [128, 256, 512, 1024, 2048]
#     # 生成learning rate的备选集
#     learningrate_list = [0.0001, 0.001, 0.01, 0.1]
    
#     for i in range(520):
#         if i < 20:
#             client_characteristic[i][0] = random.sample(cpu_list[45:51], 1)[0] 
#             client_characteristic[i][1] = random.sample(memory_list[2:4], 1)[0] 
#             client_characteristic[i][2] = random.sample(gpu_list[2:4], 1)[0] 
#             client_characteristic[i][3] = random.sample(datasize_list[18:20], 1)[0] 
#             client_characteristic[i][4] = random.sample(batchsize_list[4:5], 1)[0] 
#             client_characteristic[i][5] = random.sample(learningrate_list[0:2], 1)[0] 
#         # 第一类
#         elif i < 70:
#             client_characteristic[i][0] = random.sample(cpu_list[0:10], 1)[0] 
#             client_characteristic[i][1] = random.sample(memory_list[0:3], 1)[0] 
#             client_characteristic[i][2] = random.sample(gpu_list[0:2], 1)[0] 
#             client_characteristic[i][3] = random.sample(datasize_list[0:5], 1)[0] 
#             client_characteristic[i][4] = random.sample(batchsize_list[0:2], 1)[0] 
#             client_characteristic[i][5] = random.sample(learningrate_list[2:3], 1)[0] 
#         elif i < 120:
#             client_characteristic[i][0] = random.sample(cpu_list[10:20], 1)[0] 
#             client_characteristic[i][1] = random.sample(memory_list[1:3], 1)[0] 
#             client_characteristic[i][2] = random.sample(gpu_list[0:1], 1)[0] 
#             client_characteristic[i][3] = random.sample(datasize_list[5:10], 1)[0] 
#             client_characteristic[i][4] = random.sample(batchsize_list[1:3], 1)[0] 
#             client_characteristic[i][5] = random.sample(learningrate_list[1:4], 1)[0] 
#         elif i < 170:
#             client_characteristic[i][0] = random.sample(cpu_list[20:35], 1)[0] 
#             client_characteristic[i][1] = random.sample(memory_list[2:4], 1)[0] 
#             client_characteristic[i][2] = random.sample(gpu_list[1:2], 1)[0] 
#             client_characteristic[i][3] = random.sample(datasize_list[10:15], 1)[0] 
#             client_characteristic[i][4] = random.sample(batchsize_list[2:4], 1)[0] 
#             client_characteristic[i][5] = random.sample(learningrate_list[0:4], 1)[0] 
#         elif i < 220:
#             client_characteristic[i][0] = random.sample(cpu_list[35:49], 1)[0] 
#             client_characteristic[i][1] = random.sample(memory_list[3:4], 1)[0] 
#             client_characteristic[i][2] = random.sample(gpu_list[2:3], 1)[0] 
#             client_characteristic[i][3] = random.sample(datasize_list[15:20], 1)[0] 
#             client_characteristic[i][4] = random.sample(batchsize_list[2:4], 1)[0] 
#             client_characteristic[i][5] = random.sample(learningrate_list[0:4], 1)[0] 
#         # 第二类
#         elif i < 370:
#             client_characteristic[i][0] = random.sample(cpu_list[20:30], 1)[0] 
#             client_characteristic[i][1] = random.sample(memory_list[1:3], 1)[0] 
#             client_characteristic[i][2] = random.sample(gpu_list[1:3], 1)[0] 
#             client_characteristic[i][3] = random.sample(datasize_list[5:15], 1)[0] 
#             client_characteristic[i][4] = random.sample(batchsize_list[1:4], 1)[0] 
#             client_characteristic[i][5] = random.sample(learningrate_list[1:3], 1)[0] 
#         # 第三类
#         else:
#             # client_characteristic[i][0] = random.sample(cpu_list[0:10], 1)[0] 
#             # client_characteristic[i][1] = random.sample(memory_list[0:2], 1)[0] 
#             # client_characteristic[i][2] = random.sample(gpu_list[0:2], 1)[0] 
#             # client_characteristic[i][3] = random.sample(datasize_list[15:20], 1)[0] 
#             # client_characteristic[i][4] = random.sample(batchsize_list[3:5], 1)[0] 
#             # client_characteristic[i][5] = random.sample(learningrate_list[2:4], 1)[0] 
#             client_characteristic[i][0] = random.sample(cpu_list[0:51], 1)[0] 
#             client_characteristic[i][1] = random.sample(memory_list[0:4], 1)[0] 
#             client_characteristic[i][2] = random.sample(gpu_list[0:4], 1)[0] 
#             client_characteristic[i][3] = random.sample(datasize_list[0:20], 1)[0] 
#             client_characteristic[i][4] = random.sample(batchsize_list[0:5], 1)[0] 
#             client_characteristic[i][5] = random.sample(learningrate_list[0:4], 1)[0] 
    
#     # 归一化
#     for i in range(count):
#         client_characteristic[i][0] = client_characteristic[i][0]/150
#         client_characteristic[i][1] = client_characteristic[i][1]/1024
#         client_characteristic[i][2] = client_characteristic[i][2]/8
#         client_characteristic[i][3] = client_characteristic[i][3]/10
#         client_characteristic[i][4] = client_characteristic[i][4]/2048
#         client_characteristic[i][5] = client_characteristic[i][5]/0.1
    
#     return client_characteristic


# 读取 CSV 文件
csv_file_path = '/home/xschen/workspace/fd_learning/simulator/simDataset/clients_vu_for_sim.csv'
df = pd.read_csv(csv_file_path)

def get_client_characteristic(count):
    # count: client的个数
    client_characteristic = np.zeros((count, 6))
    # 生成cpu的备选集
    cpu_list = []
    for i in range(51):
         cpu_list.append(50+i*2) # 范围[50, 150] 核数，偶数
    # 生成memory的备选集
    memory_list = [128, 256, 512, 1024] 
    # 生成gpu的备选集
    gpu_list = [2,4,6,8]
    # 生成datasize的备选集
    datasize_list = []
    for i in range(20):
         datasize_list.append(0.5+i*0.5)  # 范围[0.5, 10] GB
    # 生成batch size的备选集
    batchsize_list = [128, 256, 512, 1024, 2048]
    # 生成learning rate的备选集
    learningrate_list = [0.0001, 0.001, 0.01, 0.1]
    
    for i in range(2500):
        client_characteristic[i][0] = random.sample(cpu_list[0:51], 1)[0] 
        client_characteristic[i][1] = random.sample(memory_list[0:4], 1)[0] 
        client_characteristic[i][2] = random.sample(gpu_list[0:4], 1)[0] 
        client_characteristic[i][3] = random.sample(datasize_list[0:20], 1)[0] 
        client_characteristic[i][4] = random.sample(batchsize_list[0:5], 1)[0] 
        client_characteristic[i][5] = random.sample(learningrate_list[0:4], 1)[0] 

        for i in range(2045, 2050):
            for j in range(0, 500, 50):
                client_characteristic[i+j][0] = random.sample(cpu_list[46:51], 1)[0] 
                client_characteristic[i+j][1] = random.sample(memory_list[3:4], 1)[0] 
                client_characteristic[i+j][2] = random.sample(gpu_list[3:4], 1)[0] 
                client_characteristic[i+j][3] = random.sample(datasize_list[18:20], 1)[0] 
                client_characteristic[i+j][4] = random.sample(batchsize_list[3:5], 1)[0] 
                client_characteristic[i+j][5] = random.sample(learningrate_list[3:4], 1)[0]
        for i in range(2448, 2450):
            client_characteristic[i][0] = random.sample(cpu_list[50:51], 1)[0] 
            client_characteristic[i][1] = random.sample(memory_list[3:4], 1)[0] 
            client_characteristic[i][2] = random.sample(gpu_list[3:4], 1)[0] 
            client_characteristic[i][3] = random.sample(datasize_list[19:20], 1)[0] 
            client_characteristic[i][4] = random.sample(batchsize_list[4:5], 1)[0] 
            client_characteristic[i][5] = random.sample(learningrate_list[3:4], 1)[0]
        for i in range(2497, 2500):
            client_characteristic[i][0] = random.sample(cpu_list[50:51], 1)[0] 
            client_characteristic[i][1] = random.sample(memory_list[3:4], 1)[0] 
            client_characteristic[i][2] = random.sample(gpu_list[3:4], 1)[0] 
            client_characteristic[i][3] = random.sample(datasize_list[19:20], 1)[0] 
            client_characteristic[i][4] = random.sample(batchsize_list[4:5], 1)[0] 
            client_characteristic[i][5] = random.sample(learningrate_list[3:4], 1)[0]
  

        # max = (i+1) // 50
        # if max <= 1:
        #    min = 0
        # else:
        #    min = max -1
        # max = max / 50
        # min = min / 50
        # if int(min * 51) == int(max * 51):
        #     if int(min * 51) < 51:
        #         client_characteristic[i][0] = random.sample(cpu_list[int(min * 51):int(min * 51)+1], 1)[0]
        #     else:
        #         client_characteristic[i][0] = random.sample(cpu_list[int(max * 51)-1:int(max * 51)], 1)[0]
        # else:
        #     client_characteristic[i][0] = random.sample(cpu_list[int(min * 51):int(max * 51)], 1)[0] 

        # if int(min * 4) == int(max * 4):
        #     if int(min * 4) < 4:
        #         client_characteristic[i][1] = random.sample(cpu_list[int(min * 4):int(min * 4)+1], 1)[0]
        #     else:
        #         client_characteristic[i][1] = random.sample(cpu_list[int(max * 4)-1:int(max * 4)], 1)[0]
        # else:
        #     client_characteristic[i][1] = random.sample(memory_list[int(min * 4):int(max * 4)], 1)[0] 

        # if int(min * 4) == int(max * 4):
        #     if int(min * 4) < 4:
        #         client_characteristic[i][2] = random.sample(cpu_list[int(min * 4):int(min * 4)+1], 1)[0]
        #     else:
        #         client_characteristic[i][2] = random.sample(cpu_list[int(max * 4)-1:int(max * 4)], 1)[0]
        # else:
        #     client_characteristic[i][2] = random.sample(gpu_list[int(min * 4):int(max * 4)], 1)[0] 

        # if int(min * 20) == int(max * 20):
        #     if int(min * 20) < 20:
        #         client_characteristic[i][3] = random.sample(cpu_list[int(min * 20):int(min * 20)+1], 1)[0]
        #     else:
        #         client_characteristic[i][3] = random.sample(cpu_list[int(max * 20)-1:int(max * 20)], 1)[0]
        # else:
        #     client_characteristic[i][3] = random.sample(datasize_list[int(min * 20):int(max * 20)], 1)[0] 

        # if int(min * 5) == int(max * 5):
        #     if int(min * 5) < 5:
        #         client_characteristic[i][4] = random.sample(cpu_list[int(min * 5):int(min * 5)+1], 1)[0]
        #     else:
        #         client_characteristic[i][4] = random.sample(cpu_list[int(max * 5)-1:int(max * 5)], 1)[0]
        # else:
        #     client_characteristic[i][4] = random.sample(batchsize_list[int(min * 5):int(max * 5)], 1)[0]  

        # if int(min * 4) == int(max * 4):
        #     if int(min * 4) < 4:
        #         client_characteristic[i][5] = random.sample(cpu_list[int(min * 4):int(min * 4)+1], 1)[0]
        #     else:
        #         client_characteristic[i][5] = random.sample(cpu_list[int(max * 4)-1:int(max * 4)], 1)[0]
        # else:
        #     client_characteristic[i][5] = random.sample(learningrate_list[int(min * 4):int(max * 4)], 1)[0]

    
    # 归一化
    for i in range(count):
        client_characteristic[i][0] = client_characteristic[i][0]/150
        client_characteristic[i][1] = client_characteristic[i][1]/1024
        client_characteristic[i][2] = client_characteristic[i][2]/8
        client_characteristic[i][3] = client_characteristic[i][3]/10
        client_characteristic[i][4] = client_characteristic[i][4]/2048
        client_characteristic[i][5] = client_characteristic[i][5]/0.1
    
    return client_characteristic

if __name__ == '__main__':
    # client_characteristic = get_client_characteristic(520)
    # for i in range(520):
    #     print(client_characteristic[i])
    pass
