import pandas as pd

if __name__ == '__main__':
    read_file = r'C:\Users\wzl\Desktop\中广核104测点\0416部署需要\最终测点配置.xlsx'
    df = pd.read_excel(read_file)

    read_file = r'C:\Users\wzl\Desktop\中广核104测点\12CZYC1.csv'
    ori_df = pd.read_csv(read_file, encoding='gbk', usecols=['遥测名称', '遥测别名'])

    ori_df['测点'] = ori_df['遥测别名'].apply(lambda x: '.'.join(x.split('.')[3:]))

    wind_names = df['场站'].unique()

    result_dict_2404 = dict()
    result_dict_2405 = dict()
    for wind_name in wind_names:
        ori_now_df = ori_df[ori_df['遥测名称'].str.contains(wind_name)]
        now_df = df[df['场站'] == wind_name]
        port = int(now_df['端口'].values[0])
        cedianers = now_df['测点'].unique()
        for cedian in cedianers:
            now_count = now_df[now_df['测点'] == cedian].shape[0]
            ori_count = ori_now_df[ori_now_df['测点'] == cedian].shape[0]
            diff = ori_count - now_count
            if port == 2404:
                if wind_name not in result_dict_2404.keys():
                    result_dict_2404[wind_name] = dict()

                result_dict_2404[wind_name][cedian] = diff
            else:
                if wind_name not in result_dict_2405.keys():
                    result_dict_2405[wind_name] = dict()

                result_dict_2405[wind_name][cedian] = diff

    print('*' * 50)
    for win_name, diff_dict in result_dict_2404.items():
        print(win_name)
        for cedian, diff in diff_dict.items():
            print(cedian, diff)

    print('*' * 50)
    for win_name, diff_dict in result_dict_2405.items():
        print(win_name)
        for cedian, diff in diff_dict.items():
            print(cedian, diff)
