from service import plt_service

wind_farms = {
    # "WOF35900004": "平陆风电场",
    # "WOF35100072": "阳曲风电场",
    "WOF35100073": "古交风电场",
    "WOF35200074": "马家梁风电场",
    "WOF35400075": "太谷风电场",
    "WOF35900076": "坡底风电场",
    "WOF35300077": "西潘风电场",
    "WOF35900078": "芮城风电场",
    "WOF34900079": "右玉风光互补电站",
    "WOF35800080": "贺家沟",
    "WOF35800081": "石楼风电场",
    "WOF35800082": "盂县风光互补电站"
}

for k, v in wind_farms.items():
    wind_infos, _ = plt_service.get_wind_info(k, False)
    for type in ['second', 'minute']:
        for name, wind_code in wind_infos.items():
            print('-- ', v, type, wind_code)

            sql = f"""
            SET tidb_mem_quota_query = 8589934592;
            DELETE t FROM {k}_{type} t 
            JOIN(
            SELECT wind_turbine_number,time_stamp, ROW_NUMBER() OVER (PARTITION BY wind_turbine_number,time_stamp ORDER BY wind_turbine_number,time_stamp) AS rn
                FROM {k}_{type} a
            WHERE  
            a.wind_turbine_number = '{wind_code}'
            and a.time_stamp in (
            SELECT time_stamp from {k}_{type} PARTITION(p202504) b where b.time_stamp BETWEEN '2025-04-01 00:00:00' and '2025-04-30 23:59:59'
            and b.wind_turbine_number = '{wind_code}'
            GROUP BY b.time_stamp HAVING count(1) > 1
            )) t2 on t.time_stamp = t2.time_stamp and t.wind_turbine_number = t2.wind_turbine_number where t2.rn > 1;
            """
            print(sql)
            # trans.execute(sql)
