|
@@ -5,7 +5,7 @@
|
|
# @Author :David
|
|
# @Author :David
|
|
# @Company: shenyang JY
|
|
# @Company: shenyang JY
|
|
|
|
|
|
-import logging
|
|
|
|
|
|
+import logging, os
|
|
import pandas as pd
|
|
import pandas as pd
|
|
from scipy.cluster.hierarchy import weighted
|
|
from scipy.cluster.hierarchy import weighted
|
|
|
|
|
|
@@ -13,8 +13,6 @@ from app.model.tf_model_train import ModelTrainer
|
|
from app.predict.tf_model_pre import ModelPre
|
|
from app.predict.tf_model_pre import ModelPre
|
|
from app.common.data_cleaning import key_field_row_cleaning
|
|
from app.common.data_cleaning import key_field_row_cleaning
|
|
from app.common.config import logger
|
|
from app.common.config import logger
|
|
-from app.model.tf_region_train import RegionTrainer
|
|
|
|
-from app.model.material import MaterialLoader
|
|
|
|
|
|
|
|
|
|
|
|
class TaskTrain(object):
|
|
class TaskTrain(object):
|
|
@@ -143,6 +141,7 @@ class CDQTaskPre(object):
|
|
2. 将遍历的历史功率和短期时间对齐,算出过去3个时刻的平均
|
|
2. 将遍历的历史功率和短期时间对齐,算出过去3个时刻的平均
|
|
3. 根据起止时间获取短期的16个点,根据偏差进行短期加权
|
|
3. 根据起止时间获取短期的16个点,根据偏差进行短期加权
|
|
"""
|
|
"""
|
|
|
|
+
|
|
def weighted_each_point(his_rp_term, dq_16, error):
|
|
def weighted_each_point(his_rp_term, dq_16, error):
|
|
weighted = list(his_rp_term.head(1)[['Grade', 'Type', 'ID', 'Value']].values[0])
|
|
weighted = list(his_rp_term.head(1)[['Grade', 'Type', 'ID', 'Value']].values[0])
|
|
dq_16['dq_fix'] = dq_16['Power'] + error
|
|
dq_16['dq_fix'] = dq_16['Power'] + error
|
|
@@ -170,15 +169,47 @@ class CDQTaskPre(object):
|
|
dq_area['Datetime'] = pd.to_datetime(dq_area['Datetime'])
|
|
dq_area['Datetime'] = pd.to_datetime(dq_area['Datetime'])
|
|
his_rp_plant = his_rp[his_rp['Grade']==1]
|
|
his_rp_plant = his_rp[his_rp['Grade']==1]
|
|
his_rp_area = his_rp[his_rp['Grade']==0]
|
|
his_rp_area = his_rp[his_rp['Grade']==0]
|
|
- all = []
|
|
|
|
- all.append(dq_fix_weighted(his_rp_area, dq_area))
|
|
|
|
|
|
+ all_weights = [dq_fix_weighted(his_rp_area, dq_area)]
|
|
for id, dq_id in dq.groupby('PlantID'):
|
|
for id, dq_id in dq.groupby('PlantID'):
|
|
his_rp_id = his_rp_plant[his_rp_plant['ID']==id]
|
|
his_rp_id = his_rp_plant[his_rp_plant['ID']==id]
|
|
- all.append(dq_fix_weighted(his_rp_id, dq_id))
|
|
|
|
|
|
+ all_weights.append(dq_fix_weighted(his_rp_id, dq_id))
|
|
weighted_cols = ['Grade', 'Type', 'ID', 'Value'] + ['P'+str(x) for x in range(1, 17)]
|
|
weighted_cols = ['Grade', 'Type', 'ID', 'Value'] + ['P'+str(x) for x in range(1, 17)]
|
|
- weighted_cdq = pd.DataFrame(all, columns=weighted_cols)
|
|
|
|
|
|
+ weighted_cdq = pd.DataFrame(all_weights, columns=weighted_cols)
|
|
return weighted_cdq
|
|
return weighted_cdq
|
|
|
|
|
|
|
|
+
|
|
|
|
+ def post_processing(self, df, station_info):
|
|
|
|
+ # 假设原DataFrame为df,station_info为station_info_df
|
|
|
|
+
|
|
|
|
+ # 步骤1:排除Grade=0的行
|
|
|
|
+ grade_zero_mask = df['Grade'] == 0
|
|
|
|
+ grade_zero_df = df[grade_zero_mask].copy()
|
|
|
|
+ non_grade_zero_df = df[~grade_zero_mask].copy()
|
|
|
|
+
|
|
|
|
+ # 步骤2:合并PlantCap信息
|
|
|
|
+ merged_df = non_grade_zero_df.merge(
|
|
|
|
+ station_info[['PlantID', 'PlantCap']],
|
|
|
|
+ left_on='ID',
|
|
|
|
+ right_on='PlantID',
|
|
|
|
+ how='left'
|
|
|
|
+ ).drop(columns=['PlantID']) # 移除多余的PlantID列
|
|
|
|
+
|
|
|
|
+ # 步骤3:处理P1-P16列
|
|
|
|
+ p_columns = [f'P{i}' for i in range(1, 17)]
|
|
|
|
+
|
|
|
|
+ # 将大于PlantCap的值设为PlantCap,小于0的值设为0
|
|
|
|
+ merged_df[p_columns] = merged_df[p_columns].clip(
|
|
|
|
+ lower=0,
|
|
|
|
+ upper=merged_df['PlantCap'],
|
|
|
|
+ axis=0
|
|
|
|
+ ).round(2) # 保留两位小数
|
|
|
|
+
|
|
|
|
+ merged_df.drop(columns=['PlantCap'], inplace=True) # 移除临时列
|
|
|
|
+
|
|
|
|
+ # 步骤4:合并处理后的数据与Grade=0的数据
|
|
|
|
+ final_df = pd.concat([merged_df, grade_zero_df], axis=0).reset_index(drop=True)
|
|
|
|
+ return final_df
|
|
|
|
+
|
|
def cdq_task(self, config):
|
|
def cdq_task(self, config):
|
|
"""场站级训练任务"""
|
|
"""场站级训练任务"""
|
|
station_id = -99
|
|
station_id = -99
|
|
@@ -193,11 +224,13 @@ class CDQTaskPre(object):
|
|
dq_area = data_objects.dq_area
|
|
dq_area = data_objects.dq_area
|
|
his_rp = data_objects.cdq_his_rp
|
|
his_rp = data_objects.cdq_his_rp
|
|
begin_time, end_time = data_objects.begin_time, data_objects.end_time
|
|
begin_time, end_time = data_objects.begin_time, data_objects.end_time
|
|
|
|
+ station_info = data_objects.station_info
|
|
weighted_cdq = self.calculate_dq_fix_weighted(dq, dq_area, his_rp, begin_time, end_time)
|
|
weighted_cdq = self.calculate_dq_fix_weighted(dq, dq_area, his_rp, begin_time, end_time)
|
|
|
|
+ weighted_cdq = self.post_processing(weighted_cdq, station_info)
|
|
print("444")
|
|
print("444")
|
|
- # 模型训练
|
|
|
|
- # model = ModelTrainer(station_id, train_data, capacity=data_objects.cap, gpu_id=config.get('gpu_assignment'))
|
|
|
|
-
|
|
|
|
|
|
+ out_dir_cdq = str(os.path.join(config['cdqyc_base_path'], config['moment'], config['input_file']))
|
|
|
|
+ out_dir_cdq.replace('IN', 'OUT')
|
|
|
|
+ weighted_cdq.to_csv(out_dir_cdq, index=False)
|
|
print("555")
|
|
print("555")
|
|
return {'status': 'success', 'station_id': station_id, 'weights': local_weights}
|
|
return {'status': 'success', 'station_id': station_id, 'weights': local_weights}
|
|
except Exception as e:
|
|
except Exception as e:
|