import os

import pandas as pd


def add_minute_table(df):
    del df['历史采样表名']
    del df['历史采样域名']

    min_table_path = r'C:\Users\wzl\Desktop\中广核104测点\分钟级表-字段.csv'
    min_df = pd.read_csv(min_table_path, encoding='gbk', usecols=['遥测ID', '历史采样表名', '历史采样域名'])

    min_df['遥测ID'] = min_df['遥测ID'].apply(lambda x: x.replace('遥测定义表 ', '').replace('遥测值', '').strip())
    min_df.rename(columns={'遥测ID': '遥测名称'}, inplace=True)

    df = df.merge(min_df, on='遥测名称', how='left')
    return df


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

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

    for wind_name in wind_names:
        now_df = df[df['场站'] == wind_name]
        port = now_df['端口'].unique()[0]
        os.makedirs(str(port), exist_ok=True)
        now_df.sort_values(by=['风机号', '测点'], inplace=True)
        now_df.to_csv(os.path.join(str(port), wind_name + '.csv'))
